SPARQL BABELNET Prefix not recognised in DBpedia SNORQL - sparql

I want to reproduce the example from the Babelnet SPARQL Endpoint in DBpedia/Snorql.
I enter the prefixes and the query as such:
PREFIX bn-lemon: <http://babelnet.org/model/babelnet#>
PREFIX lemon: <http://www.lemon-model.net/lemon#>
SELECT ?entries WHERE {
?entries a lemon:LexicalEntry .
?entries lemon:language ?lang .
FILTER(?lang = "IT")
} LIMIT 30
and I get no result. If I run exactly the same query (without the 2 prefixes) in the Babelnet SPARQL endpoint (https://babelnet.org/sparql/) I get several results. What may be the reason for this? I have hat similar situations when using other prefixes on different subjects outside of DBpedia.
Thank you for the valuable feedback. I have modified my code using SERVICE as such:
PREFIX lemon: <http://lemon-model.net/lemon#>
PREFIX lexinfo: <http://www.lexinfo.net/ontology/2.0/lexinfo#>
SELECT DISTINCT ?entries WHERE {
SERVICE <http://babelnet.org/rdf/> {
?entries a lemon:LexicalEntry .
?entries lemon:language ?lang .
FILTER(?lang = "IT")
}
}
LIMIT 30
However the query is blocked for security reasons: Virtuoso 42000 Error SQ070:SECURITY: Must have select privileges on view DB.DBA.SPARQL_SINV_2 SPARQL query
I assume that people using a public SPARQL accesspoint like DBpedia sparl have no chance. Are there any alternatives beside installing your own accesspoint?

Related

SPARQL error attempt to attach a filter with used variable

I'm trying to extract information about 2 genes at the same time using this query:
BASE <http://www.southgreen.fr/agrold/>
PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
PREFIX vocab:<vocabulary/>
SELECT DISTINCT ?gene ?gene_lbl ?pathway
WHERE{
VALUES ?gene {<http://identifiers.org/ensembl.plant/BGIOSGA000040>
<http://identifiers.org/ensembl.plant/Sb01g003700.1>}
{
GRAPH ?graph1{
OPTIONAL{?gene rdfs:label ?gene_lbl.}
}
}
UNION
{
GRAPH ?graph2{
OPTIONAL{?gene vocab:is_agent_in ?pathway.}
}
}
}
but it gives me the following error :
Virtuoso 37000 Error SP031: SPARQL compiler: Internal error: sparp_gp_attach_filter_cbk(): attempt to attach a filter with used variable
It work without problems when I run it using only one gene OR when I remove the OPTIONAL keyword, can someone explain to me the reason behind this behaviour ?
Endpoint Virtuoso version: 07.10.3211
EDIT :
Part of the complexity is due to the fact that this is just a sample of a bigger query.
#TallTed, thank you for you answer, when I apply your proposed method to extract more information I don't get the desired results. for instance in this example gene OB12G15100 encodes a protein, but it doesn't show up in the results unless if I comment the OPTIONAL of gene_lbl, as far as I know, since the gene_lbl is optional it can be ignored, hence, showing results of the rest of the query but it doesn't do so and I don't know why.
Please forgive my lack of knowledge.
I believe your target endpoint, now running a 3 year old version, should be encouraged to upgrade to the current Virtuoso Open Source Edition, 07.20.3229 a/k/a 7.2.5.1. Note that both your original query and my revision execute without error on the LOD Cloud Cache (which lacks some of the data in AgroLD, so these don't deliver the results you want).
That said, I think your original query is unnecessarily complex. Note that this revision gets results from AgroLD with no problem --
BASE <http://www.southgreen.fr/agrold/>
PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
PREFIX vocab:<vocabulary/>
SELECT DISTINCT ?gene ?gene_lbl ?pathway
WHERE
{
VALUES ?gene { <http://identifiers.org/ensembl.plant/BGIOSGA000040>
<http://identifiers.org/ensembl.plant/Sb01g003700.1> }
OPTIONAL{ ?gene rdfs:label ?gene_lbl }
OPTIONAL{ ?gene vocab:is_agent_in ?pathway }
}

Get movie(s) based on book(s) from DBpedia

I am new to SPARQL and trying to fetch a movie adapted from specific book from dbpedia. This is what I have so far:
PREFIX onto: <http://dbpedia.org/ontology/>
SELECT *
WHERE
{
<http://dbpedia.org/page/2001:_A_Space_Odyssey> a ?type.
?type onto:basedOn ?book .
?book a onto:Book
}
I can't get any results. How can I do that?
When using any web resource, and in your case the property :basedOn, you need to make sure that you have declared the right prefix. If you are querying from the DBpedia SPARQL endpoint, then you can directly use dbo:basedOneven without declaring it, as it is among predefined. Alternatively, if you want to use your own, or if you are using another SPARQL client, make sure that whatever short name you choose for this property, you declare the prefix for http://dbpedia.org/ontology/.
Then, first, to get more result you may not restrict the type of the subject of this triple pattern, as there could be movies that actually not type as such. So, a query like this
select distinct *
{
?movie dbo:basedOn ?book .
?book a dbo:Book .
}
will give you lots of good results but not all. For example, the resource from your example will be missing. You can easily check test the available properties between these two resource with a query like this:
select ?p
{
{<http://dbpedia.org/resource/2001:_A_Space_Odyssey_(film)> ?p <http://dbpedia.org/resource/2001:_A_Space_Odyssey> }
UNION
{ <http://dbpedia.org/resource/2001:_A_Space_Odyssey> ?p <http://dbpedia.org/resource/2001:_A_Space_Odyssey_(film)>}
}
You'll get only one result:
http://www.w3.org/2000/01/rdf-schema#seeAlso
(note that the URI is with 'resource', not with 'page')
Then you may search for any path between the two resource, using the method described here, or find a combination of other patterns that would increase the number of results.

dbpedia sparql movie query sql

Hi I'm trying to learn how to query DBpedia using SPARQL. I can't find any website/source that shows me how do this and I'm finding it difficult to learn how to use all the properties (like the ones available at http://mappings.dbpedia.org/index.php?title=Special%3AAllPages&from=&to=&namespace=202 ). Any good source I can learn from?
So for example if I want to check if the wikipedia page http://en.wikipedia.org/wiki/Inception is a movie (property film) or not, how do I do that?
The wikipedia URL http://en.wikipedia.org/wiki/Inception maps to the dbpedia URI http://dbpedia.org/resource/Inception. Dbpedia has a SPARQL endpoint at: http://dbpedia.org/sparql, which you may use to run queries either programmatically or via the html interface.
To check if http://dbpedia.org/page/Inception is a "movie", you have many options. To give you an idea:
If you know the URI of "movie" in dbpedia (it is http://schema.org/Movie), then run an ASK query to check against that type. ASK will return true/false based on whether the pattern in the where clause is valid against the data:
ASK where {
<http://dbpedia.org/resource/Inception> a <http://schema.org/Movie>
}
If you don't know the URI of "movie" then you have a number of options. For example:
Execute an ASK query with a filter on whether the resource has a type that contains the word "movie" somewhere in its uri (or its associated rdfs:label, or both). You would use a regular expression for this:
ASK where {
<http://dbpedia.org/resource/Inception> a ?type .
FILTER regex(str(?type), "^.*movie", "i")
}
Same idea, but return all matches and post-process the results (programmatically I pressume) to see if they match your request:
select distinct ?type where {
<http://dbpedia.org/resource/Inception> a ?type .
FILTER regex(str(?type), "^.*movie", "i")
}
Return all the types of the resource without applying a filter and post-process to see if they match your request:
select distinct ?type where {
<http://dbpedia.org/resource/Inception> a ?type
}
Many options. The SPARQL spec is you number one resource.
First I suggest you start reading up on what exactly SPARQL is. There are tons of really good tutorials such as: this.
If you want to write SPARQL queries on dbpedia, there are various endpoints that you can use. They don't always accept all features that are supported by SPARQL, but if you don't want to go through the trouble of installing one locally, they can be a relatively reliable test environment. The queries that I am going to write below, have been tested on Virtuoso endpoint.
Let's say you want to find all the movies in dbpedia. You first need to know what is the URI for a movie type in dbpedia. If you open Inception in dbpedia, you can see that the type dbpedia-owl:Film is associated to it. So if you want to get the first 100 movies, you just need to call:
select distinct *
where {
?s ?o dbpedia-owl:Film
} LIMIT 100
If you want o know more about each of these movies, you just need to expand your queries by expanding the triples.
select distinct *
where {
?s ?p dbpedia-owl:Film.
?s ?x ?y.
} LIMIT 100

Simple SPARQL query on dbpedia results doesn't match expectations

I am struggling with the following SPARQL query executed via at DBpedia's SPARQL endpoint:
select (count(?abstract) as ?count)
where {
<http://dbpedia.org/resource/Linked_Data> dbpedia-owl:abstract ?abstract .
}
SPARQL seems pretty simple and when I look at the linked data page, it appears that expected result would be 9. But the actual response is 0. Is my understanding or expectation wrong? Could someone more experienced clarify please?
There are nine abstracts on the linked data article, but the title of the article is "Linked data", not "Linked Data", and the capitalization matters. Thus, you can do this, and see all nine abstracts getting counted:
select (count(?abstract) as ?nAbstract) {
dbpedia:Linked_data dbpedia-owl:abstract ?abstract
}
SPARQL results
The public endpoint defines the dbpedia: prefix. It's short for http://dbpedia.org/resource, so dbpedia:Linked_data is just short for http://dbpedia.org/resource/Linked_data. That's the URI for the resource, but when you put it into a web browser, you'll get redirected to a human readable HTML version at http://dbpedia.org/page/Linked_data.

How to form dbPedia iSPARQL query (for wikipedia content)

Say I need to fetch content from wikipedia about all mountains. My target is to show initial paragraph, and an image from respective article (eg. Monte Rosa and Vincent Pyramid.
I came to know about dbpedia, and with some research got to find that it provides live queries into wiki database directly.
I have 2 questions:
1 - I am finding it difficult how could I formulate my queries. I can't play around iSPARQL. I tried following query but it throws error saying invalid xml.
SELECT DISTINCT ?Mountain FROM <http://dbpedia.org> WHERE {
[] rdf:type ?Mountain
}
2 - My requirement is to show only mountains that have at least 1 image (I need to show this image too). Now the ones I listed above have images, but how could I be sure? Also, looking at both examples I see many fields differ in wiki articles - so for future extension it maybe quite difficult to fetch them.
I just want to reject those which do not have sufficient data or description.
How can I filter out mountains based on pictures present?
UPDATE:
My corrected query, which solves my first problem:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT ?name ?description
WHERE {
?name rdf:type <http://dbpedia.org/ontology/Mountain>;
dbpedia-owl:abstract ?description .
}
You can also query dbpedia using its SPARQL endpoint (less fancy than iSPARQL). To find out more about what queries to write, take a look at the DBpedia's datasets page. The examples there show how one can select pages based on Wikipedia categories. To select resources in the Wikipedia Mountains category, you can use the following query:
select ?mountain where {
?mountain a dbpedia-owl:Mountain .
}
SPARQL Results
Once you have some of these links in hand, you can look at them in a web browser and see the data associated with them. For instance the page for Mount Everest shows lots of properties. For restricting results to those pages that have an image, you might be interested in the dbpedia-owl:thumbnail property, or perhaps better yet foaf:depiction. For the introductory paragraph, you probably want something like the dbpedia-owl:abstract. Using those, we can enhance the query from before. The following query finds things in the category Stratovolcanoes with an abstract and an depiction. Since StackOverflow is an English language site, I've restricted the abstracts to those in English.
select * where {
?mountain a dbpedia-owl:Mountain ;
dbpedia-owl:abstract ?abstract ;
foaf:depiction ?depiction .
FILTER(langMatches(lang(?abstract),"EN"))
}
LIMIT 10
SPARQL Results