使用 grakn / graql 在知识图中插入属性的属性

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

我的 KG 包含具有属性的关系类型的实例。

我想插入新的属性值,但现在链接到那些关系中已经存在的属性(属性的属性)。

考虑一个虚构的例子,首先我要插入关系:

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";

然后,假设我想插入一个新属性 invoice-date "2020-06-14" 作为 invoice "aei379" 的属性。

匹配属性invoice "aei379"和插入新属性invoice-date "2020-06-14"的查询应该怎么写?

是否需要匹配特定的关系(在我的示例中可以有多个关系具有相同的属性)或者是否可以直接匹配 invoice 属性?

您可以像这样将一个属性添加到另一个属性:

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

或者您可以在一次查询中完成

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;