I want to use similarity algorithm and for that, I am trying to create a native projection which has nodes having a specific name (for example, create a native graph containing nodes of label 'Person' where name of the person is 'Carl' and 'John'). Thanks in advance!
Hi @abhishekjayant1, Iām not sure of what your question is
But you can create your nodes with Person as label and names as properties and then launch the algorithm on the native projection. Does it answer your question?
Hi @tlibersat , thanks for your reply. This didn't answer my question. I want to create a native projection, which has nodes of label 'Person' and their names should be 'Carl' and 'John' ( I want to basically select a few nodes from 'Person' nodes on the basis of their name).
Hello @abhishekjayant1
You will have to use gds.graph.create.cypher:
CALL gds.graph.create.cypher(
'my-cypher-graph',
'MATCH (n:Person) WHERE n.name IN ["Carl", "John"] RETURN id(n) AS id',
'MATCH (n)-->(m) RETURN id(n) AS source, id(m) AS target'
)
Regards,
Cobra
Hi @cobra , thanks for your reply. I used the above query I got an error saying:
"Failed to invoke procedure gds.graph.create.cypher
: Caused by: java.lang.IllegalArgumentException: Failed to load a relationship because its source-node with id 732 is not part of the node query or projection. To ignore the relationship, set the configuration parameter relationshipValidation
to false."
How can I set this property to false in the cypher projection?
Thanks a lot for all of your responses, I feel great to be a part of this wonderful community.
You only want nodes in your projection, no relationships?
Here is the link to the Github issue.
CALL gds.graph.create.cypher(
'my-cypher-graph',
'MATCH (n:Person) WHERE n.name IN ["Carl", "John"] RETURN id(n) AS id',
'MATCH (n)-->(m) RETURN id(n) AS source, id(m) AS target',
{validateRelationships: False}
)
Hello @alicia_frame1
I think there is an issue with the error message:
"Failed to invoke procedure
gds.graph.create.cypher
: Caused by: java.lang.IllegalArgumentException: Failed to load a relationship because its source-node with id 732 is not part of the node query or projection. To ignore the relationship, set the configuration parameterrelationshipValidation
to false."
But it should be validateRelationships
instead of relationshipValidation
.
I also think the documentation is not updated with this new configuration parameter
Regards,
Cobra
Hi @cobra , I do want relationships in my projection. I used validateRelationships
and ended up having 0 relationships in my projection.
That's why you should select all Person
nodes in your graph. If you really want to select a few Person
nodes, you must make sure they have relationships between them. For example, Carl
and John
must be directly connected together. The validateRelationships
must be used when you only want nodes. So in your case, you should use this query:
CALL gds.graph.create.cypher(
'my-cypher-graph',
'MATCH (n:Person) RETURN id(n) AS id',
'MATCH (n)-->(m) RETURN id(n) AS source, id(m) AS target'
)
After if you are only interested about John
and Carl
similarity results from the algortihm:
CALL gds.nodeSimilarity.stream('my-cypher-graph')
YIELD node1, node2, similarity
WITH gds.util.asNode(node1).name AS p1, gds.util.asNode(node2).name AS p2, similarity
WHERE p1 = "John" AND p2 = "Carl"
RETURN p1, p2, similarity
@cobra - I've created a card and we'll fix the error message
Solution of the thread (done by private message).
First, I create the projection of the whole graph:
CALL gds.graph.create('graph', '*', '*')
Then I compute similarity on it:
CALL gds.nodeSimilarity.stream('graph')
YIELD node1, node2, similarity
WITH gds.util.asNode(node1) AS n1, gds.util.asNode(node2) AS n2, similarity
WHERE n1:Adverse_Event
AND n2:Adverse_Event
AND exists((n1)-[:reports]->(:SideEffect {SideEffect: "death"}))
AND exists((n2)-[:reports]->(:SideEffect {SideEffect: "death"}))
RETURN n1, n2, similarity
I don't know the name of the property in the SideEffect node so I put SideEffect as property name.