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.

Strongly Connected Components

Hello,

I have this query

CALL gds.alpha.scc.stream({

   nodeQuery: 'MATCH (Compartment{dbId:74700})<-[:compartment]- 
  (rle:Reaction{speciesName:"Homo sapiens"})-[:input]-> 
  (pe:PhysicalEntity{speciesName:"Homo sapiens"}) return id(rle) AS id UNION MATCH 
  (Compartment{dbId:74700})<-[:compartment]-(rle:Reaction{speciesName:"Homo 
   sapiens"})-[:input]->(pe:PhysicalEntity{speciesName:"Homo sapiens"})   RETURN id(pe) 
   AS id',

  relationshipQuery: 'MATCH (Compartment{dbId:74700})<-[:compartment]- 
  (rle:Reaction{speciesName:"Homo sapiens"})-[i:input]-> 
  (pe:PhysicalEntity{speciesName:"Homo sapiens",stId:"R-HSA-9610136"})- 
  [:compartment]->(Compartment{dbId:74700}) RETURN id(rle) AS source, id(pe) AS 
  target' }) 
 YIELD nodeId, componentId 
  RETURN gds.util.asNode(nodeId) AS Name, componentId AS Component

I would like to use the scc algorithm.

My problem is That I want to display only the nodes that have an 'input' relationship.
Currently this query shows me all the relationships of the various nodes.
You can help me?
Thanks

1 ACCEPTED SOLUTION

At first sight, I can see different SCC. When a path exists in both directions for each pair of nodes then the pair will be in the same connected component. In your image, I can see different subgraphs where nodes have paths connecting them in both directions.

View solution in original post

7 REPLIES 7

Hi Daniela,
for what I'm seeing you're just returning the name of the node and the id of the connected component the node belongs to. If you want to show the input relationships you have at least do something like that:

CALL gds.alpha.scc.stream({

   nodeQuery: 'MATCH (Compartment{dbId:74700})<-[:compartment]- 
  (rle:Reaction{speciesName:"Homo sapiens"})-[:input]-> 
  (pe:PhysicalEntity{speciesName:"Homo sapiens"}) return id(rle) AS id UNION MATCH 
  (Compartment{dbId:74700})<-[:compartment]-(rle:Reaction{speciesName:"Homo 
   sapiens"})-[:input]->(pe:PhysicalEntity{speciesName:"Homo sapiens"})   RETURN id(pe) 
   AS id',

  relationshipQuery: 'MATCH (Compartment{dbId:74700})<-[:compartment]- 
  (rle:Reaction{speciesName:"Homo sapiens"})-[i:input]-> 
  (pe:PhysicalEntity{speciesName:"Homo sapiens",stId:"R-HSA-9610136"})- 
  [:compartment]->(Compartment{dbId:74700}) RETURN id(rle) AS source, id(pe) AS 
  target' }) 
 YIELD nodeId, componentId 
WITH nodeId
MATCH p = (pe:PhysicalEntity)<-[:input]-()
WHERE id(pe) = nodeId
RETURN p

But of course, you need a way to distinguish your components when you visualize them. So maybe using Bloom can help you with this task.
I'm not sure this will answer your question.

What I can add is that probably in your nodeQuery you're doing the same query twice and you don't need to do a "union". The second query also extracts the nodes of the first one.

I changed the query but I don't get a strongly connected components
I get it

At first sight, I can see different SCC. When a path exists in both directions for each pair of nodes then the pair will be in the same connected component. In your image, I can see different subgraphs where nodes have paths connecting them in both directions.

Dear all,

I am using Neo4j Desktop, Graph Data Science Library 2.2.3, and Neo4j Server 4.4.14.

I am wondering whether the interface of

gds.alpha.scc.stream

is changed?

Since when I try the queries in this discussion, I get

Type mismatch: expected String but was Map (line 2, column 27 (offset: 39))
" CALL gds.alpha.scc.stream({"
^}

Thanks in advance for your answer!

Pierre

Hello @pjljvandelaar 🙂

The procedure name has changed, check here.

Regards,
Cobra

Dear Cobra,

I really need strongly connected and not weakly connected components.

I solved it by first creating a subgraph (using gds.graph.project[.cypher]),
then calling the current scc function on that subgraph,
and finaly droppping the subgraph (using gds.graph.drop).

Greetings,
Pierre

Oh sorry, the current documentation of SCC is here.