I would like to find all DBpedia resources with rdf:type equal to owl:Thing. How can I extract such a list using SPARQL? What query would I need?
Since a triple would be something like
:a rdf:type owl:Thing and SPARQL is using triple patterns to match triples, you need a variable at the positions of the triple which is not fixed:
SELECT * WHERE {
?s a <http://www.w3.org/2002/07/owl#Thing>
}
Related
Is it possible to execute SPARQL construct while adding information outside the scope of query? e.g., I want to execute SPARQL construct while defining enumeration information like this:
PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
construct {
?s a skos:Concept
?s ex:index <enumeration starting from 1 -- this is just a sample>
}
where {
?s a skos:Concept
}
is it possible to do something like that with pure SPARQL? what are the alternatives?
* Additional Information *
Probably I am not explained my problem clearly, so basically I want to achieve the following (assuming that ex:index is a valid datatypeProperty):
== Initial RDF triples ==
#prefix skos:<http://www.w3.org/2004/02/skos/core#>
#prefix ex: <http://example.org/> .
ex:abc rdf:type skos:Concept .
ex:def rdf:type skos:Concept .
...
ex:endOfSample rdf:type skos:Concept .
== RDF triples after SPARQL Update execution ==
#prefix skos:<http://www.w3.org/2004/02/skos/core#>
#prefix ex: <http://example.org/> .
ex:abc rdf:type skos:Concept ;
ex:index 1 .
ex:def rdf:type skos:Concept ;
ex:index 2 .
...
ex:endOfSample rdf:type skos:Concept ;
ex:index <endOfSampleNumber> .
You can construct any valid RDF value in a CONSTRUCT. However the query will fail if any of the variables in the CONSTRUCT graph pattern is unbound after executing the WHERE graph. I.e. there can be no binding for ?p in your query and the CONSTRUCT will never execute.
This is an example that should get you started:
PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
PREFIX ex:<http://example.org/construct#>
construct {
ex:someProp a owl:ObjectProperty .
?s ex:someProp (1 2 3)
}
where {
?s a skos:Concept
}
This will result in the construction of seven triples for the property value and the list structure.
The ex:someProp is added because there isn't a good object property in SKOS for ad-hoc lists. It would be best to define the property with some semantic meaning. Also note that while the {ex:someProp a owl:ObjectProperty} triple will be asserted for each match of {?s a skos:Concept}, it is the same triple, hence there will be only one in the end. The price is efficiency, so asserting the property outside of this query would be a better choice - it is included in the above query for the sake of example completeness.
I am trying this query:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?label
WHERE
{
?AGE rdfs:label ?label.
}
I need all the values of AGE from my model but instead this query is giving me other resources values which have the same property label .
For example I have connected the resource gender to have a property rdfs:label. So in my result I get both age values and gender values.
Can anybody tell me where am I wrong ?
It seems you may be assigning some semantics to the variable '?AGE'. SPARQL is a graph pattern matching language and anything with a '?' as the first character is a variable - or better yet, an unknown in the graph pattern match. I.e., the following is an equivalent query to yours:
SPARQL ?label
WHERE
{ ?s rdfs:label ?label .
}
This will find all triples that have a rdfs:label property and select the value of ?label.
If you have a specific resource you want to query, then specify that resource in the subject, for example:
PREFIX ex: <http://example.org/ex>
SPARQL ?label
WHERE
{ ex:AGE rdfs:label ?label .
}
So understanding the difference between an unknown (denoted by '?' (or '$')) and a known (a qname or a full URI) is important to understand how SPARQL performs graph pattern matching.
Lots of SPARQL learning material on the Web, so a suggestion is to look into some of these to learn some basics.
I am trying to select all different language tags that appear on a sparql endpoint (like DBpedia) and display them as a list, but with no luck until now.
A simple Example of Triples on Endpoint.
<person1> rdfs:label "name1"#en
<person1> rdfs:label "name2"#fr
<person2> rdfs:comment "comment"#en
<person2> rdfs:label "name3"#el
The goal is to create a sparql query that returns:
fr
en
el
Is there any way to select languages tags efficiently?
Is there a solution for any sparql version(1.0,1.1) ?
Given your tags include SPARQL, you could try this:
SELECT DISTINCT ?lang
WHERE {
?s ?p ?o .
BIND (lang(?o) AS ?lang)
}
Hello everybody i'm using a SPARQL query to retrieve properties and values of a specified resource. For example if i ask for Barry White, i obtain: birth place, associatedBand, recordLabels and so on.
Instead for any instance such as "Hammerfall", i obtain only this results:
Query results
But i want properties and values as shown in this page: Correct results.
My query is:
PREFIX db: <http://dbpedia.org/resource/>
PREFIX prop: <http://dbpedia.org/property/>
PREFIX onto: <http://dbpedia.org/ontology/>
SELECT ?property ?value
WHERE { db:Hammerfall?property ?value }
Anyone can tell me how to access to the correct resource and obtain corrects properties and values in every case?
select ?p ?o { dbpedia:HammerFall ?p ?o }
SPARQL results
The particular prefix doesn't matter; I just used dbpedia: because it's predefined on the endpoint as http://dbpedia.org/resource/, just like your db:. The issue is that HammerFall has a majuscule F in the middle, but your query uses a miniscule f.
As an alternative, since the results for Hammerfall (with a miniscule f) do include
http://dbpedia.org/ontology/wikiPageRedirects http://dbpedia.org/resource/HammerFall
you could use a property path to follow any wikiPageRedirects paths:
select ?p ?v {
dbpedia:Hammerfall dbpedia-owl:wikiPageRedirects* ?hammerfall .
?hammerfall ?p ?v
}
SPARQL results
See Retrieving dbpedia-owl:type value of resource with dbpedia-owl:wikiPageRedirect value? for more about that approach.
I'm trying to get details about an artist via DBPedia and the SPARQL query language, however, it seems almost impossible (with my understanding) of how to get certain pieces of information.
I'm trying to get an Artist and pull information such as their Hometown. I'm guessing the query should be something similar to that of:
SELECT ?c WHERE {
?b <http://dbpedia.org/property/Artist> <http://dbpedia.org/resource/Arctic_Monkeys>.
?b <http://www.w3.org/2002/07/owl#ObjectProperty> <http://dbpedia.org/ontology/hometown>.
?b rdfs:label ?c.
}
If anyone could enlighten me to how it should be done, that would be amazing.
I've been trying out the queries at:
http://dbpedia.org/sparql
If you want to find the label of their hometown, try this:
SELECT ?hometownLabel WHERE {
<http://dbpedia.org/resource/Arctic_Monkeys> <http://dbpedia.org/ontology/hometown> ?hometown .
?hometown <http://www.w3.org/2000/01/rdf-schema#label> ?hometownLabel .
}
Maybe you don't have a good understanding of SPARQL syntax. Unlike SQL, SPARQL search results by writing some triples with unknow variables in the WHERE clause.
you can try:
prefix dbpedia-owl:<http://dbpedia.org/ontology/>
SELECT ?c
WHERE {
<http://dbpedia.org/resource/Arctic_Monkeys> dbpedia-owl:hometown ?c.
}
With this search, you will get Arctic_Monkeys' hometown.
SELECT ?hometown
WHERE {
dbr:Arctic_Monkeys dbo:hometown ?label.
?label rdfs:label ?hometown.
FILTER(langMatches(lang(?hometown), "en"))
}