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.

Creating named graphs with complex filtering

Hello.

Consider having the following graph. There's 3 types of nodes (A,B,C) where type C has the property "Traversable" with the values "true" or "false".

I would like to create a named graph (or subgraph) that includes type C nodes depending on the value of "Traversable" as well as the position in the graph.

Let's say the nodes are structured like this (with "-" for relationships between them):
A-B-C-B-(C)-B-C-B-A

Here, I'd like to include all nodes of type A and B. If a node of type C is in the middle of the path (not first C or last C), it should be excluded if the field "Traversable" has the value "false" (and included if true). The node in question is the C-node with parenthesis around it.

How can I make a named graph/subgraph with this type of filter?

If possible, it would also be desirable to include another filter on another property. I'm thinking something like

MATCH (n) WHERE n.GROUP = 1

and then the C-node filter mentioned above.

The purpose here is to use Yen's algorithm on the mentioned subgraph so if there's any possible solution that enables it through a configuration of Yen's, it's very welcomed.

Neo4j browser version 4.2.3
GDS version 1.6.1
APOC version 4.2.0.1

Best regards
Lukas

1 REPLY 1

I managed to fix this myself, I'm including the query below for anyone else looking for a solution like this.

CALL gds.graph.create.cypher('graphname',
            'MATCH (wid {WCC_ID: <id>})
            unwind wid as n 
            with distinct n
            where (n:C)-[]-(:A {NAME:<name>})
            or (n:C)-[]-(:A {NAME:<name>})
            or n.Traversable = true
            or (n:A)
            or (n:B)
            RETURN id(n) as id',
            'MATCH (a)-[r]-(b) RETURN id(a) as source, id(b) as target, r.COST as COST',
            {validateRelationships: false});