# How to apply rules on incoming triplets in Neo4j graph?

Given a rule I build in a graph like (Running a Decision Tree Graph in Neo4j):

In the above graph model, we have a tree, this is what our decisions are going to fit into, and we have the first rule. The first rule asks: Are you age 21 or older? If the answer is true, then you go down to the yes node. From the `IS_TRUE` relationship, you are allowed to get into the club.

If the answer is false, and you are not age 21 or older, then we check something else. We then ask: Are you 18 or older?

Then the gender equals some gender, and we don’t know what that is just yet. And if that’s true, then that is great. That means that you are allowed to get in as well. However, if it’s false, out you go. You are not allowed in.

How can I apply these kind of rules on new triplets that will come inside the graph (node-relation-node)?

Hi,

I think so what you are trying to understand here is how can this model be dynamic, i.e. with every addition of a new rule in the form of triplets can be included into the existing model without breaking the existing model.

One suggestion here could be to use triplets for each rule separately. So like there can be triplet with main node having the rule(if age >= 21) and two result nodes based on outcome(true/false). Another separate triplet for another rule(if age>=18) and similarly its possible outputs. And another third one for the third rule(for gender).
Then have these groups/triplets connected to each other through some kind of Relationship maybe something like a relationship [:NEXT_RULE] and separate nodes for each eventual outcome (like one node for "allowed in club" and another for "cannot enter club").
So this would look something like, We first hit the first rule, see if age is greater than 21, if yes we go follow the [:TRUE] relationship and go to the left node of that triplet, then that left node goes by a relationship to the outcome node that says "allowed in club".
If in the initial rule we flow through [:FALSE] then we got to the other node of the triplet which would again flow to another rule(whether greater than 18yrs) through a relationship [:NEXT_RULE]. Then further the process will flow similarly through the next rule.