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.

Running WCC with weights on anonymous graphs

Hello,

I tried the following:

CREATE (nAlice:User {name: 'Alice'})
CREATE (nBridget:User {name: 'Bridget'})
CREATE (nCharles:User {name: 'Charles'})
CREATE (nDoug:User {name: 'Doug'})
CREATE (nMark:User {name: 'Mark'})
CREATE (nMichael:User {name: 'Michael'})

CREATE (nAlice)-[:LINK {weight: 0.5}]->(nBridget)
CREATE (nAlice)-[:LINK {weight: 4}]->(nCharles)
CREATE (nMark)-[:LINK {weight: 1.1}]->(nDoug)
CREATE (nMark)-[:LINK {weight: 2}]->(nMichael);

and

CALL gds.wcc.write({
  nodeProjection: 'User',
  relationshipProjection: 'LINK',
  relationshipWeightProperty: 'weight',
  threshold: 1.0,
  writeProperty: 'componentId'}
)

but got the following error:

Failed to invoke procedure `gds.wcc.write`: Caused by: java.lang.IllegalArgumentException: Relationship weight property `weight` not found in graph with relationship properties: []

Is there a simple syntax error that I do not see? Please let me know.

1 ACCEPTED SOLUTION

You've almost got it. Conceptually, what's happening here is that GDS is "projecting" a graph out of your database into memory, and then running WCC on that. (This is important: GDS isn't running on what you have stored in Neo4j, it's on the in-memory graph) The error says that the projected in-memory graph doesn't have a "weight" property on the relationships. The reason for that is that you didn't configure GDS to project that property.

Here's the fix:

CALL gds.wcc.write({
  nodeProjection: 'User',
  relationshipProjection: 'LINK',
  relationshipWeightProperty: 'weight',
  relationshipProperties: ['weight'],
  threshold: 1.0,
  writeProperty: 'componentId'}
)

The only thing that's different:
relationshipProperties: ['weight'],

View solution in original post

2 REPLIES 2

You've almost got it. Conceptually, what's happening here is that GDS is "projecting" a graph out of your database into memory, and then running WCC on that. (This is important: GDS isn't running on what you have stored in Neo4j, it's on the in-memory graph) The error says that the projected in-memory graph doesn't have a "weight" property on the relationships. The reason for that is that you didn't configure GDS to project that property.

Here's the fix:

CALL gds.wcc.write({
  nodeProjection: 'User',
  relationshipProjection: 'LINK',
  relationshipWeightProperty: 'weight',
  relationshipProperties: ['weight'],
  threshold: 1.0,
  writeProperty: 'componentId'}
)

The only thing that's different:
relationshipProperties: ['weight'],

Docs on this are in table 5.121 here:
https://neo4j.com/docs/graph-data-science/current/algorithms/wcc/

This is an easy thing to miss, because it's one of a lot of config parameters for projecting into an anonymous graph.