Rule error in Grakn: "rule does not form a valid clause, as it contains a multi-atom head"

49 Views Asked by At

I have a rule that is failing to commit. This is the rule:

when {
    $t isa person; 
    $car isa car; 
    $t2 isa person; 
    $r ($t, $car) isa ownership;     
    $r2 ($t2, $car) isa ownership;     
}, then {
    $car has age 23; 
    ($car, $t2) isa ownership; 
};

This is the error that I get after I commit this:

INVALID_ARGUMENT: InvalidKBException-A structural validation error has occurred. Please correct the [`1`] errors found. 
The rule [rule-32] does not form a valid clause, as it contains a multi-atom head
. Please check server logs for the stack trace.
All uncommitted data is cleared
2

There are 2 best solutions below

0
On

What @Jon T said is correct, and therefore the solution specific to your problem is to split the rule into two rules.

Both rules will have an identical when clause where the then clause has exactly one conclusion:

when {
    $t isa person; 
    $car isa car; 
    $t2 isa person; 
    $r ($t, $car) isa ownership;     
    $r2 ($t2, $car) isa ownership;     
}, then {
    $car has age 23; 
};

when {
    $t isa person; 
    $car isa car; 
    $t2 isa person; 
    $r ($t, $car) isa ownership;     
    $r2 ($t2, $car) isa ownership;     
}, then {
    ($car, $t2) isa ownership; 
};
0
On

A rule can only infer one fact:

In Graql, the “when” part of the rule is required to be a conjunctive pattern, whereas the “then” should be atomic - each rule can derive a single fact only

docs