0

I'm trying to insert this rule (data is masked):

when {
    $d isa person; 
    $a isa animal; 
    $r (role-1: $d, role-2: $a) isa relation-1, has attr $ds; 
    not {$r1 (role-3: $d, role-4: $a) isa relation-2; };
    $ds > 0.5;
}, then {
    (role-3: $a, role-4: $d, role-5: $ds) isa relation-2;
};

However I keep getting this structural validation error after I do commit. Please help

INVALID_ARGUMENT: InvalidKBException-A structural validation error has occurred. Please correct the [`1`] errors found. 
The rule graph is not stratifiable - it contains following cycles with negation: [[[Base Type [RELATION_TYPE] - Id [V65648]  - Label [relation-2] ]]]
. Please check server logs for the stack trace.
All uncommitted data is cleared
user7420209
  • 225
  • 2
  • 10

1 Answers1

0

Rules that cause loops - for example, where the conclusion is negated in the when clause - are not allowed in Grakn.

Here's an example to demonstrate why.

define
person sub entity, plays employee;
employment sub relation, relates employee;

there-are-no-unemployed sub rule,
when {
    $p isa person;
    not {
        (employee: $p) isa employment;
    };
}, then {
    (employee: $p) isa employment;
}

If we have a person who is not in an employment relation, then they are in an employment relation. But now, we've contradicted the initial premise of the rule - that they were not in an employment relation. Thus, we have a logical contradiction.

Alex Walker
  • 2,337
  • 1
  • 17
  • 32