使用SPARQL进行有限的RDFS和OWL推理 [英] Using SPARQL for limited RDFS and OWL reasoning

查看:332
本文介绍了使用SPARQL进行有限的RDFS和OWL推理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前使用rdflib在Python中创建和管理RDF图的内容.但是,RDFlib不执行任何RDFS或OWL推理.这样会导致如下结果:

What I'm currently using rdflib for creating and managing RDF graphs in Python. RDFlib doesn't do any RDFS or OWL reasoning, though. This leads to results like the following:

  1. 如果有

  1. If I have

A rdf:type MyType .
MyType rdfs:subClassOf SuperType .

我问

select ?x where {?x rdf:type SuperType}

然后我什么也没得到,但是我想得到A(通过RDFS语义).

then I get nothing, but I'd like to get A (by RDFS semantics).

owl:equivalentClass也会发生相同的情况.如果有

The same thing happens with owl:equivalentClass. If I have

A rdf:type MyType .
MyType owl:equivalentClass SiblingType .

我问

select ?x where {?x rdf:type SiblingType}

我想得到A,但我什么也没得到.

I'd like to get A, but I get nothing.

有没有办法获得这些结果?

Is there a way to get these results?

推荐答案

尽管这是一个库请求问题,因此,与StackOverflow无关,我想指出的是,在许多情况下,您都可以回答这两种情况这些查询使用更加复杂的SPARQL查询.对于这两种情况,您都可以使用以下查询获取所需的结果,其中<class-of-interest>:SuperClass:SiblingClass:

Although this is a library request problem and, as such, off topic for StackOverflow, I would like to point out that for many cases, you can answer both of these queries using sightly more sophisticated SPARQL queries. For both of these cases, you could use the following query to get the results you want, where <class-of-interest> is :SuperClass or :SiblingClass:

select ?x where {
  ?x rdf:type/(rdfs:subClassOf|owl:equivalentClass)* <class-of-interest> .
}

这发现?x的路径以rdf:type开头,后跟零个或多个rdfs:subClassOfowl:equivalentClass并最终到达:SuperType.

This finds ?xs that have a path to starting with rdf:type and followed by zero or more of rdfs:subClassOf or owl:equivalentClass and eventually gets to :SuperType.

例如,考虑Turtle/N3中的以下数据. (顺便说一句,如果您要询问有关对数据运行查询的问题,请提供我们可以使用的数据.您在问题中提供了某种类似于RDF的数据,但是我们无法复制,粘贴和编写针对该查询的任何内容)

For instance, consider the following data in Turtle/N3. (As an aside, if you're asking questions about running queries against data, provide data that we can work with. You provided something sort of like RDF data in your question, but nothing that we could copy and paste and write a query against.)

@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix : <http://stackoverflow.com/q/20474862/1281433/>

:i1 a :C .
:C rdfs:subClassOf :D .
:D rdfs:subClassOf :E .

:i2 a :F .
:F rdfs:subClassOf :G1 .
:G1 owl:equivalentClass :G2 .
:G2 rdfs:subClassOf :H .

您可以像上面的查询一样运行查询来选择个人及其类型(请注意,a是SPARQL和Turtle/N3中rdf:type的简写形式):

You can run a query like the one above to select individuals and their types (note that a is shorthand in SPARQL and Turtle/N3 for rdf:type):

prefix owl: <http://www.w3.org/2002/07/owl#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix : <http://stackoverflow.com/q/20474862/1281433/>

select ?i ?type where {
  ?i a/(rdfs:subClassOf|owl:equivalentClass)* ?type
}

--------------
| i   | type |
==============
| :i2 | :F   |
| :i2 | :G1  |
| :i2 | :G2  |
| :i2 | :H   |
| :i1 | :C   |
| :i1 | :D   |
| :i1 | :E   |
--------------

这篇关于使用SPARQL进行有限的RDFS和OWL推理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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