I'm new to sparql and I'm learning it right now.
I took this code from a tutorial
prefix dbpo: <http://dbpedia.org/ontology/>
prefix dbpr: <http://dbpedia.org/resource/>
select distinct ?Predicate ?Object where {
?Subject ?Predicate ?Object
filter(?Subject = dbpr:Markiplier)
}
and executed it on http://dbpedia.org/sparql, it returns empty result
as you can see on this image
I tried many codes and I always get empty result, is there anything I must do to get data ? Any advice will be appreciated.
I didn't understand why you put space for publishing the question but you should reunite them again. Besides you can also ask for ?Subjectif you like:
prefix dbpo: <http://dbpedia.org/ontology/>
prefix dbpr: <http://dbpedia.org/resource/>
select distinct ?Subject ?Predicate ?Object where {
?Subject ?Predicate ?Object
filter(?Subject = dbpr:Markiplier)
}
By the way if you have troubles with prefixes, I would reccomend to work on the http://dbpedia.org/snorql/ endpoint. So that you can use the predefined prefixes directly like this.
Related
I am using DBpedia to retrieve data on specific towns' POIs, for instance Barcelona. I've tried to find appropriate answers to my problems on Stack Overflow but almost all the answers provided did not work out for me, and given that I am new in SPARQL, I couldn't manage to figure out whether or not it was the syntax that was at fault or if there was something else. I am using the DBpedia SPARQL Endpoint available at the following address : http://dbpedia.org/sparql
I've tried to use some things such as ?citylabel or ?location, and to either use the FILTER command or directly fill a value for these classes. I've also tried a few other things, without satisfying results (and most of the times syntax errors that I could not resolve). These solutions have been, in most cases, applied and seemed to work just fine for people, so I do not understand what's going on.
BASE <http://www.dbpedia.org/resource/>
PREFIX : <http://dbpedia.org/resource/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dbpedia: <http://dbpedia.org/>
PREFIX dbpedia2: <http://dbpedia.org/property/>
PREFIX dbpedia3: <http://dbpedia.org/ontology/>
SELECT (SAMPLE(?label) as ?activity_name)
(SAMPLE(?latitude) as ?activity_lat)
(SAMPLE(?longitude) as ?activity_lon)
(SAMPLE(?homepage) as ?URL)
(SAMPLE(?type) as ?activity_type)
(SAMPLE(?abstract) as ?descriptor)
WHERE
{ ?Museum a dbo:Museum ;
rdfs:label ?label ;
dbo:abstract ?abstract ;
dbo:type ?type ;
geo:lat ?latitude ;
geo:long ?longitude ;
foaf:homepage ?homepage .
}
GROUP BY ?Museum ?label
The results of this query are, I think, pretty much any museum that is known by DBpedia and categorized as such. What I'd like to have is a list of museums within Barcelona. Can somebody give me an rather in-depth answer so I can understand how it is working ? Thanks, in advance.
I was hoping someone could help me with a SPARQL query I'm writing. I may get some of the terminology wrong, I'm not a SPARQL expert.
I am trying to get some information from the Nobel prizes SPARQL endpoint (data.nobelprize.org/sparql), retrieving the labels of predicates where the labels of objects match a certain string.
So, for example, if I search for an object with an objectLabel that contains the string 'Robert Burns Woodward', I should receive a number of results including:
predicateLabel, objectLabel
"Laureate","Robert Burns Woodward"
"LaureateAward","Chemistry 1965, Robert Burns Woodward"
"AwardFile","Nobel Lecture Robert Burns Woodward"
I have written the SPARQL below which should work, however it does not retrieve any results:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT ?predicateLabel ?objectLabel
WHERE
{
?subject ?predicate ?object .
?object rdfs:label ?objectLabel .
?predicate rdfs:label ?predicateLabel .
FILTER contains(?objectLabel, 'Robert Burns Woodward')
}
The reason is that the ?predicate URI is in a different case to the URI which is linked to the corresponding rdfs:label property.
So for example, the predicate
http://data.nobelprize.org/terms/nobelPrize
is used to connect laureates to the prizes they have won. Eg:
sub: http://data.nobelprize.org/resource/laureate/231
pred: http://data.nobelprize.org/terms/nobelPrize
obj: http://data.nobelprize.org/resource/nobelprize/Chemistry/1965
However, the rdfs:label is linked to
http://data.nobelprize.org/terms/NobelPrize
not
http://data.nobelprize.org/terms/nobelPrize
Note the difference in case between the two - the second URI has a lower case 'n' in nobelprize, wheras the first uses an upper case N.
So my question is, is there a way in SPARQL to make a URI case insensitive so that http://data.nobelprize.org/terms/NobelPrize will match with http://data.nobelprize.org/terms/nobelPrize? I know it is possible to search for strings that are case insensitive using FILTER regex or FILTER contains, but I don't know if it is possible with URIs.
You're approaching this the wrong way, I think. That data source has two separate concepts. The resource spelled NobelPrize denotes the class of Nobel Prizes, as can be seen in the ontology. The resource spelled nobelPrize is a different resource, namely the relation between a laureate and a particular Nobel Prize.
In other words: they are distinct, deliberately so, and you shouldn't try to turn them into the same thing by doing case-insensitive matches.
It's somewhat odd that that the nobelPrize property has no label in the SPARQL endpoint, because according to the ontology file it should have one. But given that it doesn't have a label, you're sort of stuck with just getting back the predicate URI itself. You can optionally shorten it by snipping of the namespace part using strafter, like so:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT (strafter(str(?predicate), "http://data.nobelprize.org/terms/") as ?predicateLabel) ?objectLabel
WHERE
{
?subject ?predicate ?object .
?object rdfs:label ?objectLabel .
FILTER contains(?objectLabel, 'Robert Burns Woodward')
}
An alternative, which is somewhat more complex but conceptually neater, is that instead of returning the name of the predicate, you return the name of the type of the object to which the predicate points:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT ?objectClassName ?objectLabel
WHERE
{
?subject ?predicate ?object .
?object a ?objectClass .
?objectClass rdfs:label ?objectClassName .
?object rdfs:label ?objectLabel .
FILTER contains(?objectLabel, 'Robert Burns Woodward')
}
This is an evolution of this question.
Basically I am having trouble getting all the solutions to a SPARQL query from a remote endpoint. I have read through section 2.4 here because it seems to describe a situation almost identical to mine.
The idea is that I want to filter my results from DBPedia based on information in my local RDF graph. The query is here:
PREFIX ns1:
<http://www.semanticweb.org/caeleanb/ontologies/twittermap#>
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT *
WHERE {
?p ns1:displayName ?name .
SERVICE <http://dbpedia.org/sparql> {
?s rdfs:label ?name .
?s rdf:type foaf:Person .
}
}
And the only result I get is dbpedia:John_McCain (for ?s). I think this is because John McCain is the only match in the first 'x' results, but I can't figure out how to get the query to return all matches. For example, if I add a filter like:
SERVICE <http://dbpedia.org/sparql> {
?s rdfs:label ?name .
?s rdf:type foaf:Person .
FILTER(?name = "John McCain"#en || ?name = "Jamie Oliver"#en)
}
Then it correctly returns BOTH dbpedia:Jamie_Oliver and dbpedia:John_McCain. There are dozens of other matches like Jamie Oliver that do not come through unless I specifically add it to a Filter like this.
Can someone explain a way to extract the rest of the matches? Thanks.
It looks like the cause of this issue is that the SERVICE block is attempting to pull all foaf:Persons from DBPedia, and then filter them based on my local Stardog db. Since there is a 10,000 result limit when querying DBPedia, only matches which occur in that set of 10,000 arbitrary Persons will be found. To fix this, I wrote a script to put together a FILTER block containing every string name in my Stardog db and attached it to the SERVICE block to filter remotely and thereby avoid hitting the 10,000 result limit. It looks something like this:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbr: <http://dbpedia.org/resource/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX ns1: <http://www.semanticweb.org/caeleanb/ontologies/twittermap#>
CONSTRUCT{
?s rdf:type ns1:Person ;
ns1:Politician .
}
WHERE {
?s rdfs:label ?name .
?s rdf:type dbo:Politician .
FILTER(?name IN ("John McCain"#en, ...)
}
So I encountered a Problem on DBpedia. Apparently I can retrieve any kind of property from a resource with the query below, but when the property is from the type DatatypeProperty or just a number (xsd:integer or something similar) the DBpedia SPARQL Endpoint returns an empty result.
I would like to know what I have to change or even better optional include in my current query to solve this problem.
Important note: Germany and population total are required inputs in my program. Please remember that I must use them.
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT ?objectLabel
WHERE {
?subject ?predicate ?object ; rdfs:label "Germany"#en .
?predicate rdfs:label "population total"#en .
?object rdfs:label ?objectLabel
FILTER (LANG(?objectLabel)='en')
}
Thank you for your help.
A DatatypeProperty is used to related an individual to a literal and literals can't have any outgoing edge, thus, no rdfs:label. If you want to have the lexical form of the literal you can use the str function:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT (str(?object) as ?value)
WHERE {
?subject ?predicate ?object ; rdfs:label "Germany"#en .
?predicate rdfs:label "population total"#en
FILTER (LANG(?objectLabel)='en')
}
Why does this SPARQL query return no data?
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
PREFIX dbpedia: <http://dbpedia.org/resource/>
SELECT *
WHERE {
<http://dbpedia.org/resource/Louis,_Prince_of_Condé_(1530–1569)> dbpedia-owl:abstract ?abstract
}
LIMIT 1
If you look at the DBpedia page, it shows the person has an abstract. Is it to do with the brackets in the URL? If so, how can I get round this?
This URI does not lead to the same result as the DBpedia page - for what ever reason. You can see this with
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
PREFIX dbpedia: <http://dbpedia.org/resource/>
SELECT *
WHERE {
<http://dbpedia.org/resource/Louis,_Prince_of_Condé_(1530–1569)> ?p ?o
}
LIMIT 100
But it has an owl:sameAs relation to
http://dbpedia.org/resource/Louis,_Prince_of_Cond%C3%A9_(1530%E2%80%931569)
That means if you use this URI in your query, it should work as expected. But you should indeed apply a FILTER on the language, e.g. 'en' for English abstracts.
As AKSW mentions, the resource actually doesn't have many properties, but is connected to the "canonical" version by an owl:sameAs link. You can keep using the IRI that you're using now, follow owl:sameAs in either direction to any of its equal resources (let's call them ?s), and then ask for the abstract of ?s. (And then it's not a bad idea to filter by language, if that's applicable.) You can do this with a query like this (note that the current DBpedia endpoint uses dbo:, now, not the older dbpedia-owl:):
select ?abstract where {
<http://dbpedia.org/resource/Louis,_Prince_of_Condé_(1530–1569)> (owl:sameAs|^owl:sameAs)* ?s .
?s dbo:abstract ?abstract .
filter langMatches(lang(?abstract),'en')
}
It does not have dbpedia-owl:abstract predicate. If you list its predicates you find the following properties:
http://www.w3.org/2002/07/owl#sameAs
http://xmlns.com/foaf/0.1/name
http://purl.org/dc/elements/1.1/description
http://dbpedia.org/ontology/alias
http://dbpedia.org/ontology/birthYear
http://dbpedia.org/ontology/deathYear
http://dbpedia.org/ontology/viafId
http://dbpedia.org/ontology/deathPlace
http://dbpedia.org/ontology/deathDate
http://dbpedia.org/ontology/birthPlace
http://dbpedia.org/ontology/birthDate