cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

3.5.14 nodeSimilarity create a single relationship between two nodes

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

2X_9_9438615519b6ee76cc50190f4513bc8704ba28e7.png

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!

8 REPLIES 8

MuddyBootsCode
Graph Steward

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

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:
2X_9_98551a63e0471185d93b49c2bf95aa4733cc6124.png

Not all of them happened like this, most of them will return 2 relationships:
2X_3_364ac6ca18bd52459b7548aa60882b8fec16372f.png

Thanks

MuddyBootsCode
Graph Steward

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?

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.
2X_9_9438615519b6ee76cc50190f4513bc8704ba28e7.png
And some of them have created 2 relationships after calling nodeSimilarity
2X_3_364ac6ca18bd52459b7548aa60882b8fec16372f.png

Hope you get my point this time
Thanks

MuddyBootsCode
Graph Steward

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.

Yes indeed, the docs' example is using outgoing, in my case, I use incoming otherwise the nodeSimilarity will not work.

MuddyBootsCode
Graph Steward

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.

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
2X_a_a6fc5dbdd7b3b9c7d64f40e75599c2c57127ce6c.png
2X_6_66c64341fc61cc67fd651b7cc4b4fba702fc1c94.png

Thanks