Open spranger opened 3 months ago
Hi @spranger! @jackboyla just added support for multigraphs in Grand-Cypher here: https://github.com/aplbrain/grand-cypher/pull/42
So that's certainly going to help here. I also think (need to do a deeper dive before I can confirm) that this is indeed a limitation of Grand right now; I don't think we support MultiGraphs very well. (Maybe @acthecoder23 this would be a fun project to chew on?)
Just thinking out loud, probably the correct answer is to split Graph/DiGraph/MultiGraph/MultiDiGraph implementations like we briefly discuss in this issue: https://github.com/aplbrain/grand/issues/44 ...
A short-term solution might be to create a MultiDiGraph in networkx itself (rather than in Grand) and try out @jackboyla's new implementation (which I'll have on PyPI / pip-installable shortly in grand-cypher==0.8.0
). If that works for you, then we'll know the next step is support for multigraphs in the Grand backends!
PS: Just got back from a week in Berlin, and totally thinking about adding a LIVES_IN
edge there someday... :)
@j6k4m8 I can give this a shot. I'll have to do a little digging but it'd be worthwhile
@spranger also to answer 2. -- to MATCH (a:friend)
you need to assign the node label to the __labels__
attribute, in a set
. We should probably include this in the README as it's not immediately obvious :) hopefully the multigraph support helps too:
from grandcypher import GrandCypher
import networkx as nx
host = nx.MultiDiGraph()
host.add_node("a", name="Alice", age=30)
host.add_node("b", name="Bob", age=40)
host.add_node("c", name="Charlie", age=50)
host.add_edge("a", "b", __labels__={"friend"}, years=3) # <---
host.add_edge("a", "c", __labels__={"colleague"}, years=10)
host.add_edge("a", "c", __labels__={"parent"}, duration='forever')
host.add_edge("b", "c", __labels__={"colleague"}, duration=10)
host.add_edge("b", "c", __labels__={"mentor"}, years=2)
qry = """
MATCH (a)-[r]->(b)
RETURN a.name, b.name, r.__labels__, r.duration
"""
res = GrandCypher(host).run(qry)
print(res)
'''
{'a.name': ['Alice', 'Alice', 'Bob'],
'b.name': ['Bob', 'Charlie', 'Charlie'],
'r.__labels__': [{0: {'friend'}}, {0: {'colleague'}, 1: {'parent'}}, {0: {'colleague'}, 1: {'mentor'}}],
'r.duration': [{0: None}, {0: None, 1: 'forever'}, {0: 10, 1: None}]}
'''
Hello, I use the new version 0.5.1 of grand-graph:
results in
Kind Regards. Steffen, the graphologist