Reputation: 147
I'm very new on GRAKN.AI and I'm wondering if in a GRAKN's graph I can create an "entity" composed by an "enitity". I know I can do the following code:
table sub entity
has book;
book sub resources datatype string;
But can I relate the "book" as an entity to the "table" ??
I need to have "book" as a complex concept and not as a simple resource.
Thanks,
Davide.
Upvotes: 2
Views: 317
Reputation: 3565
An alternative solution is to go through a relationship which allows you to define things more explicitly. For example,
To define a relationship you start by defining roles which provide context for how things relate to each other. For example:
insert
thing-on-top-of-table sub role;
table-with-thing-on-top sub role;
You then say how these roles link to the relationship and to the entities:
insert
sits-on sub relation
relates thing-on-top-of-table
relates table-with-thing-on-top;
table plays table-with-thing-on-top;
book plays thing-on-top-of-table;
The above is pretty much the schema of your simple knowledge base.
Now we can add some data. Let's say some book is on top of some table:
insert
$book isa book;
$table isa table;
(thing-on-top-of-table: $book, table-with-thing-on-top: $table) isa sits-on
Naturally you can expand things from here. For example you can give your book a title via a resource.
Side Note: Resources Vs Entities
The basic rule of thumb for relating something as a resource or as another entity depends on how much information you want to express in the model as well as if something can be defined by a data literal (e.g. String, Int, Long, etc . . . ).
For example a book is an entity because it is made up of multiple resources which help identify the book. I.e. the title, isbn, etc. . . those resources on the other hand are simple data values. A title is nothing but a string so there is no reason to make the title an entity, that should be fine as just a resource.
Upvotes: 3
Reputation: 781
You couold model two entites book
and table
and have a relation that you could call something like belongs
and add the roles you need e.g. book-role
and table-role
If the concepts are hierarchically related you can use inheritance.
table sub entity
has some property
book sub table
has additional property
Inheritance is usefull for classification you can easily understand that two sub entities are related and both can be retrieved by querying the parent.
match $t isa table;
would return the books as they are children entities of table.
Upvotes: 3