views:

54

answers:

1

It seemed a trivial matter at the beginning but so far I have not managed to get the unique identifier for a given resource using SPARQL. What I mean is given, e.g., rdf:Description rdf:about="http://..." and then some properties identifying this resource, what I want to do is to first find this very resource and then retrieve all the triples given some URI.

I have tried naïve approaches by writing statements in a WHERE clause such as:

?x rdf:about ?y and ?x rdfs:about ?y

I hope I am being precise.

+2  A: 

You're making a classic mistake: confusing RDF (which is what SPARQL queries) with (one of) its serialisation, namely RDF/XML. rdf:about (and rdf:ID, rdf:Description, rdf:resource) are part of RDF/XML, a way RDF is written down. You can play around with the RDF Validator to see what RDF triples result from a piece of RDF/XML.

In your case let's start with:

<?xml version="1.0"?>
<rdf:RDF 
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:dc="http://purl.org/dc/terms/"&gt;
  <rdf:Description rdf:about="http://www.example.org/"&gt;
    <dc:title>Example for Donal Fellows</dc:title> 
  </rdf:Description>
</rdf:RDF>

Plug that into the validator and you get:

Number      Subject                      Predicate                        Object
1           http://www.example.org/      http://purl.org/dc/terms/title   "Example for Donal Fellows"

(you can also ask for a pictorial representation)

Notice that rdf:about is not present: its value provides the subject for the triple.

How do I do a query to find properties associated with http://www.example.org? Like this:

select * {
    <http://www.example.org/&gt; ?predicate ?object
}

You'll get:

?predicate                        ?object
<http://purl.org/dc/terms/title&gt;  "Example for Donal Fellows"

You'll notice that the query is a triple match with variables (?v) in places where we want to find values. We could also ask what predicate links http://www.example.org/ with "Example for..." by asking:

select * {
    <http://www.example.org/&gt; ?predicate "Example for Donal Fellows"
}

This pattern matching is the heart of SPARQL.

RDF/XML is a tricky beast, and you might find it easier to work with N-Triples, which is very verbose but clear, or turtle, which is like N-Triples with a large number of shorthands and abbreviations. Turtle is often preferred by the rdf community.

P.S. rdfs:about doesn't exist anywhere.

All true but you could also try semantic web questions at http://www.semanticoverflow.com/ where more expert folks hang out.
dajobe