Search code examples
vaticle-typedbvaticle-typeqlknowledge-graph

Insertion of an attribute of an attribute in a knowledge-graph with grakn / graql


My KG contains instances of a relation type that has an attribute.

I would like to insert new attribute values, but now linked to the attribute that already exists in those relations (attributes of an attribute).

Considering a fictional example, first I would insert the relation:

match
$per isa person, has id_per "xyz123";
$pro isa product, has id_pro "abc123";
insert $pur (purchaser: $per, purchased: pro) isa purchase, has invoice "aei379";

And after that, suppose that I want to insert a new attribute, invoice-date "2020-06-14" as an attribute of invoice "aei379".

How should I write the query for the match of the attribute invoice "aei379" and the insert of the new attribute invoice-date "2020-06-14"?

Is it necessary to match an specific relation (in my example there can be more than one relation with the same attribute) or is it possible to match directly the invoice attribute?


Solution

  • You can add an attribute to another attribute like that:

    match 
    $n "aei379" isa invoice;
    insert 
    $n, has invoice-date "2020-06-14";
    

    or you can do it in one query

    match
    $per isa person, has id_per "xyz123";
    $pro isa product, has id_pro "abc123";
    insert 
    $a "aei379";
    $a isa invoice, has invoice-date "2020-06-14";
    $pur (purchaser: $per, purchased: pro) isa purchase, has invoice $a;