3 ms·
Interesting. I think the required computation is different for 2 different cases you have in your post. Case 1: If you have = relationships (let's call the typ
by semihsalihoglu 4y ago
Interesting. I think the required computation is different for 2 different cases you have in your post.
Case 1: If you have = relationships (let's call the type of the relationship eq). Then what you need is to identify weak connectivity. If you want to do find the equivalence class of a single node, say with primary key "foo", you can do this with a Cypher query using Kleene star:
"MATCH (a)-[:eq*]->(b) WHERE a.pk = "foo" RETURN DISTINCT b"
This finds the "weakly connected component" of node "foo". If you want to find all equivalence classes, that's equivalent to finding all weakly connected components and you should probably call that algorithm from the algorithms library built over the GDBMS (e.g., https://tinyurl.com/mtx98c5s https://tinyurl.com/mtx98c5s). You can do it in Cypher but it will be very slow.
Case 2: You have <= relationships, so relationships are not symmetric, so you want to find strong connectivity of nodes. I won't type it here but you could do this with a Cypher query for a single node but for all nodes again you can call the strongly connected components algorithm from the algorithms library of the GDBMS.
You can do some of these natively in Datalog, but if you implement it yourself in a native query language, but the computations is likely to be quite slow. So it might still be better to call a specialized algorithm that's implemented in a library above the DBMS you are using.
Hope this helps.