Difficulty upgrading older algo stream query to graph projection and GDS for LPA community detection

Hi all,

I'm trying to migrate and upgrade my graph to the latest version of Neo4j and make use of new features and GDS algorithms. The old LPA community detection query was as follows:

CALL algo.labelPropagation.stream(
'MATCH (p:Publication) RETURN id(p) as id',

'MATCH (p1:Publication)-[r1:HAS_WORD]->(w)<-[r2:HAS_WORD]-(p2:Publication)
WHERE r1.occurrence > 5 AND r2.occurrence > 5
RETURN id(p1) as source, id(p2) as target, count(w) as weight',

{graph:'cypher',write:false, weightProperty : "weight"})

yield nodeId, label

WITH
label, collect(algo.asNode(nodeId)) as nodes where size(nodes) > 2
MERGE (c:PublicationLPACommunity {id : label})
FOREACH (n in nodes |
 MERGE (n)-[:IN_LPA_COMMUNITY]->(c)
)

return label, nodes

I've been trying to understand the documentation for projecting a graph then performing community detection - and I think I've been close - but I just don't fully understand what is happening and how to project it correctly first in order to perform the LPA.
Here is my code so far:

CALL gds.graph.project.cypher(
  'testProjection',
  'MATCH (p:Publication) RETURN id(p) AS id',
  'MATCH (p:Publication)-[r1:HAS_WORD]->(w)<-[r2:HAS_WORD]-(p2:Publication) WHERE r1.occurrence > 5 AND r2.occurrence > 5 RETURN id(p1) as source, id(p2) as target, count(w) as weight'
)
YIELD
  graphName AS graph, nodeCount AS nodes, relationshipCount AS rels, weightProperty AS weight

I think I'm mixing up elements of the projection and elements of the algorithm - I can't get it working. I've managed to make simple graph projections with the Publication nodes in the past - but it seems like that isn't enough information to perform the LPA algorithm - I could but thinking about this incorrectly also.

Any help very much appreciated.

You're on the right track.

Now you can run arbitrary algorithms on this projected graph named "testProjection"

e.g.

https://neo4j.com/docs/graph-data-science/current/algorithms/label-propagation/

CALL gds.labelPropagation.stream('testProjection', { relationshipWeightProperty: 'weight' })
YIELD nodeId, communityId AS Community
RETURN gds.util.asNode(nodeId).name AS Name, Community
ORDER BY Community, Name

https://neo4j.com/docs/graph-data-science/current/algorithms/label-propagation/#algorithms-label-propagation-examples-weighted