Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
03-25-2020 06:31 AM
Hi,
According to documentation, it seems that nodeSimilarity will create 2 relationships with different direction between the compared two nodes.
Somehow I got 1 relationship between 2 compared nodes:
MATCH (n:Sub_Field)-[s:SIMILAR]-(m:Sub_Field)
WHERE n.id = 2 and m.id = 14
RETURN n,m
My query as followed:
CALL algo.nodeSimilarity('Sub_Field | Project', 'PROJECT_SUB_FIELD_BELONG', {
direction: 'INCOMING',
write: true
})
YIELD nodesCompared, relationships, write, writeProperty, writeRelationshipType;
Is this normal? What cause that if it is normal?
By the way, how do I use cypher projection to express a complex path like
'MATCH (male:Male) RETURN id(male) as id',
(s:School)--(n:Male)-[:LIKE]-(:Books)-[:LIKE]-(m:Male), (s)--(m)
RETURN id(n) as source, id(m) as target'
I want to create the similarity of male students who are in the same school according to books they like. Assume there are many schools and Game node (like Books mentioned) type between males.
Thanks for helping!
03-25-2020 07:30 AM
I think you'd also need to return the relationship as well to get multiple relationships back. I'm not sure it does that by default so
MATCH (n:Sub_Field)-[s:SIMILAR]-(m:Sub_Field)
WHERE n.id = 2 and m.id = 14
RETURN n,s,m
Give that a shot
03-25-2020 07:37 AM
Hi Porter,
Thanks for helping.
I tried what you suggested
MATCH (n:Sub_Field)-[s:SIMILAR]-(m:Sub_Field)
WHERE n.id = 2 and m.id = 14
RETURN n,m,s
It returns the same:
Not all of them happened like this, most of them will return 2 relationships:
Thanks
03-25-2020 07:54 AM
Ah sorry didn't quite grok what you were asking. It may be possible that you got a typo in there somewhere. Did you try to clear the graph and start again?
03-25-2020 08:20 AM
Hi Porter,
Sorry about the confusion and forgive my poor English.
I am asking if I use nodeSimilarity to compute similarity, is it possible to happen that only one similar relationship was created between the compared 2 nodes?
Because the official example shows that there are two relationships would be created after calling nodeSimilarity.
After calling nodeSimilarity:
Alice -> Dave
Dave-> Alice
2 relationships(opposite directions) are created between Alice and Dave
Alice -> Bob
Bob-> Alice
2 relationships(opposite directions) are created between Alice and Bob
And also the same for Carol and Alice, Dave and Carol, Bob and Dave.
But in my case, some compared nodes only have created 1 relationship between them after calling nodeSimilarity.
And some of them have created 2 relationships after calling nodeSimilarity
Hope you get my point this time
Thanks
03-25-2020 08:24 AM
If you're trying to recreate the example given in the Docs it looks like you have a different relationship direction. Incoming vs. outgoing in the example. That may affect the results you're getting.
03-25-2020 08:35 AM
Yes indeed, the docs' example is using outgoing, in my case, I use incoming otherwise the nodeSimilarity will not work.
03-25-2020 08:36 AM
Are you doing anything differently besides that? Have a cut off? Does that node match others in your graph that have multiple similarity relationships or scores? Seems like something of that nature is happening.
03-25-2020 08:43 AM
I did not have a cut off or anything else.
Just the following query I used:
CALL algo.nodeSimilarity('Sub_Field | Project', 'PROJECT_SUB_FIELD_BELONG', {
direction: 'INCOMING',
write: true
})
YIELD nodesCompared, relationships, write, writeProperty, writeRelationshipType;
The node with id 2 and the node with id 14 both have other matchs with multiple similarity relationships
Thanks
All the sessions of the conference are now available online