RDF可以使用边缘属性为带标签的属性图建模吗? [英] Can RDF model a labeled property graph with edge properties?

查看:349
本文介绍了RDF可以使用边缘属性为带标签的属性图建模吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想像以下那样建立合作伙伴关系模型,我用标记的属性图的格式表示。

I wanted to model partner relationship like the following, which I expressed in the format of labeled property graph.

我想使用RDF语言来表达上面的图形,尤其是我想了解是否可以表达 loves边缘的标签(这是URI的

I wanted to use RDF language to express the above graph, particularly I wanted to understand if I can express the label of the "loves" edge (which is an URI to an article/letter).

我是RDF的新手,我知道RDF可以轻松表示LPG中的节点属性,但是可以方便地表示边缘属性?

I am new to RDF, and I know the RDF can easily express the node properties in the LPG, but is it possible to conveniently express the edge properties?

此问题的更多上下文:我想使用RDF(而不是Gremlin)的原因是,从长远来看,我想添加一些推理功能

A bit more context of this question: the reason I wanted use RDF (rather than Gremlin) is that I wanted to add some reasoning capability in the long run.

进一步补充的问题:如果我们选择使用RDF模型来表示上述LPG,用简单的英语,我想回答以下问题带有SPARQL查询的s:

Further added question: if we choose an RDF model to represent the above LPG, in plain English, I wanted to answer the following questions with SPARQL query:


  1. 鲍勃爱上了任何人吗?

  2. 如果是,谁他是否爱上了,为什么?

SPARQL语句查询 loveletters的复杂程度如何。 com / 123

How complex would the SPARQL statement be to query out the loveletters.com/123?

推荐答案

RDF不支持边缘属性,因此简要答案是。但是,当然有一些方法可以在RDF中对此类型进行建模。

RDF doesn't support edge properties, so the brief answer is no. But of course there are ways to model this kind of thing in RDF.

如果我们不想对边缘进行注释,则鲍勃和玛丽之间的关系将变成三重关系,鲍勃为主体,玛丽为对象,爱为谓词:

If we didn't want to annotate the edge, the relationship between Bob and Mary would simply be a triple with Bob as Subject, Mary as object, and "loves" as predicate:

PREFIX : <http://example.org/ontology#>
PREFIX person: <http://example.org/data/person/>

person:Bob :loves person:Mary.

那么我们如何添加注释?

So how can we add annotations?

RDF具有一个内置的解决方案,称为 RDF修正。它允许对以下语句进行声明:

RDF has a built-in solution called "RDF reification". It allows making statements about statements:

PREFIX : <http://example.org/ontology#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX person: <http://example.org/data/person/>
PREFIX statement: <http://example.org/data/statement/>

person:Bob :loves person:Mary.

statement:1 a rdf:Statement;
    rdf:subject person:Bob;
    rdf:predicate :loves;
    rdf:object person:Mary;
    :reason <http://loveletters.com/123>.

所以我们说有一个陈述,其中鲍勃为主体,玛丽为客体,爱作为谓词。然后,我们可以向该语句添加属性。缺点是它有点多余。首先,我们添加爱三元组,然后再添加四个三元组来复制爱三元组。

So we say that there is a statement with Bob as subject, Mary as object, and "loves" as predicate. Then we can add properties to that statement. The downside is that it is kind of redundant. First we add the "loves" triple, then we add four more triples to replicate the "loves" triple.

另一种方法是更改​​模型。我们没有将``爱''视为人与人之间的优势,而是将其视为自身的一个节点。表示该关系的节点,并连接到所涉及的两方。

Another approach is to change the model. Instead of considering "loves" an edge between people, we consider it a node in itself. A node that represents the relationship, and is connected to the two parties involved.

PREFIX relationship: <http://example.org/data/relationship/>

relationship:1 a :LovesRelationship;
    :who person:Bob;
    :whom person:Mary;
    :reason <http://loveletters.com/123>.

因此,在我们的模型中,我们创建了一个类:LovesRelationship 表示爱,并使用属性:who :whom 表示两方。这种方法的缺点是图结构不再直接代表我们的社交网络。因此,在查询两个人之间的关系时,我们总是必须遍历这些关系实体,而不仅仅是处理连接人的边缘。

So in our model we created a class :LovesRelationship that represents "loves", and properties :who and :whom to indicate the two parties. The downside of this approach is that the graph structure no longer directly represents our social network. So when querying how two people are related, we always have to go through those relationship entities instead of just dealing with edges connecting people.

一项名为RDF * 的提案很好地解决了这个问题。 (有时称为RDR或正确完成版本化。。)RDF * / RDR添加了新语法,允许三元组成为其他三元组的主题:

There is a proposal called RDF* that addresses this problem quite nicely. (Sometimes it's called RDR or Reification Done Right.) RDF*/RDR adds new syntax that allows triples to be the subject of other triples:

<<person:Bob :loves person:Mary>>
    :reason <http://loveletters.com/123>.

缺点是它是非标准的,到目前为止仅受少数系统支持( Blazegraph AnzoGraph Jena的扩展 )。截至2019年4月,海王星不在其中。

The downside is that it is non-standard and so far supported only by a few systems (Blazegraph, AnzoGraph, and an extension for Jena). As of April 2019, Neptune is not among them.

在基本的RDF版本以及选项1和选项3中都很容易做到这一点。

This is easy to do in the basic RDF version as well as in Option 1 and Option 3:

ASK { person:Bob :loves ?anyone }

由于模型已更改,选项2需要一个不同的查询:

Option 2 requires a different query, because of the changed model:

ASK {
   ?rel a :LovesRelationship;
       :who person:Bob.
}

这将匹配任何:LovesRelationship ,其中:who 属性是Bob,而不管:whom :原因属性。

This would match any :LovesRelationship where the :who property is Bob, regardless of the :whom and :reason properties.

选项1 ,RDF修改:

SELECT ?whom ?why {
    ?statement a rdf:Statement;
        rdf:subject person:Bob;
        rdf:predicate :loves;
        rdf:object ?whom;
        :reason ?why.
}

我发现此查询不是很直观,因为它谈论RDF语句,而我们对人员和关系真的很感兴趣。

I find this query not very intuitive, because it talks about RDF statements, while we are really interested in people and relationships.

选项2 ,将关系建模为实体:

Option 2, relationship modelled as entity:

SELECT ?whom ?why {
    ?rel a :LovesRelationship;
        :who person:Bob;
        :whom ?whom;
        :reason ?why.
}

一旦您接受了关系是该模型中的实体,它就会变得非常直观。

This is better in my eyes; once you have accepted that relationships are entities in this model, it becomes fairly intuitive.

选项3 ,RDF *,使用SPARQL *:

Option 3, RDF*, using SPARQL*:

SELECT ?whom ?why {
    <<person:Bob :loves ?whom>>
        :reason ?why.
}

这是简洁直观的方法,这是我们当前无法使用的可耻之处在大多数SPARQL系统中都是如此!

This is concise and intuitive, so it's a shame we can't currently use it in most SPARQL systems!

这篇关于RDF可以使用边缘属性为带标签的属性图建模吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆