How to query rules in a TypeDB database?

328 Views Asked by At

In my schema I think I defined this rule:

define rule transitive-hierarchy-rule:
when {
(before: $a, after: $b) isa hierarchy;
(before: $b, after: $c) isa hierarchy;
} then {
(before: $a, after: $c) isa hierarchy;
};

Notice from the documentation:

"facts defined via rules are not stored in the knowledge graph. [...] However, by defining the rule in the schema, at query time the extra fact will be generated."

Also notice from the documentation:

Currently, for a match query to trigger reasoning and obtain inferences from rules, you must use a read transaction. We are working towards enabling reasoning in write transactions in subsequent releases.

However in my query match (before: $x, after: $y) isa hierarchy inside a read transaction doesn't return the expected results:

{ $x iid 0x826e800b8000000000000000 isa task; $y iid 0x826e80048000000000000002 isa task; }
{ $x iid 0x826e800a8000000000000000 isa task; $y iid 0x826e800b8000000000000000 isa task; }

The above two results I had explicity defined. I was expecting the third result to be inferred via the rule.

So I am trying to debug the situation. Could it be possible that I did not define the rule properly?

So question: how do I query more about the rules that have been defined in the database schema?

1

There are 1 best solutions below

3
James Williams On

Have you been sure to turn on inference? The 'infer' option must be turned on for rules to be triggered whilst running queries.

See the infer option for the java client API: https://docs.vaticle.com/docs/client-api/java#options