Question

Im having a problem with RDF. I have a couple of triples defined as :

<User rdf:about="#T">
 <hasName rdf:datatype="http://www.w3.org/2001/XMLSchema#string">T</hasName>
 <hasFavourite rdf:resource="#x"/>
 <hasFavourite rdf:resource="#y"/>
</User>

Im wanting to add to the (user, hasFavourite, x) and (user, hasFavourite, y) triples as i need to associate an integer with them. Im a bit unsure of how to add an integer to a triple. Im sure this must be simple but im just getting my head around RDF so any help is appreciated.

Thanks Ally

Was it helpful?

Solution

So if I'm reading the question and your comment on dajobe's post correctly you probably want something like this (again in Turtle notation since it's so much more readable):

@base <http://example.org/ns#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix : <> .

:T
    :hasFavourite :fave1, :fave2 ;
    :hasName "T" ;
    a :User .

:fave1 a :Favourite ;
       :band :x ;
       :playCount 10 .

:fave2 a :Favourite ;
       :band :y ;
       :playCount 4 .

:x a :Band ;
   :hasName "Band 1" .

:y a :Band ;
   :hasName "Band 2" .

So this allows you to keep play counts for each users favourites individually and each Band may be chosen as a favourite by different users by creating new Favourites as required.

I could of course be completely wrong of course and this may be nothing like what you actually want!

OTHER TIPS

I'm not entirely clear what you want to model here; that the User resource has triples with integer values or X and Y resources have integer values. I'll assume the latter since it's more complex.

<?xml version="1.0" encoding="utf-8"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns="http://example.org/ns#">
<User rdf:about="#T">
 <hasName rdf:datatype="http://www.w3.org/2001/XMLSchema#string">T</hasName>
 <hasFavourite rdf:resource="#x"/>
 <hasFavourite rdf:resource="#y"/>
</User>
 <hasFavourite rdf:about="#x">
   <integerThatMeansSomething rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">10</integerThatMeansSomething>
 </hasFavourite>
 <hasFavourite rdf:about="#y">
   <integerThatMeansSomething rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">20</integerThatMeansSomething>
 </hasFavourite>
</rdf:RDF>

This is slightly easier to read in Turtle: (converted via rapper -q -o turtle foo.rdf 'http://example.org/ns#' from my Raptor software)

@base <http://example.org/ns#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix : <> .

:T
    :hasFavourite :x, :y ;
    :hasName "T"^^<http://www.w3.org/2001/XMLSchema#string> ;
    a :User .

:x
    :integerThatMeansSomething 10 ;
    a :hasFavourite .

:y
    :integerThatMeansSomething 20 ;
    a :hasFavourite .

Disclaimer: I edited rdf/xml, invented Turtle and wrote the software above!

Reading above like: "T is a User, has two favourites x and y and a string name. X is a favourite and has an integer property with value 10." etc. for Y.

If it was the former, the rdf/xml is simpler:

<User rdf:about="#T">
 <hasName rdf:datatype="http://www.w3.org/2001/XMLSchema#string">T</hasName>
 <hasFavourite rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">10</hasFavourite>
 <hasFavourite rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">20</hasFavourite>
</User>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top