0

I have a problem trying to "decypher" a logical tree with Neo4js Cypher.

I have a logical tree of Operation to Leaves. I want to collect valid sets of Leaves. I am currently trying to collect valid Sets of Leaves on a Valid Configuration Node. So I can later quickly path through that Configuration node.

Example (1 AND 2) AND (3 AND 4) Is easy to match (rule)-[AND*]->(leaf) return collect(leaf) However (1 XOR 2) AND (3 XOR 4) Is a problem because whenever I collect 1,2,3,4 in a single variable, I cannot later properly get the cartesian product of the AND Operation. (13,14,23,24) would be valid.

In general I have a tree of variable depth (upto max about 3-4) Operations are XOR, AND, Not AND, Not XOR

  • Is there a simple way in Cypher I am missing for navigating such trees?
  • Is trying to merge Valid Sets in a ValidConfiguration Node a good idea for fast Queries?
  • Later it should support a query of the form (:Model)->(:ValidConf)->(:Leaf:Option)->(:Feature) then return all models that have a certain Feature in a valid configuration. Or multiple Features at a certain configuration price.

  • Do I need UDFs or ObjectGraphMapper to get this problem solved? Are there any UDFs that work with such decision trees which I can use?

Any help would be highly appreciated.

Create Example

CREATE (r:Rule{id:123})-[:COMPOSITION]->
startOp:AndOperation:Operation:Operand)
CREATE (startOp)-[:AND]->(intermediateOp1:OrOperation:Operation:Operand)
CREATE (startOp)-[:AND]->(intermediateOp2:OrOperation:Operation:Operand)
CREATE (intermediateOp1)-[:XOR]->(o1:Option:Operand{id:321})
CREATE (intermediateOp1)-[:XOR]->(o2:Option:Operand{id:564})
CREATE (intermediateOp2)-[:XOR]->(o3:Option:Operand{id:876})
CREATE (intermediateOp2)-[:XOR]->(o4:Option:Operand{id:227})
CREATE (o1)-[:CONSISTS_OF]->(f1:Feature{text:"magicwand"})
....

This tree is symmetric but they usually aren't. I need to make o1 + o4 be valid and o1 + o2 to not be valid. The OR are to be understood as XOR.

Luanne
  • 19,145
  • 1
  • 39
  • 51
samst
  • 536
  • 7
  • 19

1 Answers1

1

I don't think Cypher is going to work for evaluating a boolean binary expression tree. To quote cybersam's answer to a related question:

This is because Cypher has no looping statements powerful enough to iteratively calculate subresults (in the correct order) for trees of arbitrary depth.

You're going to have to look for some additional system to do the evaluation.

If you can code Java, you should be able to do this by implementing your own custom procedure to evaluate a boolean expression tree in the correct order.

Community
  • 1
  • 1
InverseFalcon
  • 29,576
  • 4
  • 38
  • 51