Discussion Forum

Transative relation

Hello,

I can seem to get the rules working for transative behaviour.
My setup is as follows (this is a reduced example)

Schema file:

define

name sub attribute,
value string;

super_group sub entity,
owns name @key,
plays belongs_to:target;

group sub entity,
owns name @key,
plays belongs_to:source,
plays belongs_to:target;

sub_group sub entity,
owns name @key,
plays belongs_to:source;

belongs_to sub relation,
relates source,
relates target;

rule transitive-belongs-to:
when {
(source:$x, target:$y) isa belongs_to;
(source:$y, target:$z) isa belongs_to;
} then {
(source:$x, target:$z) isa belongs_to;
};

Data file:

insert
$super-1 isa super_group, has name “big”;
$group-1 isa group, has name “normal”;
$sub-1 isa sub_group, has name “small”;
$belongs-to-1 (source: $sub-1, target: $group-1) isa belongs_to;
$belongs-to-2 (source: $group-1, target: $super-1) isa belongs_to;

In the console I query on the belongs to relation as follows

pif::data::read> match (source: $x, target: $y) isa belongs_to; get $x, $y;

{ $x iid 0x966e80018000000000000000 isa group; $y iid 0x966e80028000000000000000 isa super_group; }
{ $x iid 0x966e80038000000000000000 isa sub_group; $y iid 0x966e80018000000000000000 isa group; }

I would also expect that the rule would fire and give me the relation between sub_group and super_group.
Is there something I should change in the files and/or query to get this expected bahaviour.

I am working with version:
$ ./typedb console --version
2.3.0
2.3.0

Hi,

At first glance everything looks correct to see transitivity, so first can I check if you enabled reasoning when you opened the transaction in the console?

I guess not.
From this documentation it seems that I should use a read transaction, which I am doing.

Is there another way to enable this?

Thanks in advance

That’s right, the extra option you need is documented under console.

Open the transaction in console with transaction my-database data read --infer true.

When you use the clients for Java/Python/NodeJS etc you also need to enable inference in the transaction options

1 Like

Yes, thanks that was missing.