aplbrain / grand-cypher

Implementation of the Cypher language for searching NetworkX graphs
Apache License 2.0
77 stars 8 forks source link

Edge Hopping #23

Closed khoale88 closed 1 year ago

khoale88 commented 1 year ago

My use case is a perfect fit for this feature. I do not know exactly the depth of a branch, so I would like to search for depth starting from a node all the way down or to a limit. It would be good if edge hopping or variable relationship is supported.

From what I understand, the syntax for it is -[*min..max]- where min and max are positive integers. The result is subgraphs having that branch node reaching out from min to max.

j6k4m8 commented 1 year ago

This would be a great feature, and I think that indeed this will be a technical challenge to put into the current grandiso implementation. This may be another case where it will be easiest to do several "simple" searches and combine them, replacing the "virtual" query edge -[*min..max]- with a set of searches using networkx.all_simple_paths...

I would be very supportive of adding this here, or even finding a good way to add it directly to grandiso, if not too complicated. (I selfishly want to also support this in grandiso and DotMotif!)

khoale88 commented 1 year ago

hi @j6k4m8 , I gave it a thought about doing it from the grandcypher layer, but it doesn't seem to be simple, especially when the hop = 0. I foresee this might lead to tons of conner cases with hard-to-reasoning algorithm.

I'm going to make a bolder move updating the grandiso to support edge hopping. It is not that easy to understand every pieces of the algorithm. So I'm not expecting this to be done in the 1st iteration. But I'm going to create a MR anyway to illustrate the idea.

Basically, I am going to support the two hidden attribute __min_hop__ and __max_hop__ following convention [min, max). As an edge (last_node, next_node) is evaluated, I fill the candidate with all hopped nodes. Some "validations" must be modified and this is also a headache.