Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
07-23-2021 12:57 AM
I have a group of nodes connected like this:
Within a group, each of the nodes will be connected to similar nodes by 1 or more hops.
I need to get a group members separately ? Not really worried about how they are connected, as long as they are connected, they should be returned.
How can I do this?
I am expecting this result from the above graph:
[0,1,2,3,4]
[5,6,7,8,9]
Solved! Go to Solution.
07-23-2021 02:50 PM
You were pretty close
CALL gds.wcc.stream({
nodeProjection: "*",
relationshipProjection: "*"
})
YIELD nodeId, componentId
WITH componentId, gds.util.asNode(nodeId) AS n
WHERE n:Label
RETURN componentId, collect(n.name) AS nodes
07-23-2021 12:59 AM
07-23-2021 12:02 PM
Thank you @Cobra for helping.
Actually all these nodes are not directly connected... there may be some other nodes and relationships in between them, how do we specify them in the WWC query?
I have below nodes and relationships:
create(d:Label{name:"D"})
create(d1:Label{name:"D1"})
create(d2:Label{name:"D2"})
create(d3:Label{name:"D3"})
create(d4:Label{name:"D4"})
create(d5:Label{name:"D5"})
create(c1:CLabel{name:"c1"})
create(c2:CLabel{name:"c2"})
create(c3:CLabel{name:"c3"})
create(c4:CLabel{name:"c4"})
create(c5:CLabel{name:"cs"})
create(e:Label{name:"e"})
create(e1:Label{name:"e1"})
create(e2:Label{name:"e2"})
create(e3:Label{name:"e3"})
create(e4:Label{name:"e4"})
create(e5:Label{name:"es"})
create(f1:CLabel{name:"f1"})
create(f2:CLabel{name:"f2"})
create(f3:CLabel{name:"f3"})
create(f4:CLabel{name:"f4"})
create(f5:CLabel{name:"fs"})
MERGE (d)-[:CONTAINS]->(c1)-[:CONNECTED]->(d1)
MERGE (d)-[:CONTAINS]->(c2)-[:CONNECTED]->(d2)
MERGE (d)-[:CONTAINS]->(c3)-[:CONNECTED]->(d3)
MERGE (d)-[:CONTAINS]->(c4)-[:CONNECTED]->(d4)
MERGE (d)-[:CONTAINS]->(c5)-[:CONNECTED]->(d5)
MERGE (e)-[:CONTAINS]->(f1)-[:CONNECTED]->(e1)
MERGE (e)-[:CONTAINS]->(f2)-[:CONNECTED]->(e2)
MERGE (e)-[:CONTAINS]->(f3)-[:CONNECTED]->(e3)
MERGE (e)-[:CONTAINS]->(f4)-[:CONNECTED]->(e4)
MERGE (e)-[:CONTAINS]->(f5)-[:CONNECTED]->(e5)
RETURN *
I expect this result:
[D,D1,D2,D3,D4,D5]
[E,E1,E2,E3,E4,E5]
This query is not giving me expected results!
CALL gds.wcc.stream({
nodeProjection: "Label",
relationshipProjection: "CONNECTED"
})
YIELD nodeId, componentId
RETURN componentId, collect(gds.util.asNode(nodeId).name) AS myNodes
ORDER BY size(myNodes) DESC;
How to solve this problem now ?
07-23-2021 02:50 PM
You were pretty close
CALL gds.wcc.stream({
nodeProjection: "*",
relationshipProjection: "*"
})
YIELD nodeId, componentId
WITH componentId, gds.util.asNode(nodeId) AS n
WHERE n:Label
RETURN componentId, collect(n.name) AS nodes
All the sessions of the conference are now available online