0

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?

Chris Mukherjee
  • 841
  • 9
  • 25
Musich87
  • 562
  • 1
  • 12
  • 31
  • Are you asking how to use the resource as the object instead of a using the string as a the object? – Joshua Taylor Jun 06 '14 at 14:54
  • I ask how I can make object "Piemonte" (for example) in the with resource "Piemonte" in the , that mean the same thing. – Musich87 Jun 06 '14 at 15:01
  • 1
    Well, they can't be the *same* thing, because one is a string, which is an RDF literal, and the other is a URI resource. They're not the same *type* of thing. What you can do, though, is use the resource as the object. I've added an answer. – Joshua Taylor Jun 06 '14 at 15:06

1 Answers1

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>
Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
  • ok thanks. And for the Regione and Nome predicates? I can add into subject? – Musich87 Jun 06 '14 at 15:13
  • I'm not sure what you're asking. The predicates are already resources. (In fact, in RDF, predicates are required to be URIs; they can't be literals or blank nodes). – Joshua Taylor Jun 06 '14 at 16:24
  • I ask if it's possibile to link "Regione" predicate () with "Regione" subject (). In past, I didn't have this subject, I added "Regione" subject to add further information about "Regione" like label, comment or other (for example). I would like to make it clear that this information ("Regione" subject and "Regione" predicate) is the same thing. Sorry, but my English is very bad. – Musich87 Jun 09 '14 at 07:11
  • The *are* the same though. The namespace is defined with `j.0="http://stackoverflow.com/q/24084473/1281433/relations/"` so `j.0:Regione` is `http://stackoverflow.com/q/24084473/1281433/relations/Regione`. Notice in the Turtle serialization, both occurrences appear as `:Regione`. – Joshua Taylor Jun 09 '14 at 14:44
  • Hi Joshua. How I can develop your solution ("Piemonte" object as "Piemonte" resource) in Java Code using Jena? – Musich87 Jun 10 '14 at 09:02
  • That's a different question, and people looking for an answer to it won't be looking at this one for an answer. Please ask the new question as a new question. – Joshua Taylor Jun 10 '14 at 10:32
  • I'm sorry. New question is here: http://stackoverflow.com/questions/24139012/write-blank-node-in-java-code – Musich87 Jun 10 '14 at 10:44