Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
08-11-2021 09:47 AM
Hello I have been working on NLP project for that I have to find the common relationship patterns in the two different graphs.
This is one graph
And the other one which is actually a pattern
Both graph has the common relationship pattern i.e., NN<-[:nsubj]-AUX->[:dobj].So,how to match with this similarity and show that the graph1 matches the graph2 patterns?
Could anyone know about this please?
I tried the adjacency matrix concept but it didn't work out.
Thanks
Vigneshwar
08-11-2021 01:33 PM
I created the data.
CREATE (each:DT {word:"Each"}),
(confirmation:NN {word:"confirmation"}),
(window:NN {word:"window"}),
(has:AUX {word:"has"}),
(a:DT {word:"a"}),
(close:JJ {word:"close"}),
(button:NN {word:"button"})
CREATE (each)<-[:det]-(window),
(confirmation)<-[:compound]-(window),
(window)<-[:nsubj]-(has),
(has)-[:dobj]->(button),
(a)<-[:dobj]-(button),
(close)<-[:amod]-(button)
Search for this in the pattern and it will match.
MATCH (nn1:NN)<-[:nsubj]-(aux:AUX)-[:dobj]->(nn2:NN)
RETURN *
Is this an answer to your question?
08-12-2021 01:13 AM
Hello @koji Yes! Thanks for your reply and an idea.
Similar like this I have other patterns such as,
In this one pattern can't match with the main graph.
Because the main graph don't have relationship from POS tag NN<-[:nsubj]-VB-[:dobj]->NN
And,I might have to check with many patterns like this.Each patterns has the number like 1,2,3, so on ... Which patterns get matched ,the number or id of it should be returned.
So,is it possible to check with all the patterns simultaneously whether it matches the relationship with the main graph?
Please let me know..
Thanks
Vigneshwar
08-12-2021 03:36 AM
I made this Cypher.
It's not cool codes.
OPTIONAL MATCH (nn1:NN)<-[:nsubj]-(aux:AUX)-[:dobj]->(nn2:NN)
WITH "Pattern1" + collect(id(nn1)) + collect(id(aux)) + collect(id(nn2)) AS list1
OPTIONAL MATCH (nn1:NN)<-[:nsubj]-(vb:VB)-[:dobj]->(nn2:NN)
RETURN list1, "Pattern2" + collect(id(nn1)) + collect(id(vb)) + collect(id(nn2)) AS list2
Pattern 1 shows the id of the node.
Pattern 2 has no id because there is no match.
08-12-2021 05:22 AM
Thanks for your reply This solution works for me.
However, By using this I can match the main graph with few patterns manually.But,I will have many patterns which is actually the subgraphs. So, dynamically need to find the common relationship between the main graph and the many other patterns.
Is it possible? Can you give any suggestions please?
Thanks
VIGNESHWAR
08-13-2021 01:26 AM
I think this code is better than the previous one.
Now you just add more MATCH patterns with UNION ALL.
If you know the id of the nodes used in the main graph, you can add it to the Where clause to make the search faster.
Since the main graph is a sentence, you can repeat this process.
OPTIONAL MATCH (nn1:NN)<-[:nsubj]-(aux:AUX)-[:dobj]->(nn2:NN)
RETURN 1 AS Pattern, collect(id(nn1)) + collect(id(aux)) + collect(id(nn2)) AS idList
UNION ALL
OPTIONAL MATCH (nn1:NN)<-[:nsubj]-(vb:VB)-[:dobj]->(nn2:NN)
RETURN 2 AS Pattern, collect(id(nn1)) + collect(id(vb)) + collect(id(nn2)) AS idList
08-13-2021 04:23 AM
Hi @koji Thanks for your reply This code is good and helpful.Actually,I'm trying to MATCH my main graph with the other patterns to find the common relationship i.e., Whether it's a subgraph or not.So,manually I can do as you suggested say for few patterns.But,I will have nearly 100 patterns to be check with the main graph.
All that patterns will be saved in the same database as different labeled nodes.So,I'm searching for the idea to find the match between the main graph with the hundreds of patterns.
It will return which pattern has been matched.Is there any possible way for that to make the main graph itself check automatically ?
Please let me know.
Thanks
VIGNESHWAR
08-16-2021 06:35 AM
How about using the Triggers to check when a document is added?
https://neo4j-contrib.github.io/neo4j-apoc-procedures/3.5/operational/triggers/
All the sessions of the conference are now available online