我认为您真正要问的是如何将资源用作某些主题的对象,而不是恰好具有相似内容的字符串。首先,让我们将 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>