Добавить значение из переменной Python в оператор Cypher - PullRequest
0 голосов
/ 15 апреля 2019

Возможно ли то, что я пытаюсь сделать? Я работаю с Neo4j в Python. Пожалуйста, смотрите мой код. Я сохраняю результат первого оператора шифра в переменной Python 'random'. Я хочу добавить значение этой случайной величины в мой второй оператор cypher, cypher2. - Я знаю, что синтаксис cypher2 - это нонсенс, просто добавление случайного. Пожалуйста, воспринимайте это как псевдокод, выражающий мою цель. Как я могу добавить случайное значение в оператор Cypher, если вообще? Спасибо!

#gives me a random element
cypher1 = "MATCH (n:Event) WITH n, rand() AS r ORDER BY r RETURN n        LIMIT 1"
#I want to add the value of the random element in the cypher     statement
 cypher2 = "MATCH (n:Event)-[:NEXT]->(m:Event) WHERE n = random    RETURN  m.time"
with driver.session() as session:
random = session.run(cypher1)
#i want to mesaure execution time from here without calculating    time for finding random element 
result = session.run(cypher2)

1 Ответ

0 голосов
/ 16 апреля 2019
#Execute a given query
def executeCypher(cypher):
    tx = session.begin_transaction()
    result = tx.run(cypher)
    tx.commit()
    return result


#gives me a random element
cypher1 = "MATCH (n:Event) WITH n, rand() AS r ORDER BY r RETURN ID(n) LIMIT 1"
result = executeCypher(cypher1)
id = result.single()[0]
#I want to add the value of the random element in the cypher     statement
cypher2 = """MATCH (n)-[:NEXT]->(m:Event) WHERE ID(n) = %d    RETURN  m.time""" % (id)
executeCypher(cypher2)

Эта ссылка может помочь вам: https://neo4j.com/docs/driver-manual/1.7/cypher-values/#driver-result

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...