Link object to subject in RDF domain

非 Y 不嫁゛ 提交于 2019-12-25 07:33:20

问题


I have this RDF file:

<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>

I would like to link Piemonte and Vercelli objects (in the "soggetto" subject) with Piemonte and Vercelli subjects, and I would like to link Regione and Nome predicates (in the "soggetto" subject) with Regione and Nome subjects.

For me, Vercelli subject is equal to Vercelli object, Piemonte subject is equal to Piemonte object, Regione predicate is equal to Regione subject, and Nome predicate is equal to Nome subject.

How I can accomplish this? Can I use rdf:type predicate to make Vercelli object equal to Vercelli subject? Or does another attribute exist?


回答1:


I think that what you're really asking is how to use the resource as the object of some of the subjects instead of the a string that happens to have similar content. First, let's add an xml:base and an xmlns to your data, so that it's a bit more predictble:

<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>

Now, it's much easier to work with a Turtle/N3 serialization than with RDF/XML, so let's look at the same data in 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" .

It's much easier to see the structure of the data, and to see what to do to fix it. It sounds like rather than saying

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

you'd like to have the region of :soggetto be the resource :Piemonte, which you can do simply by using :Piemonte instead of "Piemonte". Then your data, in Turtle and RDF/XML would be

@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>


来源:https://stackoverflow.com/questions/24084473/link-object-to-subject-in-rdf-domain

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!