Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
01-28-2022 02:49 PM
Hi,
I'm trying to replicate some of the working browser GDS code into Python script for automation purposes.
I am working on basic graph create functionality.
Within browser this works:
CALL gds.graph.create.cypher(
"self_cite",
"MATCH (n:patent)-[:Assigned_to]-(a:company) WHERE a.name='applied materials' RETURN id(n) AS id, labels(n) AS labels",
"MATCH (a:patent)-[:Cites]-(b:patent) return id(a) AS source, id(b) AS target",
{validateRelationships: FALSE}
);
I am using the Neo4J python driver and working with a Jupyter notebook.
Here is what I have:
def make_self_cite(tx):
result = tx.run("CALL gds.graph.create.cypher('self_cite', "
"'MATCH (n:patent)-[:Assigned_to]-(a:company) WHERE a.name='applied materials' RETURN id(n) AS id, labels(n) AS labels', "
"'MATCH (a:patent)-[:Cites]-(b:patent) return id(a) AS source, id(b) AS target', {validateRelationships: FALSE});")
with driver.session() as session:
selftest = session.write_transaction(make_self_cite)
driver.close()
And I am getting
CypherSyntaxError: {code: Neo.ClientError.Statement.SyntaxError} {message: Invalid input 'p': expected 'n/N' (line 1, column 103 (offset: 102))
And trying to figure out the correct syntax.
I think that puts it at the where clause where I define 'applied materials' . What should be the correct syntax. And as extra credit how would I parameterize the 'applied materials' part to further allow automation?
Andy
01-28-2022 04:34 PM
Ok
Got the first part figured out by backslash quoting.
def make_self_cite(tx):
result = tx.run("CALL gds.graph.create.cypher('self_cite', "
"\"MATCH (n:patent)-[:Assigned_to]-(a:company) WHERE a.name=\'applied materials\' RETURN id(n) AS id, labels(n) AS labels\", "
"'MATCH (a:patent)-[:Cites]-(b:patent) return id(a) AS source, id(b) AS target', {validateRelationships: FALSE});")
with driver.session() as session:
selftest = session.write_transaction(make_self_cite)
driver.close()
Andy
All the sessions of the conference are now available online