0

我有一个 SKOS 术语的下图。我已经创建了一个 SKOS 本体和一个数据属性断言“定义”以向术语添加定义,此外还有另一个数据属性作为 skos:altLabel(地址)的子属性,我如何创建一个 SPARQL 查询来选择一个prefLabeladdress以及definition术语的?

<skos:concept rdf:about="&amp;Ontology129;Zoology"> 
<rdf:type rdf:resource="&amp;owl;NamedIndividual"/> 
<rdf:type rdf:resource="&amp;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="&xsd;long">123</Address>
 <skos:altlabel xml:lang="en">zoological science</skos:altlabel> <skos:preflabel 
 xml:lang="en">zoology</skos:preflabel> 
<skos:broader rdf:resource="&amp;Ontology129;Biology"/> 
<skos:inscheme rdf:resource="&amp;Ontology129;ScientificDisciplines"/> 
</skos:concept>
4

1 回答 1

2

不良数据

您还没有提供完整的 RDF/XML 文档,因此很难准确判断发生了什么,但是您的一些 RDF/XML 看起来很可疑。对于以下类型:

<skos:concept rdf:about="&amp;Ontology129;Zoology"> 
  <rdf:type rdf:resource="&amp;owl;NamedIndividual"/> 
  <rdf:type rdf:resource="&amp;owl;Thing"/> 
  …

看起来不对。我认为您想说的是由 IRI 以结尾标识的某些资源Zoology是 anowl:Thing和 an 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="&amp;Ontology129;Zoology"> 
  …
  <definition xml:lang="en">the branch of biology that studies animals</definition>         
  <Address rdf:datatype="&xsd;long">123</Address>

SPARQL 查询

我认为您想要的数据更像:

<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 语法非常相似。海龟中的数据是:

@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 |
-----------------------------------------------------------------------------------------------
于 2013-11-29T16:27:06.260 回答