# Use Similarity graph algorithm to include shared nodes in the 2nd degree

Hello, I have a graph in this image:

There are Person nodes, which are connected to Car nodes, and the Car nodes are all connected to a Fuel node (Gasoline).

Here is my code to make the graph projection:

// Make a Similarity Projection based on connections.
CALL gds.graph.project(
'myGraph',
// Nodes to include
['Person', 'Car', 'Fuel'],
{
//// Relationships to include
DRIVES: {

},
USES_FUEL: {

}
}
)

Here is my code to check the Similarity:

// Get similarity of Persons
CALL gds.nodeSimilarity.stream('myGraph')
YIELD node1, node2, similarity
where gds.util.asNode(node1):Person and gds.util.asNode(node2):Person
RETURN gds.util.asNode(node1).name AS Person1, gds.util.asNode(node2).name AS Person2, similarity
ORDER BY similarity DESCENDING, Person1, Person2

This query returns no changes, no records.

I understand why it does this, but I'm asking if there is maybe a way where I could get some similarity score based off of a connection type like this.

This graph is an example I made for the question. I will be utilizing a graph with a lot more data, connections, and situations like this.

Thank you!

I think what is happening is that your are not getting any results back for the Person nodes, since they have not relationships to a common node. If you remove your 'where' clause, you will get back similarities for the Car nodes, which all have a similarity of 1 since they all have a single relationship to the same Fuel node.

If you add a person that shares a car, then you will get a similarity score between the two. In the example graph below, Eve and Bob have a similarity score of 1.

If you add a connection from Bob to another Car, then similarity between 1) Bob and Eve and 2) Bob and Alice is 0.5 for both pairs of Persons.

As you can see, the similarity between people does not go through two relationships to the common Fuel entity. The Cars have a similarity measure between them since they are related to Fuel via the USES_FUEL relationship.

Hi, thanks for your answer. Regarding the last paragraph-- is there any way to calculate similarity between people through two relationships?

You want to measure the similarity to Persons based on similar fuel types? I guess you could create relationships between person and fuel nodes. You can delete them after projecting the graph.

Match(p:Person)-[:DRIVES]->(:Car)-[: USES_FUEL]->(f:Fuel)
create(p)-[:PERSON_TO_FUEL]->(f)

Then project Person and Fuel nodes, along with PERSON_TO_FUEL relationship

After projection, you can delete the relationships
match()-[r:PERSON_TO_FUEL]->()
Delete r