English 中文(简体)
Defining cardinality for a RDF statement
原标题:

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

最佳回答

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!

问题回答

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>




相关问题
Defining cardinality for a RDF statement

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> <...

Duplicate triple in RDF, authoritative view?

if a triple store contains twice the same triple, what is (if any exist) the authoritative position about this redundancy ? Additionally, should a triplestore be allowed to store twice the same ...

Pick and RDF/SPARQL

Anyone have any interest in intergrating RDF and/or SPARQL with a PICK database? Has anyone tried this yet? I have some thoughts about what to try. One idea is to figure out how to create a file with ...

Using contexts in rdflib

I am having trouble finding a clear, sensible example of usage of context with rdflib. ConjunctiveGraph does not accept contexts, and Graph is deprecated. How am I supposed to create and operate on ...

What is the difference between RDF and OWL? [closed]

I am trying to grasp the concept of Semantic Web. I am finding it hard to understand what exactly is the difference between RDF and OWL. Is OWL an extension of RDF or these two are totally different ...

Problem with SPARQLWrapper (Python)

I m making a SPARQL query against the Sesame store in localhost, using SPARQLWrapper: sparql = SPARQLWrapper( http://localhost:8080/openrdf-sesame/repositories/rep/statements ) sparql.setQuery(...

热门标签