我正在尝试从包含 onProperty 和 someValuesFrom 的 owl 文件中提取类的内容,其中 someValueFrom 由包含 unionOf(onProperty、someValueFrom 和等效类)的类组成,我创建了一个 SPARQL 查询来提取这些数据,但是每次它返回空白节点,例如“ :b0”和“ :b1”。有谁知道我应该如何处理我的查询以使其提供所需的结果。这是我的猫头鹰文件:
<?xml version="1.0"?>
<rdf:RDF
xmlns="http://owl.cs.manchester.ac.uk/2009/07/sssw/people#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:ns0="http://owl.cs.manchester.ac.uk/2009/07/sssw/people#"
xml:base="http://owl.cs.manchester.ac.uk/2009/07/sssw/people">
<owl:Ontology rdf:about="http://owl.cs.manchester.ac.uk/2009/07/sssw/people"/>
<owl:Class rdf:about="http://www.w3.org/2002/07/owl#Thing"/>
<owl:Class rdf:about="http://owl.cs.manchester.ac.uk/2009/07/sssw/people#haulage_worker">
<rdfs:comment rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
></rdfs:comment>
<owl:equivalentClass>
<owl:Restriction>
<owl:onProperty>
<owl:ObjectProperty rdf:about="http://owl.cs.manchester.ac.uk/2009/07/sssw/people#works_for"/>
</owl:onProperty>
<owl:someValuesFrom>
<owl:Class>
<owl:unionOf rdf:parseType="Collection">
<owl:Restriction>
<owl:onProperty>
<owl:ObjectProperty rdf:about="http://owl.cs.manchester.ac.uk/2009/07/sssw/people#part_of"/>
</owl:onProperty>
<owl:someValuesFrom>
<owl:Class rdf:about="http://owl.cs.manchester.ac.uk/2009/07/sssw/people#haulage_company"/>
</owl:someValuesFrom>
</owl:Restriction>
<owl:Class rdf:about="http://owl.cs.manchester.ac.uk/2009/07/sssw/people#haulage_company"/>
</owl:unionOf>
</owl:Class>
</owl:someValuesFrom>
</owl:Restriction>
</owl:equivalentClass>
<rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
>haulage worker</rdfs:label>
</owl:Class>
</rdf:RDF>
这是我创建的 SPARQL 查询:
prefix abc: <http://owl.cs.manchester.ac.uk/2009/07/sssw/people#>
prefix ghi: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix mno: <http://www.w3.org/2001/XMLSchema#>
prefix owl: <http://www.w3.org/2002/07/owl#>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix list: <http://jena.hpl.hp.com/ARQ/list#>
select distinct ?class ?ObjectProperty ?someValuesFrom ?otherClass where { ?class a owl:Class .
OPTIONAL{
?class owl:equivalentClass ?e .
?e a owl:Restriction .
# ?e owl:onProperty ?ObjectProperty .
?e owl:someValuesFrom [ a owl:Class;
owl:unionOf [ rdf:first ? ObjectProperty;
rdf:rest ?someValuesFrom ; rdf:rest*/rdf:first ?otherClass]] .
}
FILTER( STRSTARTS(STR(?class),STR(owl:)) || STRSTARTS(STR(?class),STR(abc:)))
}group by ?class ?ObjectProperty ?someValuesFrom ?otherClass
order by ?class
这是我得到的结果:
-------------------------------------------------------------------------------
| class | ObjectProperty | someValuesFrom | otherClass |
===============================================================================
| abc:haulage_company | | | |
| abc:haulage_worker | _:b0 | _:b1 | _:b0 |
| abc:haulage_worker | _:b0 | _:b1 | abc:haulage_company |
| owl:Thing | | | |
-------------------------------------------------------------------------------
但预期的结果是:
-----------------------------------------------------------------------------
| class | ObjectProperty | someValuesFrom | otherClass |
=============================================================================
| abc:haulage_company | | | |
| abc:haulage_worker | abc:works_for | | |
| abc:haulage_worker | abc:part_of | haulage_company | haulage_company |
| owl:Thing | | | |
-----------------------------------------------------------------------------
为了返回这个结果,我应该如何处理我的 SPARQL 查询?
提前谢谢了 :)