SPARQL 查询与 Person 相关的所有 类 列表

SPARQL Query for list of ALL Classes related to Person

我想创建一个 SPARQL 查询,其中 returns 是与 Person 相关的所有 Ontology classes/properties 的列表。例如,像 Person

的 sub类(派生自)

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

或 domain/range 的 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 .
    }
}

现在,此查询 returns 所有 类 的列表,这些 类 在其属性中明确提及 Person,但遗漏了 类,例如 Singer ,它是 MusicalArtist 的子类,属于 Person 的域。

我想要一个查询,列出所有与 Person 直接或通过 "inheritance" 相关的 classes/properties。有什么建议么?

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

如果要同时检索 类 和属性 "related to" 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/"))
}