如何使用SPARQL查询在RDF / XML的rdf:Description中获取信息?

时间:2018-10-11 18:33:21

标签: sparql rdf

例如,如何使用SPARQL查询获取defs中的skos:Concept(#4393574)中的zthes:label。 谢谢!

<?xml version="1.0" encoding="UTF-8"?>
 <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
 xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" 
 xmlns:skos="http://www.w3.org/2004/02/skos/core#" 
 xmlns:zthes="http://synaptica.net/zthes/">
 <skos:Concept rdf:about="#4393574">
 <skos:prefLabel>A prefLabel</skos:prefLabel>
 <zthes:termNote rdf:ID="Def1-4393574">Def1</zthes:termNote>
 </skos:Concept>
 <rdf:Description rdf:about="Def1-4393574">
 <zthes:label> a zthes label</zthes:label>
 </rdf:Description>
 </rdf:RDF>

更新:这是http://www.easyrdf.org/converter

转换的Turtle版本
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
@prefix ns0: <http://synaptica.net/zthes/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .

<http://example.me/#4393574>
  a skos:Concept ;
  skos:prefLabel "A prefLabel" ;
  ns0:termNote "Def1" .

<http://example.me/#Def1-4393574>
  a rdf:Statement ;
  rdf:subject <http://example.me/#4393574> ;
  rdf:predicate ns0:termNote ;
  rdf:object "Def1" .

<http://example.me/Def1-4393574> ns0:label " a zthes label" .

1 个答案:

答案 0 :(得分:1)

问题在于您的数据实际上没有在zthes:label和skos:Concept之间具有联系

此问题的根本原因是原始RDF / XML文件中的一个细微语法错误。这行:

<zthes:termNote rdf:ID="Def1-4393574">Def1</zthes:termNote>

定义标识符为<http://example.me/#Def1-4393574>的资源。同时,此行:

<rdf:Description rdf:about="Def1-4393574">

定义另一个资源,其标识符为<http://example.me/Def1-4393574>。它们不是同一资源(请注意缺少#),因此这两个定义没有链接。可以通过在前面添加#来解决此特定问题,如下所示:

<rdf:Description rdf:about="#Def1-4393574">

此修复将导致以下RDF模型(使用Turtle语法):

@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
@prefix zthes: <http://synaptica.net/zthes/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .

<http://example.me/#4393574>
  a skos:Concept ;
  skos:prefLabel "A prefLabel" ;
  zthes:termNote "Def1" .

<http://example.me/#Def1-4393574>
  a rdf:Statement ;
  rdf:subject <http://example.me/#4393574> ;
  rdf:predicate ns0:termNote ;
  rdf:object "Def1";
  zthes:label " a zthes label" .

顺便说一下,它仍然是一个非常奇怪的RDF模型,使用语句验证,但是假设这正是您必须使用的,查询以获取给定概念的zthes标签将是这样的:

 PREFIX zthes: <http://synaptica.net/zthes/>
 PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

 SELECT ?label
 WHERE {  
    [] rdf:subject <http://example.me/#4393574> ;
       zthes:label ?label . 
 }