I want to compare two semantic Knowledge Graphs, to see if they have any triple in common, using cypher.
MATCH (n1)-[r1]-(c1)
MATCH (n2)-[r2]-(c2)
WHERE r1.filePath = "../data/graph1.json"
AND r2.filePath = "../data/graph2.json"
AND n1 = n2
AND r1 = r2
AND c1 = c2
RETURN n1, n2, r1, r2, c1, c2
The two graphs are loaded in neo4j, and the only way to distinguish them is the rel property "filePath".
Is this the correct way of doing so? Are there other algorithms to search for similarities between graphs?
If you don't care whether
r1andr2have the same directionality, nor whether they have the same type, this simple query should be sufficient to find all "common triples" between the 2 knowledge graphs (that share the same node pair):Or, if you want them to have the same directionality:
Or, if you want the same directionality and type (but do not want to specify a specific type in the
MATCHpattern):Also, I'd suggest a shorter relationship property value, as long values can be wasteful of storage space. Something like "g1" and "g2" may be sufficient for your needs.