Reputation: 1874
In my website I have articles filled with rdf attributes. I Can't figure out what's the Sparql query to simply retrieve all the titles of the articles which author is admin.
I retrieved all the user names by:
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?name
WHERE {
?person foaf:name ?name .
}
Then I try:
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?dc:title
WHERE {
?person sioc:has_creator 1 .
}
LIMIT 5
But the result is:
Could not properly handle "PREFIX foaf: <http://xmlns.co" in ARC2_SPARQLPlusParser
if I remove foaf which is not used I get:
Could not properly handle "SELECT ?dc:title WHERE { " in ARC2_SPARQLPlusParser.
Sample of data output from the query:
select ?s ?p ?o where { ?s ?p ?o } limit 300
Result:
[...]
{
"s": {
"type": "uri",
"value": "http://drupal.test/users/admin"
},
"p": {
"type": "uri",
"value": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
},
"o": {
"type": "uri",
"value": "http://rdfs.org/sioc/ns#UserAccount"
}
},
{
"s": {
"type": "uri",
"value": "http://drupal.test/users/admin"
},
"p": {
"type": "uri",
"value": "http://xmlns.com/foaf/0.1/name"
},
"o": {
"type": "literal",
"value": "admin"
}
},
[...]
{
"s": {
"type": "uri",
"value": "http://drupal.test/content/consectetuer-dignissim-luptatum-tego"
},
"p": {
"type": "uri",
"value": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
},
"o": {
"type": "uri",
"value": "http://xmlns.com/foaf/0.1/Document"
}
},
{
"s": {
"type": "uri",
"value": "http://drupal.test/content/consectetuer-dignissim-luptatum-tego"
},
"p": {
"type": "uri",
"value": "http://purl.org/rss/1.0/modules/content/encoded"
},
"o": {
"type": "literal",
"value": "<p>Dignissim luptatum neo te. Damnum decet pala proprius quadrum sagaciter vel. Defui erat qui. Distineo esca macto nisl probo. Humo illum luctus nimis singularis sino sit valde wisi. Consequat eum iaceo paratus velit. Bene dolus esca eu fere mauris pala refero saepius suscipit.<\/p>\n<p>Camur dignissim facilisi genitus huic humo nimis. Ad conventio jumentum pala plaga praemitto premo quibus rusticus. Huic ibidem iriure macto nimis vel. Cui esca euismod sagaciter. Bene eros feugiat genitus jugis pagus quidem sudo valde vicis.<\/p>\n<p>Esca letalis odio tum. Abigo commodo probo quidne singularis. Eros iriure ullamcorper. Antehabeo aptent erat mauris molior oppeto validus verto wisi.<\/p>\n<p>Adipiscing aptent decet mos nostrud similis ullamcorper. Camur commoveo hendrerit jus odio uxor. Decet ea eum illum iriure natu os proprius ratis. Appellatio comis ibidem. Dolore molior neo pertineo. Autem consectetuer hendrerit patria.<\/p>\n<p>Blandit conventio eum te tego. Illum lobortis paratus wisi. Facilisi quibus singularis ulciscor. Illum in lucidus mos torqueo velit. Appellatio bene caecus hendrerit hos qui velit. Praemitto premo vereor. Acsi nulla ratis. Amet commodo consequat defui luctus vereor verto.<\/p>\n<p>Eligo ibidem illum iusto loquor neque oppeto utrum validus. At commodo eligo facilisi hos.<\/p>\n<p>Fere immitto pecus praemitto sino. Damnum hos jus laoreet letalis suscipere. Hos mauris nibh odio paulatim tation tego usitas.<\/p>\n<p>Abluo exputo iaceo volutpat. Abico duis et minim refoveo saluto validus vereor virtus voco. Ex minim vero. Commodo consequat interdico nobis singularis vel wisi. Ea fere hos quis saepius singularis torqueo virtus vulputate. Aliquip consectetuer defui ea ex quidem sudo usitas.<\/p>\n"
}
},
Describe the article:
describe
<http://drupal.test/content/consectetuer-dignissim-luptatum-tego>
Result:
{
"http://drupal.test/content/consectetuer-dignissim-luptatum-tego" : {
"http://www.w3.org/1999/02/22-rdf-syntax-ns#type" : [
{ "value" : "http://xmlns.com/foaf/0.1/Document", "type" : "uri" }
],
"http://purl.org/rss/1.0/modules/content/encoded" : [
{ "value" : "<p>Dignissim luptatum neo te. Damnum decet pala proprius quadrum sagaciter vel. Defui erat qui. Distineo esca macto nisl probo. Humo illum luctus nimis singularis sino sit valde wisi. Consequat eum iaceo paratus velit. Bene dolus esca eu fere mauris pala refero saepius suscipit.</p>\n", "type" : "literal" }
],
"http://purl.org/dc/terms/title" : [
{ "value" : "Consectetuer Dignissim Luptatum Tego", "type" : "literal" }
],
"http://purl.org/dc/terms/date" : [
{ "value" : "2014-06-11T08:22:09-07:00", "type" : "literal", "datatype" : "xsd:dateTime" }
],
"http://purl.org/dc/terms/created" : [
{ "value" : "2014-06-11T08:22:09-07:00", "type" : "literal", "datatype" : "xsd:dateTime" }
],
"http://purl.org/dc/terms/modified" : [
{ "value" : "2014-06-11T08:22:09-07:00", "type" : "literal", "datatype" : "xsd:dateTime" }
]
}
}
Give me all triples about an article:
select ?p ?o where { <http://drupal.test/content/consectetuer-dignissim-luptatum-tego> ?p ?o }
Result:
{
"head": {
"vars": [
"p",
"o"
]
},
"results": {
"bindings": [
{
"p": {
"type": "uri",
"value": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
},
"o": {
"type": "uri",
"value": "http://xmlns.com/foaf/0.1/Document"
}
},
{
"p": {
"type": "uri",
"value": "http://purl.org/rss/1.0/modules/content/encoded"
},
"o": {
"type": "literal",
"value": "<p>Dignissim luptatum neo te. Damnum decet pala proprius quadrum sagaciter vel. Defui erat qui. Distineo esca macto nisl probo. Humo illum luctus nimis singularis sino sit valde wisi. Consequat eum iaceo paratus velit. Bene dolus esca eu fere mauris pala refero saepius suscipit.<\/p>\n"
}
},
{
"p": {
"type": "uri",
"value": "http://purl.org/dc/terms/title"
},
"o": {
"type": "literal",
"value": "Consectetuer Dignissim Luptatum Tego"
}
},
{
"p": {
"type": "uri",
"value": "http://purl.org/dc/terms/date"
},
"o": {
"type": "typed-literal",
"value": "2014-06-11T08:22:09-07:00",
"datatype": "xsd:dateTime"
}
},
{
"p": {
"type": "uri",
"value": "http://purl.org/dc/terms/created"
},
"o": {
"type": "typed-literal",
"value": "2014-06-11T08:22:09-07:00",
"datatype": "xsd:dateTime"
}
},
{
"p": {
"type": "uri",
"value": "http://purl.org/dc/terms/modified"
},
"o": {
"type": "typed-literal",
"value": "2014-06-11T08:22:09-07:00",
"datatype": "xsd:dateTime"
}
}
]
}
}
Upvotes: 1
Views: 182
Reputation: 85913
This query doesn't make sense:
SELECT ?dc:title
WHERE {
?person sioc:has_creator 1 .
}
I don't think that dc:title
can be the name of a variable, and even if it is, you're not using it the query. The triple pattern ?person sioc:has_creator 1
is looking for things (which will be bound to the variable ?person
that have 1
as the value of the property sioc:has_creator
. I can't say for sure, but I doubt that 1
is the creator of many things, unless, as Clive mentions in the comments, the value of sioc:has_creator
is the id of the user, rather than some resource representing the user proper. You should start with an exploratory query like
select ?s ?p ?o where { ?s ?p ?o } limit 300
to find out what sort of triples you have in your data. Then, based on what you see, you'll have a better idea of what sort of queries you can write against it.
Without seeing your data, we can't really help you write the query you need, but I expect that to
simply retrieve all the titles of the articles which author is admin.
you'll end up doing something like this:
select ?title where {
?article dc:title ?title .
?article sioc:has_creator ?creator .
?creator foaf:name "admin" .
}
Upvotes: 3