0

我有这个 RDF 文件:

<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:j.0="http://relation/"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"> 
  <rdf:Description rdf:about="soggetto">
    <j.0:Nome>Vercelli</j.0:Nome>
    <j.0:Regione>Piemonte</j.0:Regione>
  </rdf:Description>
  <rdf:Description rdf:about="Piemonte">
    <rdfs:label>Piemonte</rdfs:label>
  </rdf:Description>
  <rdf:Description rdf:about="Regione">
    <rdfs:label>Regione</rdfs:label>
    <rdf:type rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#Property"/>
  </rdf:Description>
  <rdf:Description rdf:about="Vercelli">
    <rdfs:label>Vercelli</rdfs:label>
  </rdf:Description>
  <rdf:Description rdf:about="Nome">
    <rdfs:label>Nome</rdfs:label>
    <rdf:type rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#Property"/>
  </rdf:Description>
</rdf:RDF>

我想将 Piemonte 和 Vercelli 对象(在“soggetto”主题中)与 Piemonte 和 Vercelli 主题联系起来,并且我想将 Regione 和 Nome 谓词(在“soggetto”主题中)与 Regione 和 Nome 主题联系起来。

对我来说,Vercelli 主语等于 Vercelli 宾语,Piemonte 主语等于 Piemonte 宾语,Regione 谓语等于 Regione 主语,Nome 谓语等于 Nome 主语。

我怎么能做到这一点?我可以使用rdf:type谓词使 Vercelli 对象等于 Vercelli 主语吗?还是存在其他属性?

4

1 回答 1

1

认为您真正要问的是如何将资源用作某些主题的对象,而不是恰好具有相似内容的字符串。首先,让我们将 anxml:base和 an添加xmlns到您的数据中,以便更可预测:

<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:j.0="http://stackoverflow.com/q/24084473/1281433/relations/"
    xml:base="http://stackoverflow.com/q/24084473/1281433/"
    xmlns="http://stackoverflow.com/q/24084473/1281433/"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"> 
  <rdf:Description rdf:about="soggetto">
    <j.0:Nome>Vercelli</j.0:Nome>
    <j.0:Regione>Piemonte</j.0:Regione>
  </rdf:Description>
  <rdf:Description rdf:about="Piemonte">
    <rdfs:label>Piemonte</rdfs:label>
  </rdf:Description>
  <rdf:Description rdf:about="Regione">
    <rdfs:label>Regione</rdfs:label>
    <rdf:type rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#Property"/>
  </rdf:Description>
  <rdf:Description rdf:about="Vercelli">
    <rdfs:label>Vercelli</rdfs:label>
  </rdf:Description>
  <rdf:Description rdf:about="Nome">
    <rdfs:label>Nome</rdfs:label>
    <rdf:type rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#Property"/>
  </rdf:Description>
</rdf:RDF>

现在,使用 Turtle/N3 序列化比使用 RDF/XML 更容易,所以让我们看一下 Turtle 中的相同数据:

@prefix :      <http://stackoverflow.com/q/24084473/1281433/> .
@prefix rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#> .
@prefix j.0:   <http://stackoverflow.com/q/24084473/1281433/relations/> .

:Nome   a           rdf:Property ;
        rdfs:label  "Nome" .

:Regione  a         rdf:Property ;
        rdfs:label  "Regione" .

:Vercelli  rdfs:label  "Vercelli" .

:soggetto  j.0:Nome  "Vercelli" ;
        j.0:Regione  "Piemonte" .

:Piemonte  rdfs:label  "Piemonte" .

更容易查看数据的结构,并了解如何修复它。这听起来像是而不是说

:soggetto  j.0:Nome  "Vercelli" ;
        j.0:Regione  "Piemonte" .

您希望该区域:soggetto成为资源:Piemonte,您只需使用:Piemonte而不是"Piemonte". 然后你的数据,在 Turtle 和 RDF/XML 中将是

@prefix :      <http://stackoverflow.com/q/24084473/1281433/> .
@prefix rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#> .
@prefix j.0:   <http://stackoverflow.com/q/24084473/1281433/relations/> .

:Nome   a           rdf:Property ;
        rdfs:label  "Nome" .

:Regione  a         rdf:Property ;
        rdfs:label  "Regione" .

:Vercelli  rdfs:label  "Vercelli" .

:soggetto  j.0:Nome  "Vercelli" ;
        j.0:Regione  :Piemonte .

:Piemonte  rdfs:label  "Piemonte" .
<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns="http://stackoverflow.com/q/24084473/1281433/"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
    xmlns:j.0="http://stackoverflow.com/q/24084473/1281433/relations/">
  <rdf:Property rdf:about="http://stackoverflow.com/q/24084473/1281433/Regione">
    <rdfs:label>Regione</rdfs:label>
  </rdf:Property>
  <rdf:Property rdf:about="http://stackoverflow.com/q/24084473/1281433/Nome">
    <rdfs:label>Nome</rdfs:label>
  </rdf:Property>
  <rdf:Description rdf:about="http://stackoverflow.com/q/24084473/1281433/soggetto">
    <j.0:Nome>Vercelli</j.0:Nome>
    <j.0:Regione>
      <rdf:Description rdf:about="http://stackoverflow.com/q/24084473/1281433/Piemonte">
        <rdfs:label>Piemonte</rdfs:label>
      </rdf:Description>
    </j.0:Regione>
  </rdf:Description>
  <rdf:Description rdf:about="http://stackoverflow.com/q/24084473/1281433/Vercelli">
    <rdfs:label>Vercelli</rdfs:label>
  </rdf:Description>
</rdf:RDF>
于 2014-06-06T15:05:04.003 回答