graphneo4jcyphergraph-theorypagerank

How to create a weighted vertices in Cypher for Graph Database?


I am trying to understand which user has the most influence based on the amount of the reviews that was done by the user, i user the following code to project my graph

CALL gds.graph.project.cypher(
            'last_try',
            'match (n) WHERE (n:USER) OR (n:REVIEWS) return id(n) AS id',
            'MATCH (u:USER)<-[:POSTED]-(r:REVIEWS)<-[:REVIEWED]-(b:BEERS)
            RETURN id(u) AS source, id(b) AS target, count(distinct r) as weight'
            )

I am trying to create a weight variable but when i run it through the algorithm, i do not receive anything, or ai receive static values

CALL gds.pageRank.stream('last_try', {relationshipWeightProperty:'weight'})
            YIELD nodeId, score
            RETURN gds.util.asNode(nodeId).username AS name, score
            ORDER BY score desc
            limit 5
    

Also here is the algorithm that i am trying to run but unsuccessfully i can not get a logic result

I tried to implement different solutions, but i did not manage to find any solution, i tried to count the attributes of the reviews made by those users, and the hard part is to understand what to attribute to the weight parameter.


Solution

  • Below is the query to put the number of reviews done by that user. It will put a new property 'weight' on REVIEWS based on the number of times that user posted a review on any beer.

    MATCH (u:USER)
    WITH u
    MATCH (u)<-[p:POSTED]-(r:REVIEWS)<-[rw:REVIEWED]-(b:BEERS)
    WITH u, count(r) as cnt, collect(distinct r) as reviews
    UNWIND reviews as r
    SET r.weight =  cnt
    

    For example:

    ╒════════════════════════════════╕
    │"review"                        │
    ╞════════════════════════════════╡
    │{"review":"review11","weight":2}│
    ├────────────────────────────────┤
    │{"review":"review12","weight":2}│
    ├────────────────────────────────┤
    │{"review":"review21","weight":1}│
    ├────────────────────────────────┤
    │{"review":"review32","weight":1}│
    └────────────────────────────────┘