views:

139

answers:

2

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"&gt;T&lt;/hasName&gt;
 <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

+1  A: 

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#"&gt;
<User rdf:about="#T">
 <hasName rdf:datatype="http://www.w3.org/2001/XMLSchema#string"&gt;T&lt;/hasName&gt;
 <hasFavourite rdf:resource="#x"/>
 <hasFavourite rdf:resource="#y"/>
</User>
 <hasFavourite rdf:about="#x">
   <integerThatMeansSomething rdf:datatype="http://www.w3.org/2001/XMLSchema#integer"&gt;10&lt;/integerThatMeansSomething&gt;
 </hasFavourite>
 <hasFavourite rdf:about="#y">
   <integerThatMeansSomething rdf:datatype="http://www.w3.org/2001/XMLSchema#integer"&gt;20&lt;/integerThatMeansSomething&gt;
 </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#&gt; .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#&gt; .
@prefix : <> .

:T
    :hasFavourite :x, :y ;
    :hasName "T"^^<http://www.w3.org/2001/XMLSchema#string&gt; ;
    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"&gt;T&lt;/hasName&gt;
 <hasFavourite rdf:datatype="http://www.w3.org/2001/XMLSchema#integer"&gt;10&lt;/hasFavourite&gt;
 <hasFavourite rdf:datatype="http://www.w3.org/2001/XMLSchema#integer"&gt;20&lt;/hasFavourite&gt;
</User>
dajobe
Hey dajobe thanks for your answer. You look like you now your rdf!I realised i didn't explain my problem correctly. What i should have mentioned is that there could be more than one user and they can have the hasFavourite relationship on the same 'x' or 'y' (which are actually bands)so basically for each (user, hasfavourite, band) triple i need to associate an integer value(playCount) with this actual triple rather than either the user or band individually because each band could have multiple hasFavoutite triples. Thanks for your time. Ally
allyLogan
+1  A: 

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#&gt; .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#&gt; .
@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!

RobV
Given the clarification on the problem, this seems the right data model to me. It's easier to draw this out on paper sometimes, but that's tricky to write down on a web page!
dajobe
Yes definitely easier to write down on paper, though for the web I'd rather type that out in Turtle than RDF/XML any day
RobV
Cheers guys. I just got round to trying it and it works. I didn't think about creating a type that is basically a relationship!! Thanks again
allyLogan