Answer the question
In order to leave comments, you need to log in
How to execute a query written in cypher language (neo4j graph subd) in Python?
Good day! I work with the Neo4j graph DBMS, which has its own query language - Cypher.
I have the code for the query I need, written in cypher:
WITH split(tolower("text text text"), " ") AS text
UNWIND range(0, size(text)-2) AS i
MERGE (w1:Word {name : text[i]})
MERGE (w2:Word {name: text[i+1]})
MERGE (w1)-[:NEXT]->(w2)
How can I do this in Python code? I know that this can be done using the py2neo library, but so far I have not been able to do it correctly.
The query splits the text into words, and enters them into the database as nodes, creating links between them.
Answer the question
In order to leave comments, you need to log in
I'm querying neo4j with another library and it looks like this.
from neo4j import GraphDatabase
uri = "{}:{}".format(NEO4J_HOST, NEO4J_PORT)
driver = GraphDatabase.driver(uri, auth=(NEO4J_HOST_USER, NEO4J_HOST_PASSWORD))
with driver.session() as session:
result = session.run(YOUR_CYPHER_QUERY).values()
session.close()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question