Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
05-05-2021 01:30 AM
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!
Solved! Go to Solution.
05-06-2021 10:18 AM
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.
05-05-2021 12:25 PM
Hi @abhishekjayant1111, 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?
05-05-2021 09:52 PM
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).
05-06-2021 12:24 AM
Hello @abhishekjayant1111
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
05-06-2021 01:33 AM
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.
05-06-2021 01:35 AM
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}
)
05-06-2021 02:02 AM
Hi @Cobra , I do want relationships in my projection. I used validateRelationships
and ended up having 0 relationships in my projection.
05-06-2021 01:53 AM
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
05-06-2021 02:08 AM
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
05-06-2021 10:18 AM
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.
All the sessions of the conference are now available online