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
Related
In a certain knowledge graph there is a large number of individuals that need
to be assigned a literal token of the type xsd:token. It is not practical to
do so manually, therefore I am trying with an INSERT instruction. However, I
can't find a way to assign the desired literal type in that kind of query.
Consider in first place this basic example knowledge graph:
#prefix : <http://my.example.web/> .
#prefix foaf: <http://xmlns.com/foaf/0.1/> .
:1 a foaf:Person ;
foaf:name "Jane Doe" .
:2 a foaf:Person ;
foaf:name "John Smith" .
The exercise would be to add a token created by removing the blank spaces from
the foaf:name literal. For the :1 this would translate into the addition of the triple:
:1 dcterms:identifier "JaneDoe"^^xsd:token .
With a SELECT query I can archive it the following
way:
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT STRDT(?token, xsd:token)
WHERE {
GRAPH <http://my.example.web/> {
?s foaf:name ?name .
BIND(REPLACE(STR(?name)," ","") AS ?token) .
}
}
Which produces the result:
LONG VARCHAR
_______________________________________________________________________________
JaneDoe
JohnSmith
2 Rows. -- 54 msec.
Now using the same formulation, but with an INSERT query:
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dcterms: <http://purl.org/dc/terms/>
INSERT
{
GRAPH <http://my.example.web/> {
?s dcterms:identifier STRDT(?token, xsd:token) .
}
}
WHERE {
GRAPH <http://my.example.web/> {
?s foaf:name ?name .
BIND(REPLACE(STR(?name)," ","") AS ?token) .
}
}
An error is the result:
*** Error 37000: [Virtuoso Driver][Virtuoso Server]SQ074: Line 17 (line 17 of "(console)"): SP030: SPARQL compiler, line 9: syntax error at 'STRDT' before '('
In essence I need a way to apply the STRDT function to the
object of a triple inside the INSERT clause. Or any other alternative mechanism allowing to set a literal type in this kind of query.
Both your queries are invalid:
SELECT STRDT(?token, xsd:token)
According to the SelectClause production, an expression must be followed by AS to give it a variable binding. In essence, you have to use the same syntax you would have used after BIND (you also need parentheses around it). As for why Virtuoso accepts this, well Virtuoso does not strictly follow all of SPARQL ‒ it also allows , between the variables in SELECT, has the DEFINE clause, and allows undeclared prefixes if they are recognized by the store.
This is valid:
SELECT (STRDT(?token, xsd:token) AS ?tokenTyped)
or modify the BIND:
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?token
WHERE {
GRAPH <http://my.example.web/> {
?s foaf:name ?name .
BIND(STRDT(REPLACE(STR(?name)," ",""), xsd:token) AS ?token) .
}
}
This seems the cleanest to me.
Likewise, for the second query, you cannot have an expression as an object of a triple (or any position for that matter), see the Object production. Using a variable is the best the syntax allows you to do (while it would certainly be nice to be able to use expressions as you wanted):
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dcterms: <http://purl.org/dc/terms/>
INSERT
{
GRAPH <http://my.example.web/> {
?s dcterms:identifier ?token .
}
}
WHERE {
GRAPH <http://my.example.web/> {
?s foaf:name ?name .
BIND(STRDT(REPLACE(STR(?name)," ",""), xsd:token) AS ?token) .
}
}
I have tested it and it should work on OpenLink Virtuoso version 07.20.3231. If you have issues with this, perhaps the Virtuoso instance needs to be updated, or refer to GitHub.
I have a list of artstyles in graphDB, i am trying to use the SERVICE function to get their labels from Wikidata with this query:
PREFIX gp: <http://www.semanticweb.org/kandd/group76/final_project#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?movement ?label
WHERE{
?artist gp:hasArtStyle ?movement.
SERVICE <https://query.wikidata.org/sparql>{
?movement rdfs:label ?label .
FILTER (langMatches( lang(?label), "EN" ) )
}
}
note that gp is a namespace that only exists in my graph, not anywhere on the internet and also note that ?movement contains a list of valid Wikidata URIs such as http://www.wikidata.org/entity/Q186030
yet still the response I get is:
Error 500: error
Query evaluation error: org.eclipse.rdf4j.query.QueryEvaluationException: org.eclipse.rdf4j.query.QueryEvaluationException: java.io.IOException: Unkown record type: 83 (HTTP status 500)
What am I doing wrong?
Remember that you query is handled from the inside to the outside, meaning that the service part is handled first, and then the part where you use your own specific property.
Currently, your query on WikiData is very general. You ask for everything that has a rdfs:label, and then filter on all the English labels it returns.
Given this, my guess is that you query simply times out. Instead, I would try something like this:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
SELECT *
WHERE{
SERVICE <https://query.wikidata.org/sparql>{
?artist wdt:P101 wd:Q186030 ; #Field of Work is contemporary art
wdt:P31 wd:Q5 ; #instance of Human
rdfs:label ?name . #get the label
FILTER (langmatches(lang(?name), "en"))
}
}
If I try this in GraphDB, it returns 156 results.
I am using the Virtuoso SPARQL endpoint for DBpedia. I am having no issue running some test queries, but my issue is when I run on a query based on the foaf:name "literal" of an entity. Here is my code below:
prefix db: <http://dbpedia.org/resource/>
prefix dbo: <http://dbpedia.org/ontology/>
prefix foaf: <http://xlms.com/foaf/0.1/>
SELECT ?capital WHERE{
?state dbo:capital ?capital .
?state foaf:name "State of Alaska"#en .
}
My logic is that by ?state dbo:capital ?capital refers to the capital of a state within DBpedia owl ontology. ?state foaf:name "State of Alaska"#en should match the variable ?state up with the literal entity Alaska. I am having no issue when my queries are controlled by variables that are not foaf:name. I have looked up examples and can't see what the issue is with my syntax. Even when I edit the last line to --
?state a foaf:name "State of Alaska"#en .
-- the code continues to fail. I have looked up other examples and can't find my specific issue. It appears as if this code SHOULD return the capital for Alaska based on the foaf:name Literal.
I found the answer. The key is to not add this prefix at the top
prefix foaf: <http://xlms.com/foaf/0.1/>
That should be replaced with the correct foaf: prefix declaration:
prefix foaf: <http://xmlns.com/foaf/0.1/>
Or probably even skipped, since the foaf: prefix is predefined.
So the query below actually works:
SELECT ?capital WHERE {
?state dbo:capital ?capital .
?state foaf:name "State of Alabama"#en .
}
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.
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