Open
Description
Hello, I use the new version 0.5.1 of grand-graph:
from grand import Graph
from grandcypher import GrandCypher
from grand.backends._sqlbackend import SQLBackend
backend=SQLBackend(db_url="sqlite:///demo2.db")
G = Graph(backend=backend)
G.nx.add_node("spranger", type="Person")
G.nx.add_node("meier", type="Person")
G.nx.add_node("krause", type="Person")
G.nx.add_node("Berlin", type="City")
G.nx.add_node("Paris", type="City")
G.nx.add_node("London", type="City")
G.nx.add_edge("spranger", "Paris", type="LIVES_IN")
G.nx.add_edge("krause", "Berlin", type="LIVES_IN")
G.nx.add_edge("meier", "London", type="LIVES_IN")
G.nx.add_edge("spranger", "Berlin", type="BORN_IN")
G.nx.add_edge("krause", "Berlin", type="BORN_IN")
G.nx.add_edge("meier", "Berlin", type="BORN_IN")
result1 = GrandCypher(G.nx).run("""
MATCH (n)-[r]->(c)
WHERE
n.type == "Person"
and
c.type == "City"
RETURN n, r, c
""")
from lark.lexer import Token
n = result1[Token('CNAME', 'n')]
r = result1[Token('CNAME', 'r')]
c = result1[Token('CNAME', 'c')]
for i in range(len(n)):
print(f"{n[i]} - {r[i].get('type')} -> {c[i]}")
backend.commit()
backend.close()
results in
- spranger - BORN_IN -> Berlin
- spranger - LIVES_IN -> Paris
- meier - BORN_IN -> Berlin
- meier - LIVES_IN -> London
- krause - BORN_IN -> Berlin-
- The "krause - LIVES_IN -> Berlin" relation is not stored (as any second relation between two same nodes) .
This might be due to the cause that our "G.nx" doesn't cope with multigraphs. - In plain grandcypher I can query "Match (p:Person)" . How do I do this in my cypher query above?
- Would it be a good idea to have the backend and the graph layer (e.g. netwrokx) completely transparent and just run Cypher queries, also for creating nodes and relations?
Kind Regards.
Steffen, the graphologist
Metadata
Assignees
Labels
No labels
Activity