2

I want to write a neo4j query, that finds a 'knitting' pattern. With that I basically mean a set of four nodes with three special edges between them. And continuing these four, there can be a next set of four nodes, that are connected by three other edges, like this (in some Cypher-like syntax with vertical edges.

    (n1)-[:e1]-(n2)-[:e2]-(n3)-[:e3]-(n4)
     |          |          |          |
   [:ew]      [:ex]      [:ey]      [:ez]        
     |          |          |          |
    (n5)-[:e1]-(n6)-[:e2]-(n7)-[:e3]-(n8)
     |          |          |          |
   [:ew]      [:ex]      [:ey]      [:ez]        
     |          |          |          |
    (n?)-[:e3]-(n!)-[:e3]-(n&)-[:e3]-(n$)
     .          .          .          .
     :          :          :          :

I can write a query for exactly 8, 12 or 16... nodes, that are connected in this way. But I would like to write it more general to get the longest connected components, that are knitted like this.

Can you give me a hint, how to go along with that, because I'm totally new to neo4j?

Prodiction
  • 187
  • 12
  • Does your "knitting pattern" have a defined start? E.g., `(n1)` has only one `[:ew]` relationship so it's a start/endpoint? Is your "knitting pattern" just 2D like your example, or could it extend into more dimensions? – rickhg12hs Feb 09 '19 at 05:04
  • For my case you are totally right. For others it may be quite well to keep that open. But that isn't here the case. – Prodiction Feb 09 '19 at 09:57
  • Have you tried something like `MATCH ()-[:ew]-(n1)-[:e1]-(n2)-[:e2]-(n3)-[:e3]-(n4)-[:ez]-() WHERE (n2)-[:ex]-() AND (n3)-[:ey]-() RETURN DISTINCT n1, n2, n3, n4` ? – rickhg12hs Feb 09 '19 at 17:37
  • I think then I don't get the rows then singularly and not as connected components of 8, 12... nodes. Calling then the connected components doesn't work, because (n1) can connect to (n2) as well connect to (n3). I wished that the connected components algorithm had instead of the partition-string a list of strings, like groupby in python-pandas. https://neo4j.com/docs/graph-algorithms/current/algorithms/connected-components/ I think I also can infer a node, that has the ids of (n1) to (n4) and (n5) to (n8), and for some other node (n1)-(n4) or (n5) to (n8) they are about to be connected. – Prodiction Feb 12 '19 at 03:05
  • Ah, OK. I thought "a set of four nodes" actually meant "a sequence of four nodes" and that's all you needed. So, you actually want all the nodes with all their "knitting pattern" connections?... Do you want to exclude patterns where `(n1)` is connected to `(n3)`? I.e., even if the other desired connections are present, if that connection is also present, those nodes and connections should be excluded from the result. – rickhg12hs Feb 12 '19 at 07:41

0 Answers0