Cypher on NetworkXGraph
cvcdocdb.nx_cypher is the engine behind
NetworkXGraph.query(cypher) for read-only queries: it parses the query
and evaluates it against the in-memory graph with Neo4j semantics, so the
same Cypher gives the same results on NetworkXGraph and Neo4jGraph.
Syntax outside the supported subset raises ValueError instead of
returning wrong results. Write queries (CREATE, MERGE, SET,
DELETE) are handled separately by NetworkXGraph.
Read-only Cypher engine for NetworkXGraph.
NetworkXGraph.query(cypher) routes every read-only query here (write
queries keep using the older engine in networkx_graph). Instead of
matching the query text with regular expressions, it is tokenized, parsed
into a small AST and evaluated against the graph, following Neo4j’s
semantics for the supported subset:
Clauses:
MATCH,OPTIONAL MATCH,WHERE,WITH,RETURN(DISTINCT,*),ORDER BY(ASC/DESC),SKIP,LIMIT.Patterns:
(v:Label1:Label2 {key: expr}), anonymous nodes, chains of relationships-[r:T1|T2 {key: expr}]->,<-[...]-,-[...]-, several comma-separated patterns. Main and alternative labels both match. A relationship is not matched twice within oneMATCH(as in Neo4j).Expressions: literals (numbers, strings, booleans,
null, lists, maps),$params(bound as values, never substituted into the text), property access,AND/OR/XOR/NOTwith three-valuednulllogic,=,<>,<,<=,>,>=,IS [NOT] NULL,IN,STARTS WITH,ENDS WITH,CONTAINS,=~, label predicates (n:Label), arithmetic, and the functions in_SCALAR_FUNCTIONS.Aggregations:
count(incl.count(*)andDISTINCT),sum,avg,min,max,collect, with implicit grouping by the non-aggregated items.
Anything outside this subset (variable-length paths, path variables,
UNWIND, UNION, CASE, subqueries, unknown functions…) raises
NxCypherError (a ValueError) instead of returning wrong results.
Returned values have the same shape as before: nodes as
{"labels": [...], "properties": {...}} and relationships as
{"type", "start_node", "end_node", "properties"}.
- exception cvcdocdb.nx_cypher.NxCypherError[source]
Invalid or unsupported Cypher for the NetworkX engine.