1

How could I generate by code nested properties please? Like that:

<geo:Departement rdf:about="DEP_05">
    <geo:code_departement>05</geo:code_departement>
    <geo:subdivision>
        <geo:Arrondissement rdf:about="ARR_051">
            <geo:code_arrondissement>051</geo:code_arrondissement>
            <geo:nom xml:lang="fr">Briançon</geo:nom>
        </geo:Arrondissement>
    </geo:subdivision>
    <geo:subdivision>
        <geo:Arrondissement rdf:about="ARR_052">
            <geo:code_arrondissement>052</geo:code_arrondissement>
            <geo:nom xml:lang="fr">Gap</geo:nom>
        </geo:Arrondissement>
    </geo:subdivision>
</geo:Departement>

All my properties (created using "createProperty") are at the same level.

Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
paradise
  • 336
  • 2
  • 15

1 Answers1

3

It's not clear exactly what you mean by subproperties. It's important to realize that RDF is a graph-based data representation based on labeled, directed, edges called triples of the form:

subject predicate object

Your data for instance, includes the triples

DEP_05 rdf:type                 geo:Department
DEP_05 geo:code_department      "05"
DEP_05 subdivision              ARR_O51
ARR_051 rdf:type                geo:Arrondissement 
ARR_051 geo:code_arrondissement "051"

RDF/XML provides lots of different ways to write the same graph. For instance, one way of writing your data (I've added the appropriate prefixes) is:

<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:geo="https://stackoverflow.com/q/21383685/1281433/">
  <geo:Departement rdf:about="https://stackoverflow.com/q/21383685/1281433/DEP_05">
    <geo:code_departement>05</geo:code_departement>
    <geo:subdivision>
      <geo:Arrondissement rdf:about="https://stackoverflow.com/q/21383685/1281433/ARR_051">
        <geo:code_arrondissement>051</geo:code_arrondissement>
        <geo:nom xml:lang="fr">Briançon</geo:nom>
      </geo:Arrondissement>
    </geo:subdivision>
    <geo:subdivision>
      <geo:Arrondissement rdf:about="https://stackoverflow.com/q/21383685/1281433/ARR_052">
        <geo:code_arrondissement>052</geo:code_arrondissement>
        <geo:nom xml:lang="fr">Gap</geo:nom>
      </geo:Arrondissement>
    </geo:subdivision>
  </geo:Departement>
</rdf:RDF>

Another way, which happens to use fewer of the "shortcuts" that RDF/XML allows, is:

<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:geo="https://stackoverflow.com/q/21383685/1281433/" > 
  <rdf:Description rdf:about="https://stackoverflow.com/q/21383685/1281433/ARR_052">
    <rdf:type rdf:resource="https://stackoverflow.com/q/21383685/1281433/Arrondissement"/>
    <geo:code_arrondissement>052</geo:code_arrondissement>
    <geo:nom xml:lang="fr">Gap</geo:nom>
  </rdf:Description>
  <rdf:Description rdf:about="https://stackoverflow.com/q/21383685/1281433/ARR_051">
    <rdf:type rdf:resource="https://stackoverflow.com/q/21383685/1281433/Arrondissement"/>
    <geo:code_arrondissement>051</geo:code_arrondissement>
    <geo:nom xml:lang="fr">Briançon</geo:nom>
  </rdf:Description>
  <rdf:Description rdf:about="https://stackoverflow.com/q/21383685/1281433/DEP_05">
    <rdf:type rdf:resource="https://stackoverflow.com/q/21383685/1281433/Departement"/>
    <geo:code_departement>05</geo:code_departement>
    <geo:subdivision rdf:resource="https://stackoverflow.com/q/21383685/1281433/ARR_051"/>
    <geo:subdivision rdf:resource="https://stackoverflow.com/q/21383685/1281433/ARR_052"/>
  </rdf:Description>
</rdf:RDF>

Even though these are different XML documents, they are serializations of the same RDF graph. There are non-XML serializations as well. In the Turtle serialization, your data is:

@prefix geo:   <https://stackoverflow.com/q/21383685/1281433/> .
@prefix rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .

geo:ARR_051  a                   geo:Arrondissement ;
        geo:code_arrondissement  "051" ;
        geo:nom                  "Briançon"@fr .

geo:DEP_05  a                 geo:Departement ;
        geo:code_departement  "05" ;
        geo:subdivision       geo:ARR_051 , geo:ARR_052 .

geo:ARR_052  a                   geo:Arrondissement ;
        geo:code_arrondissement  "052" ;
        geo:nom                  "Gap"@fr .

It's very important to realize that these are all the same graph. An RDF processing tool doesn't care which one you use. That said, it can be nice to use a format that's more human-readable, so I tend to prefer Turtle. If you still need to use RDF/XML, then you may way to serialize your model using the "RDF/XML-ABBREV" language. To do this, specify "RDF/XML-ABBREV" as the lang argument to Model.write(OutputStream out, String lang). From the Javadoc:

write

Model write(OutputStream out, String lang)

Write a serialized represention of this model in a specified language.

The language in which to write the model is specified by the lang argument. Predefined values are "RDF/XML", "RDF/XML-ABBREV", "N-TRIPLE", "TURTLE", (and "TTL") and "N3". The default value, represented by null, is "RDF/XML".

Parameters:

  • out - The output stream to which the RDF is written
  • lang - The output language

Returns:

  • This model

Related Questions

Some related questions have arisen here before, and you might find some of them helpful. The ones that I quickly found are:

Community
  • 1
  • 1
Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
  • Thanks Joshua for that complete answer. In fact I've got 3 properties, each available for different dates and I wanted to group them by date. But when you began speaking of triples I realized that it was not a correct RDF-way-of-thinking, indeed. So I factorized everything at the same level: ...> ...> ...> ...> ...and so on. Not beautiful, but efficient. – paradise Jan 28 '14 at 22:52
  • @paradise I have to admit, I'm not quite sure what your solution is. Think of RDF triples as short sentences. If you have a relationship that's between more than two things, you might have a look at [Defining N-ary Relations on the Semantic Web](http://www.w3.org/TR/swbp-n-aryRelations/). – Joshua Taylor Jan 28 '14 at 22:57
  • What I needed: " " --> for year 2002, 2008 and 2010. How I did: " " Not extensible, but that was not the purpose. – paradise Jan 31 '14 at 09:55
  • @paradise Triples have a subject, a predicate (also called property), and an object, e.g., `:john :hasName "John"`. `:john` is the subject, `:hasName` is the predicate/property, and `"John"` is the object. I think you're saying "property" where I'd expect to hear "object". If I understand you correctly, you need to represent a 3-place relationship: has(subject,time,object) — the subject has object at the time. If that's the case, you really should take a look at the [defining n-ary relations](http://www.w3.org/TR/swbp-n-aryRelations/). If that's what you intend, I'll update my answer. – Joshua Taylor Jan 31 '14 at 15:10