pythonからNeo4jにアクセスしてデータをGET

前回作成したhelloworld.pyを改変して、Movie情報をGETします。

 

create_and_return_greetingメソッドを以下のように変更します。

 def _create_and_return_greeting(tx, message):
        result = tx.run("MATCH (tom:Person {name: $message})-[:ACTED_IN]->(tomHanksMovies)"
 "RETURN collect(tomHanksMovies.title)",message=message)
        return result.single()[0]

 

messageにTOM Hanksとなるように以下を変更します。

変更前:

greeter.print_greeting("hello world")

変更後:

greeter.print_greeting("Tom Hanks")

 

実行すると、Tom Hanksの出演した映画のタイトルが表示されます。

 

>python helloworld.py
['Apollo 13', "You've Got Mail", 'A League of Their Own', 'Joe Versus the Volcano', 'That Thing You Do', 'The Da Vinci Code', 'Cloud Atlas', 'Cast Away', 'The Green Mile', 'Sleepless in Seattle', 'The Polar Express', "Charlie Wilson's War"]

 

 

 

 

/* -----codeの行番号----- */