我有一个SKOS术语的图表。我创建了一个SKOS本体,以及一个数据属性断言"定义"要添加定义到术语,除了另一个数据属性作为skos:altLabel
(地址)的子属性,我如何创建一个SPARQL查询,选择prefLabel
,address
和{{ 1}}条款?
definition
答案 0 :(得分:2)
您还没有提供完整的RDF / XML文档,因此很难确切知道发生了什么,但是您的某些RDF / XML看起来非常值得怀疑。对于以下类型:
<skos:concept rdf:about="&Ontology129;Zoology">
<rdf:type rdf:resource="&owl;NamedIndividual"/>
<rdf:type rdf:resource="&owl;Thing"/>
…
看起来不对劲。我想你是想说一个由Zoology
结尾的IRI确定的资源是owl:Thing
和owl:NamedIndividual
,但那些将是IRI
http://www.w3.org/2002/07/owl#Thing
http://www.w3.org/2002/07/owl#NamedIndividual
但你正在使用(不完全)IRI
&owl;Thing
&owl;NamedIndividual
您还有一些相对的IRI(除非您在文档中指定了xml:base
,但同样,您没有发布整个文档):
<skos:concept rdf:about="&Ontology129;Zoology">
…
<definition xml:lang="en">the branch of biology that studies animals</definition>
<Address rdf:datatype="&xsd;long">123</Address>
我认为你想要的数据更像是:
<rdf:RDF
xmlns="http://stackoverflow.com/q/20287798/1281433/"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:skos="http://www.w3.org/2004/02/skos/core#">
<skos:concept rdf:about="http://stackoverflow.com/q/20287798/1281433/Zoology">
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#NamedIndividual"/>
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
<skos:altlabel xml:lang="en">animal biology</skos:altlabel>
<definition xml:lang="en">the branch of biology that studies animals</definition>
<Address rdf:datatype="http://www.w3.org/2001/XMLSchema#long">123</Address>
<skos:altlabel xml:lang="en">zoological science</skos:altlabel>
<skos:preflabel xml:lang="en">zoology</skos:preflabel>
<skos:broader rdf:resource="http://stackoverflow.com/q/20287798/1281433/Biology"/>
<skos:inscheme rdf:resource="http://stackoverflow.com/q/20287798/1281433/ScientificDisciplines"/>
</skos:concept>
</rdf:RDF>
在编写SPARQL查询时,查看Turtle格式的数据通常很有帮助,因为SPARQL模式语言和Turtle语法非常相似。 Turtle中的数据是:
@prefix : <http://stackoverflow.com/q/20287798/1281433/> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
:Zoology a owl:NamedIndividual , owl:Thing , skos:concept ;
:Address "123"^^xsd:long ;
:definition "the branch of biology that studies animals"@en ;
skos:altlabel "zoological science"@en , "animal biology"@en ;
skos:broader :Biology ;
skos:inscheme :ScientificDisciplines ;
skos:preflabel "zoology"@en .
SPARQL查询看起来很像数据:
prefix : <http://stackoverflow.com/q/20287798/1281433/>
prefix skos: <http://www.w3.org/2004/02/skos/core#>
select ?term ?preflabel ?address ?definition where {
?term a skos:concept ;
skos:preflabel ?preflabel ;
:Address ?address ;
:definition ?definition .
}
结果是:
-----------------------------------------------------------------------------------------------
| term | preflabel | address | definition |
===============================================================================================
| :Zoology | "zoology"@en | "123"^^xsd:long | "the branch of biology that studies animals"@en |
-----------------------------------------------------------------------------------------------