Inference rule applied to the entire tree and not to a particular path


#1

Hi,

I have a tree of entities; each connected by a generic relationship. (Product-Coverage-Medical_Benefit-Plan)
Each entity has associated with a different type of entity. (Benefit_Condition)
What I tired was to gather all conditions associated to a particular node and anything above from that node by the inference rule. I initially ended up with getting all conditions in the tree, then I find the right way later. However, I still don’t quite understand why the first attempt didn’t work as I expected.

I appreciate if someone can explain it to me.
Also I appreciate if anyone can define the rule in a smarter way.

Thank you in advance.

Entities:

product sub entity
plays parent
plays limited-by;

coverage sub entity
plays parent
plays child
plays limited-by;

medical_benefit sub entity
plays parent
plays child
plays limited-by;

plan sub entity
plays child
plays limited-by;

benefit_condition sub entity
plays limits;

Relationships:

benefit-hierarchy sub relationship
relates parent
relates child;
parent sub role;
child sub role;

condition-limit sub relationship
relates limited-by
relates limits;
limited-by sub role;
limits sub role;

1st attempt (I got conditions for the entire tree):

define
    delegate-limitation sub rule,
        when {
            ($parent, $child) isa benefit-hierarchy;
            ($parent, $limit) isa condition-limit;
        } then {
            (limited-by:$child, limits:$limit) isa condition-limit;
        };

2nd attempt (I got the right set of conditions):

define
    delegate-limitation-product-coverage sub rule,
        when {
            $product isa product;
            $coverage isa coverage;
           ($product, $coverage) isa benefit-hierarchy;
           ($product, $limit) isa condition-limit;
        } then {
           (limited-by:$coverage, limits:$limit) isa condition-limit;
        };

    delegate-limitation-coverage-benefit sub rule,
        when {
            $coverage isa coverage;
            $benefit isa medical_benefit;
           ($coverage, $benefit) isa benefit-hierarchy;
           ($coverage, $limit) isa condition-limit;
        } then {
           (limited-by:$benefit, limits:$limit) isa condition-limit;
        };

    delegate-limitation-benefit-plan sub rule,
        when {
            $benefit isa medical_benefit;
            $plan isa plan;
           ($benefit, $plan) isa benefit-hierarchy;
           ($benefit, $limit) isa condition-limit;
       } then {
          (limited-by:$plan, limits:$limit) isa condition-limit;
       };

#2

Can you try specifying the roles in the body of your first rule? I. e. something like this:

define
    delegate-limitation sub rule,
        when {
            (parent: $parent, child: $child) isa benefit-hierarchy;
            (limited-by: $parent, limits: $limit) isa condition-limit;
        } then {
            (limited-by:$child, limits:$limit) isa condition-limit;
        };

Let me know if that makes a difference. My suspicion is that with added types the roles can be inferred, without the roles you create a potential ambiguity (your $parent roleplayer can either play the role of parent or child, there’s nothing constraining it to be an actual parent), hence unexpected results.


#3

kasper,

Your fix worked wonderfully.

Thank you!