How can I extract rdf: about or rdf: ID properties from triplets using SPARQL?
This seemed like a trivial question at the beginning, but so far I have not been able to get a unique ID for a given resource using SPARQL. I mean, for example, rdf:Description rdf:about="http://..."
and then some properties that identify this resource, what I want to do is first find this very resource and then retrieve all the triplets with some URI.
I've tried naive approaches by writing assertions into a sentence WHERE
, like this:
?x rdf:about ?y and ?x rdfs:about ?y
I hope I am for sure.
a source to share
You're making the classic mistake: confuse RDF (that's what SPARQL queries are) with (one of) its serialization, namely RDF / XML. rdf:about
(u rdf:ID
, rdf:Description
, rdf:resource
) are part of RDF / XML, the method is recorded RDF. You can play with the RDF Validator to see which RDF triplets are derived from an RDF / XML snippet.
In your case, 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/">
<rdf:Description rdf:about="http://www.example.org/">
<dc:title>Example for Donal Fellows</dc:title>
</rdf:Description>
</rdf:RDF>
Paste this into a 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 an image)
Note that rdf:about
no: its value provides an object for the triplet.
How do I run a query to find properties related to http://www.example.org
? Like this:
select * {
<http://www.example.org/> ?predicate ?object
}
You'll get:
?predicate ?object
<http://purl.org/dc/terms/title> "Example for Donal Fellows"
You will notice that the query is a triple match with the variables ( ?v
) where we want to find the values. We can also ask which predicate links are http://www.example.org/
from "Example for..."
by asking:
select * {
<http://www.example.org/> ?predicate "Example for Donal Fellows"
}
This pattern matching is at 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 similar to N-Triples with a lot of acronyms and acronyms. Turtle is often preferred by the rdf community.
PS rdfs:about
doesn't exist anywhere.
a source to share