user3358377
user3358377

Reputation: 145

RDF/XML Properties

i need some help

I use RDF/XML to represent some data.

First of all i want to show that a person knows other person, i declare the property and i use the following code to specify that mark knows katrin and katrin knows john

PART 1
<rdf:Property rdf:about="Know">
     <rdfs:domain rdf:resource="#Person"/>
     <rdfs:range rdf:resource="#Person"/>
</rdf:Property>


PART2
<rdf:Description rdf:about="#Mark">
    <dc:Knows rdf:resource="#Katrin"/>
</rdf:Description>  


<rdf:Description rdf:about="#Katrin">
    <dc:Knows rdf:resource="#John"/>
</rdf:Description>

Now i want to declare a property and represent more things. What i mean. I want to say for example that katrin owns a dog with ID 10 where this dog has colour black and its name is Peter. Above i had only the resource the property and the object. Now that i have to say more how can i make it the part 2??

PART 1

<rdf:Property rdf:ID="Own">
     <rdfs:domain rdf:resource="#Person"/>
     <rdfs:range rdf:resource="#Dog"/>
</rdf:Property>

PART 2  ?????

Thank you in advance for your help.

Upvotes: 1

Views: 365

Answers (1)

Joshua Taylor
Joshua Taylor

Reputation: 85923

First, note that you've declared the property Know with <rdf:Property rdf:about="Know">…</rdf:Property>, but you're using Knows in the rest of your code.

If you need to write RDF by hand, it's much easier to use one of the human readable and writable syntaxes, such as Turtle (as suggested by Michael in an answer to your previous question). In Turtle, we can write for what you have so far:

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

:Knows a rdfs:Property ;
       rdfs:domain :Person ;
       rdfs:range :Person .

:Mark :Knows :Katrin .

:Katrin :Knows :John .

If you really need this in RDF/XML for some reason, you can use a converter like Jena's rdfcat to get output like:

<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns="https://stackoverflow.com/q/22782748/1281433/"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
  <rdfs:Property rdf:about="https://stackoverflow.com/q/22782748/1281433/Knows">
    <rdfs:domain rdf:resource="https://stackoverflow.com/q/22782748/1281433/Person"/>
    <rdfs:range rdf:resource="https://stackoverflow.com/q/22782748/1281433/Person"/>
  </rdfs:Property>
  <rdf:Description rdf:about="https://stackoverflow.com/q/22782748/1281433/Mark">
    <Knows>
      <rdf:Description rdf:about="https://stackoverflow.com/q/22782748/1281433/Katrin">
        <Knows rdf:resource="https://stackoverflow.com/q/22782748/1281433/John"/>
      </rdf:Description>
    </Knows>
  </rdf:Description>
</rdf:RDF>

Now, to say something like

katrin owns a dog with ID 10 where this dog has colour black and its name is Peter.

Declaring the new properties (owns, hasColor, hasId, etc.) is exactly the same as above. You don't need to declare a property to use it though, so I won't include the declarations of the new properties here. Also, the answer to your previous question, When i declare property how to use it, shows how to declare properties.) If you have an IRI for the dog, and by "its name is Peter" you mean that its IRI is <…Peter>, then you can do something like this:

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

:Katrin :owns :Peter .

:Peter a :Dog ;
       :hasId 10 ;
       :hasColor "black" .
<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns="https://stackoverflow.com/q/22782748/1281433/"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
  <rdf:Description rdf:about="https://stackoverflow.com/q/22782748/1281433/Katrin">
    <owns>
      <Dog rdf:about="https://stackoverflow.com/q/22782748/1281433/Peter">
        <hasId rdf:datatype="http://www.w3.org/2001/XMLSchema#integer"
        >10</hasId>
        <hasColor>black</hasColor>
      </Dog>
    </owns>
  </rdf:Description>
</rdf:RDF>

If you don't have an IRI for the dog, then you can use a blank node:

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

:Katrin :owns _:dog .

_:dog a :Dog ;
      :hasName "Peter" ;
      :hasId 10 ;
      :hasColor "black" .
<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns="https://stackoverflow.com/q/22782748/1281433/"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
  <rdf:Description rdf:about="https://stackoverflow.com/q/22782748/1281433/Katrin">
    <owns>
      <Dog>
        <hasName>Peter</hasName>
        <hasId rdf:datatype="http://www.w3.org/2001/XMLSchema#integer"
        >10</hasId>
        <hasColor>black</hasColor>
      </Dog>
    </owns>
  </rdf:Description>
</rdf:RDF>

Instead of the _:dog notation for the blank node, I'd typically use the more compact abbreviated notation here:

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

:Katrin :owns [ a :Dog ;
               :hasName "Peter" ;
               :hasId 10 ;
               :hasColor "black" ] .
<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns="https://stackoverflow.com/q/22782748/1281433/"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
  <rdf:Description rdf:about="https://stackoverflow.com/q/22782748/1281433/Katrin">
    <owns>
      <Dog>
        <hasName>Peter</hasName>
        <hasId rdf:datatype="http://www.w3.org/2001/XMLSchema#integer"
        >10</hasId>
        <hasColor>black</hasColor>
      </Dog>
    </owns>
  </rdf:Description>
</rdf:RDF>

Upvotes: 5

Related Questions