Trying to re-use this script which used to work before, but it gives errors now:
Virtuoso 37000 Error SP030: SPARQL compiler, line 5: Undefined namespace prefix at 'dbpedia-owl' before 'dbpedia-owl:SportsTeam'
and the script itself:
select ?a ?b ?super (?aLength + ?bLength as ?length)
{
values (?a ?b) { (dbpedia-owl:Person dbpedia-owl:SportsTeam) }
{ select ?a ?super (count(?mid) as ?aLength) {
?a rdfs:subClassOf* ?mid .
?mid rdfs:subClassOf+ ?super .
}
group by ?a ?super
}
{ select ?b ?super (count(?mid) as ?bLength) {
?b rdfs:subClassOf* ?mid .
?mid rdfs:subClassOf+ ?super .
}
group by ?b ?super
}
}
order by ?length
limit 1
Any ideas how to update it?
dbpedia-owl: is not currently a predefined namespace prefix on DBPedia, though it once was. It has been replaced by dbo:.
As things stand, you can either change all instances of dbpedia-owl: in your queries to dbo:, or add this to the start of your queries --
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
The latter is recommended.
For best results, you should always include PREFIX declarations in your SPARQL, instead of relying on such server-side predefinitions. This avoids any problems if namespace predefinitions are removed (as in this case) or changed to new URLs, which could have unpredictable effect on your query results.
The namespace dbpedia-owl is not a prefixed namespace in DBPedia.
If you know the URL for the namespace, you can use PREFIX dbpedia-owl: <NAMESPACE_URL> before the SPARQL query. But if you're looking for DBpedia resource definitions of Person and SportsTeam, then you should be using (perhaps) dbo instead of dbpedia-owl.
Related
I have some working code for getting all the ancestors of a term in a hierarchy.
Following:
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX skos-xl: <http://www.w3.org/2008/05/skos-xl#>
PREFIX rdf: <http://www.w3.org/2000/01/rdf-schema#>
select ?grandparentliteralform (count(?parent) as ?distance)
{ ?iri skos:broader+ ?parent .
?parent skos:broader* ?grandparent .
?grandparent skos-xl:prefLabel ?grandparentlabel .
?grandparentlabel skos-xl:literalForm ?grandparentliteralform .
}
group by ?grandparent
order by DESC(?distance)
It breaks when an IRI's broader predicate is a subproperty (?p rdf:subPropertyOf skos:broader)
So right now I am doing this to capture all the subproperty predicates:
select ?grandparentliteralform (count(?parent) as ?distance)
{ ?iri ?p ?parent .
?parent skos:broader* ?grandparent .
?grandparent skos-xl:prefLabel ?grandparentlabel .
?grandparentlabel skos-xl:literalForm ?grandparentliteralform .
?p rdf:subPropertyOf skos:broader .
}
group by ?grandparent
order by DESC(?distance)
What i would really like to do is :
select ?grandparentliteralform (count(?parent) as ?distance)
{ ?iri ?p+ ?parent .
?parent ?p* ?grandparent .
?grandparent skos-xl:prefLabel ?grandparentlabel .
?grandparentlabel skos-xl:literalForm ?grandparentliteralform .
?p rdf:subPropertyOf skos:broader .
}
group by ?grandparent
order by DESC(?distance)
but using ?p+ or ?p* throws an error.
Unexpected token syntax error, unexpected <variable>, expecting <decimal literal> or <double literal> or <integer literal>
How can I use */+ with variables?
You can't. As the Property Paths section of the SPARQL 1.1 spec states:
The ends of the path may be RDF terms or variables. Variables can not be used as part of the path itself, only the ends.
You could potentially use alternatives to capture this:
?parent (skos:broader|your:alternative)* ?grandparent
Exact form will need to reflect your data structure and whether you want to allow mixes of skos:broader and your alternative (which my example allows). You can move the * operator inside the brackets and add it to each alternative if you want pure chains of specific properties.
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, ...)
}
why is showing this error, i see in the sparql query is correct, i don't see any mistake in prefix.
PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
PREFIX type: <http://dbpedia.org/class/yago/>
PREFIX prop: <http://dbpedia.org/property/>
SELECT ?country_name ?population
WHERE { ?country rdf:type dbpedia-owl:Country;
rdfs:label ?country_name ;
prop:populationEstimate ?population .
FILTER (?population > 2334456) .
FILTER ( lang(?country_name) = 'en')}
Error:
Virtuoso 37000 Error SP030: SPARQL compiler, line 1: Missing in PREFIX declaration at '<' before 'http:'
SPARQL query:
define sql:big-data-const 0 define input:default-graph-uri http://dbpedia.org PREFIX rdfs:
The query you've shown us might not be the same as the query you're actually running. First, the fact that the error message says "line 1" makes me wonder whether you've actually got the query run all onto one line. That can make it easy to get typo problems.
When I put your query into sparql.org's query validator, I do get a syntax error, because there's no prefix defined for rdf:. This is an error:
Line 7, column 18: Unresolved prefixed name: rdf:type
That said, the interactive web interface to the DBpedia endpoint includes some predefined namespace prefixes, and if you paste the query from the question into the web interface, it works just fine:
PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
PREFIX type: <http://dbpedia.org/class/yago/>
PREFIX prop: <http://dbpedia.org/property/>
SELECT ?country_name ?population
WHERE { ?country rdf:type dbpedia-owl:Country;
rdfs:label ?country_name ;
prop:populationEstimate ?population .
FILTER (?population > 2334456) .
FILTER ( lang(?country_name) = 'en')}
SPARQL results
I like to use the prefixes that DBpedia defines, since it makes copying and pasting easier, so I've used the prefix dbpprop: instead of prop:. I've also used langMatches instead of lang(…) = …, because it works with regional variants of languages, whereas the latter won't. I ended up with this query:
select ?country_name ?population where {
?country rdf:type dbpedia-owl:Country ;
rdfs:label ?country_name ;
dbpprop:populationEstimate ?population .
filter (?population > 2334456)
filter langMatches(lang(?country_name),'en')
}
SPARQL results
I need a Sparql query to recover the Type of a specific DBpedia resource. Eg.:
pt.DBpedia resource: http://pt.dbpedia.org/resource/Argentina
Expected type: Country (as can be seen at http://pt.dbpedia.org/page/Argentina)
Using pt.DBpedia Sparql Virtuoso Interface (http://pt.dbpedia.org/sparql) I have the query below:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
select ?l ?t where {
?l rdfs:label "Argentina"#pt .
?l rdf:type ?t .
}
But it is not recovering anything, just print the variable names. The virtuoso answer.
Actually I do not need to recover the label (?l) too.
Anyone can fix it, or help me to define the correct query?
http in graph name
I'm not sure how you generated your query string, but when I copy and paste your query into the endpoint and run it, I get results, and the resulting URL looks like:
http://pt.dbpedia.org/sparql?default-graph-uri=http%3A%2F%2Fpt.dbpedia.org&sho...
However, the link in your question is:
http://pt.dbpedia.org/sparql?default-graph-uri=pt.dbpedia.org%2F&should-sponge...
If you look carefully, you'll see that the default-graph-uri parameters are different:
yours: pt.dbpedia.org%2F
mine: http%3A%2F%2Fpt.dbpedia.org
I'm not sure how you got a URL like the one you did, but it's not right; the default-graph-uri needs to be http://pt.dbpedia.org, not pt.dbpedia.org/.
The query is fine
When I run the query you've provided at the endpoint you've linked to, I get the results that I'd expect. It's worth noting that the label here is the literal "Argentina"#pt, and that what you've called ?l is the individual, not the label. The individual ?l has the label "Argentina"#pt.
We can simplify your query a bit, using ?i instead of ?l (to suggest individual):
select ?i ?type where {
?i rdfs:label "Argentina"#pt ;
a ?type .
}
When I run this at the Portuguese endpoint, I get these results:
If you don't want the individual in the results, you don't have to select it:
select ?type where {
?i rdfs:label "Argentina"#pt ;
a ?type .
}
or even:
select ?type where {
[ rdfs:label "Argentina"#pt ; a ?type ]
}
If you know the identifier of the resource, and don't need to retrieve it by using its label, you can even just do:
select ?type where {
dbpedia-pt:Argentina a ?type
}
type
==========================================
http://www.w3.org/2002/07/owl#Thing
http://www.opengis.net/gml/_Feature
http://dbpedia.org/ontology/Place
http://dbpedia.org/ontology/PopulatedPlace
http://dbpedia.org/ontology/Country
http://schema.org/Place
http://schema.org/Country
All, I'm trying to get a director's filmography from dbpedia:
Both the queries below (and other attempts not shown) return empty sets. Query below doesn't work:
PREFIX d: <http://dbpedia.org/ontology/>
SELECT ?filmName WHERE {
?film d:director :woody_allen .
?film rdfs:label ?filmName .
}
Or (this is from) :
PREFIX m: <http://data.linkedmdb.org/resource/movie/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?filmTitle WHERE {
?film rdfs:label ?filmTitle.
?film m:director ?dir.
?dir m:director_name "Sofia Coppola".
}
Not sure what would be the problem with such simple queries. Any ideas here?
The problem with your first query is the use of :woody_allen (besides the fact that you haven't actually defined the default prefix and so the query should technically be illegal SPARQL) the term doesn't actually appear in the data as written.
Try rewriting your query like so:
PREFIX d: <http://dbpedia.org/ontology/>
SELECT ?filmName WHERE {
?film d:director <http://dbpedia.org/resource/Woody_Allen> .
?film rdfs:label ?filmName .
}
The above does give results.
As for your second query DBPedia does not use the Linked MDB ontologies so that query can't match anything