Discussion Forum

Usage of Abstract

I noticed the abstract keyword in (Schema Concepts | GRAKN.AI).
According to the documentation,
It can be used to subtype the relation/attribute/entity. But things with abstract cannot own instance.
Things which are not abstract cannot play abstract relation:roles and own abstract attributes.
So… would you please tell me one or more usage senarios, or examples about abstract?

Could I define a rule using abstract thing?
such as

rule cmdb-rule:
when {
(from:$x, to:$y) isa cmdb-relation;
(from:$y, to:$z) isa cmdb-relation;
} then {
(from:$x, to:$z) isa cmdb-relation;

which cmdb-relation is a abstract relation.

When I defined the rule, error reported as below:

[RUW06] Invalid Rule Write: The rule 'cmdb-rule' has a then clause '{ $_0 isa cmdb-relation; $_0 (from:$x, to:$z); }' that can never be satisfied in the current schema. Please check server logs for the stack trace.

Abstract types can be used pretty similarly as you do in programming - you use them to define your model of your domain, and ensure that parts of it cannot be instantiated (only the concrete subtypes can)

That being said, you can still use the abstract types to read data:

  event sub entity, abstract;
  birthday sub event;
  marriage sub event;

[in console]
> match $x isa event; 
--> will return birthdays and marriages

We also don’t allow non-abstract hierarchies of attributes, because the meaning of a “key” attribute for another type becomes ambiguous (can link a discussion about this if you’re interested)

Hope that helps!

Thank you very much!
I don’t quite understand the meaning of this sentence. Would you explain it a little more?

check this out: Cannot subtype an attribute type unless it is abstract · Issue #6250 · vaticle/typedb · GitHub

let me know if it’s still unclear!

It is explained clearly in the issue .
Thanks a lot!