neo4j-contrib / neo4j-graph-algorithms

Efficient Graph Algorithms for Neo4j
https://github.com/neo4j/graph-data-science/
GNU General Public License v3.0
769 stars 195 forks source link

Cypher projection for PageRank does not work with when using parameter weightProperty #847

Closed mading0817 closed 5 years ago

mading0817 commented 5 years ago

The graph has node label with Person and relationship type with Human_Relation. Each relationship has a property which is called "weight" with initial value 0.5 I wish to use PageRank by cypher projection as followed:

CALL algo.pageRank( 'MATCH (p:Person) RETURN id(p) as id', 'MATCH (p1:Person)-[]-(p2:Person) RETURN id(p1) as source, id(p2) as target', {graph:'cypher', direction: 'BOTH', iterations:20, dampingFactor:0.85, write: true, writeProperty:"influence", direction: 'BOTH', weightProperty: 'weight'} )

I got the following result: image

and the stream result as followed: image

As the influences are all the same, the PageRank obviously did not work the result shows correctly if I did not use cypher projection: CALL algo.pageRank('Person', 'Human_Relation',{ iterations:20, direction:'both', dampingFactor:0.85, write: true, writeProperty:"influence", weightProperty: "weight" }) YIELD nodes, iterations, loadMillis, computeMillis, writeMillis, dampingFactor, write, writeProperty

So is this a bug or cypher projection does not support weightProperty or somewhere I had made a mistake?

Thanks, Regards

tomasonjo commented 5 years ago

Try returning weight in the relationship cypher statement:

CALL algo.pageRank( 
  'MATCH (p:Person) RETURN id(p) as id', 
  'MATCH (p1:Person)-[r]-(p2:Person) RETURN id(p1) as source, id(p2) as target, r.weight as weight',
   {graph:'cypher', direction: 'BOTH', iterations:20, dampingFactor:0.85, write: true,
    writeProperty:"influence", weightProperty: 'weight'} ) YIELD nodes
mading0817 commented 5 years ago

Thanks a lot! It did work!!