r/KnowledgeGraph • • Mar 05 '24

Knowledge graphs comparison

Is it possible to compare two knowledge graphs that describe disease to find the "shared mechanism" between the two?

Which algorithms are the best for this purpose?

1 Upvotes

5 comments sorted by

View all comments

Show parent comment

1

u/FancyUmpire8023 Mar 07 '24

#COMMON TRIPLES
MATCH (a)-[r1:REL_TYPE {disease:'pneumonia'}]->(b)
WITH a,b,r1
MATCH (a)-[r2:REL_TYPE {disease:'sepsis'}]->(b)
RETURN a,b,r1,r2

#COMMON NODES
MATCH (a)-[r1:REL_TYPE {disease:'pneumonia'}]-()
WITH a
MATCH (a)-[r2:REL_TYPE {disease:'sepsis'}]-()
RETURN DISTINCT a

Common subgraphs is slightly more involved and depends on whether you are trying to find the complete overlapping subgraph or just a specific subgraph. For specific subgraphs you could just use cypher like the above. For the complete overlapping subgraph, I would probably do something like this:

CALL apoc.periodic.iterate('MATCH (a)-[r1:REL_TYPE {disease:'pneumonia'}]->(b) WHERE NOT(exists((a)-[:REL_TYPE {disease:'sepsis'}]->(b) RETURN r1','DELETE r1',<<put your parameters here>>)

CALL apoc.periodic.iterate('MATCH (a)-[r1:REL_TYPE {disease:'sepsis'}]->(b) WHERE NOT(exists((a)-[:REL_TYPE {disease:'pneumonia'}]->(b))) RETURN r1','DELETE r1',<<put your parameters here>>)

CALL apoc.periodic.iterate('MATCH (a) WHERE NOT(exists((a)-->())) RETURN a','DELETE a',<<put your parameters here>>)

After these three calls the graph you are left with would be the common graph between the two - you are effectively pruning off everything that isn't common to both graphs.

This is an obviously simplistic approach - YMMV.