2017-06-19 36 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,謝謝! –