2017-06-19 39 views
0

我想做一个SPARQL查询,它返回与Person有关的所有本体类/属性的列表。对于例如,像亚类的PersonSPARQL查询与人有关的所有类的列表

<rdfs:subClassOf rdf:resource="http://dbpedia.org/ontology/Person"/>

(衍生自)或具有Person

<rdfs:domain rdf:resource="http://dbpedia.org/ontology/Person"/>结构域/范围。

例如,像"http://dbpedia.org/ontology/OfficeHolder" & "http://dbpedia.org/ontology/Astronaut"结果应查询返回,作为第一个具有rdfs:domain人,而第二个是一个rdfs:subClassOf人。

下面是我写的查询:

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 
PREFIX owl: <http://www.w3.org/2002/07/owl#> 
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> 
PREFIX dbo: <http://dbpedia.org/ontology/> 

select distinct ?s 
where { 
    { 
     ?s rdfs:domain dbo:Person . 
    } 
union 
    { 
     ?s rdfs:range dbo:Person . 
    } 
union 
    { 
     ?s rdfs:subClassOf dbo:Person . 
    } 
} 

现在,该查询返回所有明确提到在他们的属性Person类的列表,但错过了类,如Singer,这是一个子类MusicalArtist,它位于Person的域中。

我想要一个查询,它直接或通过“继承”列出所有与Person相关的类/属性。有什么建议么?

+0

'DBO:OfficeHolder'不是属性,它有没有'RDFS:domain'。 –

回答

3

看来,你把类与属性混淆了......仔细阅读RDFS 1.1,它很简短。

如果要检索 “与” dbo:Person两个类和属性,使用property paths

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 
    PREFIX owl: <http://www.w3.org/2002/07/owl#> 
    PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> 
    PREFIX dbo: <http://dbpedia.org/ontology/> 

    SELECT distinct ?p ?s WHERE 
{ 
    { 
    ?s (rdfs:subPropertyOf|owl:equivalentProperty|^owl:equivalentProperty)*/ 
     rdfs:domain/ 
     (rdfs:subClassOf|owl:equivalentClass|^owl:equivalentClass)* 
    dbo:Person . 
    BIND (rdfs:domain AS ?p) 
    } 
    UNION 
    { 
    ?s (rdfs:subPropertyOf|owl:equivalentProperty|^owl:equivalentProperty)*/ 
     rdfs:range/ 
     (rdfs:subClassOf|owl:equivalentClass|^owl:equivalentClass)* 
    dbo:Person . 
    BIND (rdfs:range AS ?p) 
    } 
    UNION 
    { 
    ?s (rdfs:subClassOf|owl:equivalentClass|^owl:equivalentClass)* 
    dbo:Person . 
    BIND (rdfs:subClassOf AS ?p) 
    } 
    # FILTER (STRSTARTS(STR(?s), "http://dbpedia.org/")) 
} 
+0

谢谢,这正是我正在寻找的! :) :) – Krishh

+1

@StanislavKrlain:为了得到更完整的解决方案,你必须对'owl:equivalentProperty'和'owl:equivalentClass'使用反运算符'^',因为它们是对称的,但通常只有一个方向包含在KB。即'(rdfs:subClassOf |(owl:equivalentClass |^owl:equivalentClass))'' – AKSW

+0

@AKSW,谢谢! –