Are there something like a regular expression for graphs?

Let's say there are graphs A and B made by A', C' and B', C'. Then They could be both matched with a graph C made by C' and X' (a graph regular expression sort?).

It's not entirely clear what part or parts of the property graph you are referring to. Is this about how nodes of labels can be matched? Or entire subgraphs? It would help if you used the language of property graphs for this, or provided some example pseudo-cypher, or used some example visuals which use property graph elements.

Let's say each node has a number, if two nodes have the same number they could match.
But some nodes would contain a set of numbers and it could match nodes who contain a subset.

You can try something like this:

merge (a:A1 {prop: [1,2,3,4]})
merge (b:B1 {prop: [1,2,3,5,6]})

match (a:A1)
match (b:B1)
RETURN apoc.coll.intersection(a.prop, b.prop)

[1, 2, 3]

Use your logic to create relationships

CREATE (c:typeA{value:3})<-[:sp]-(a :typeA{value:1})-[:sp]->(b :typeA{value:2})-[:sp]->(c)-[:sp]->(d:typeB {value:[4,5]})
CREATE (c1:typeA{value:3})<-[:sp]-(a1 :typeA{value:1})-[:sp]->(b1 :typeA{value:2})-[:sp]->(c1)-[:sp]->(d1:typeB {value:4})
CREATE (c2:typeA{value:3})<-[:sp]-(a2 :typeA{value:1})-[:sp]->(b2 :typeA{value:2})-[:sp]->(c2)-[:sp]->(d2:typeB {value:5})

The graph looks like the above when created with cypher.

Looking at this:
CREATE (c:typeA{value:3})<-[:sp]-(a :typeA{value:1})-[:sp]->(b :typeA{value:2})-[:sp]->(c)-[:sp]->(d:typeB {value:[4,5]})

The datatype of property value is string in node 'typeA' and in 'typeB' it is an array. We cannot compare two different data types. One suggestions is to make all datatypes of property 'value' to be array

Here is the modified query:

CREATE (c:typeA{value:[3]})<-[:sp]-(a :typeA{value:[1]})-[:sp]->(b :typeA{value:[2]})-[:sp]->(c)-[:sp]->(d:typeB {value:[4,5]})

This will not fetch any result when you use the function apoc.coll.intersection() because there is nothing common between typeA node and typeB node.

1 Like