grand-cypher
grand-cypher copied to clipboard
Support passing `hints` in grandiso
grandiso.find_motifs supports a hints attribute with is a list of partial-mappings, instead of requiring an exhaustive search:
host = nx.DiGraph()
nx.add_path(host, ["A", "B", "C", "A"])
motif = nx.DiGraph()
nx.add_path(motif, ["A", "B", "C", "A"])
assert (
find_motifs(
motif,
host,
count_only=True,
# ↓ won't yield anything ↓ ↓ results in 1 match ↓
hints=[{"A": "A", "B": "C"}, {"A": "A", "B": "B"}],
)
== 1
)
It would be a HUGE query savings if we could optionally pass a set of hints directly to the grandcypher constructor:
GrandCypher(G.nx).run(" ... ", grandiso_hints=[{"A": "A", "B": "B"}])
It would also be a huge performance boost if we took the attributes that have "simple" mappings (attribute equality, for instance) and auto-generated a set of hints from that. For example,
MATCH (A)-[]->(B)
WHERE B.username == "j6k4m8"
RETURN A
We should see that B can be easily found first, and populate a set of hints with all valid matches for B before we even call the motif search here.
This does seem like a really interested idea!
This is interesting. I was having performance issues when I used grand-cypher in a large-scale project. I ended up traversing the graph myself.
This might be the solution. It's excited to see how the project grows, truely.
I forget a lot of stuff, but I think the node json_rule can be a good start for hinting.
Hi @j6k4m8 , coiuld you please help create 2 sub-issues for adding node hints from node json_data, and another one from node labels?