I'd like to find out if property paths exist between two entities on DBpedia. This is a sample query that I tried on snorql:
SELECT * WHERE {
:Braveheart (:|!:)* :Mel_Gibson
}
LIMIT 100
The queries runs into a memory error:
Virtuoso 42000 Error TN...: Exceeded 1000000000 bytes in transitive temp memory. use t_distinct, t_max or more T_MAX_memory options to limit the search or increase the pool SPARQL query: define sql:big-data-const 0 #output-format:application/sparql-results+json define input:default-graph-uri PREFIX owl: PREFIX xsd: PREFIX rdfs: PREFIX rdf: PREFIX foaf: PREFIX dc: PREFIX : PREFIX dbpedia2: PREFIX dbpedia: PREFIX skos: SELECT * WHERE { :Braveheart (:|!:)* :Mel_Gibson } LIMIT 100
I suspect someone's going to suggest setting up a local dbpedia mirror. If that's the case, I'd love some detailed steps on how to do so.
I think your query is a bit wrong for what you're trying to answer... also as there are no variables in it select * can't project anything out (i'd consider it a bug to even compile this), so let me rephrase your query to
ASK { dbr:Braveheart (<>|!<>)+ dbr:Mel_Gibson }
Sadly that query errs with the same problem you described.
While i agree, that complicated should be executed against local endpoints, the above query isn't complicated at all, especially considering that there are several direct edges between the two nodes:
SELECT * { dbr:Braveheart ?p dbr:Mel_Gibson }
I consider this a bug in Virtuoso's query planner and reported it: https://github.com/openlink/virtuoso-opensource/issues/641
Having said all that, i'd like to point out that in real cases you're probably interested in paths that don't only point forward. The direction of edges greatly depends on modelling. So consider using queries like these instead:
ASK { dbr:Braveheart ((<>|!<>)|^(<>|!<>))+ dbr:Mel_Gibson }
The expression says follow any edge in their direction or against it (^) for at least one step. (Yes, i also wonder why property paths didn't a short syntax for arbitrary edges ;) )
Spinning off #JörnHees's answer, a couple of points:
<> is an invalid predicate identifier. For Virtuoso, <> identifies a document (Location of Content that returns 200 OK on HTTP GET) which is why <#> or <#this> work. This isn't a parsing issue since it has more to do with the semantics of an identifier.
The public DBpedia endpoint isn't configured to accept that kind of query, hence the error.
Using <#this> rather than <>, we have --
prefix dbpedia: <http://dbpedia.org/resource/>
ASK { dbpedia:Braveheart (<#this>|!<#this>)+ dbpedia:Mel_Gibson }
Two alternative instances, both hosted by OpenLink Software (my employer, and producer of Virtuoso), that produce solutions for that query:
DBpedia-Live instance
LOD Cloud Cache instance
Related
I have created a prefix which has various sublevels for example:
PREFIX myprefix: <https://myprefix.org/>
I have several sublevels of prefix that I have used to organise my data. For example:
https://myprefix.org/people
https://myprefix.org/buildings
https://myprefix.org/plants
I would now like to be able to specify the prefix with the extension in a SPARQL query. For example, I would like to select all of the properties in my database connected to the instance with the URI https://myprefix.org/people/michael :
PREFIX myprefix: <https://myprefix.org/>
select * where {
myprefix:people/michael ?p ?o.
} limit 100
I have tried several approaches and have been unable to extend the prefix URI in the SPARQL query. I am now wondering if it good practice to use subcategories for prefixes or whether each prefix be complete to the instance or property it is describing.
Is there any advice on how to accomplish this?
What I tend to do is to have a prefix for entities and one for ontologies, such as this:
PREFIX : <http://example.com/entities#>
PREFIX ont: <http://example.com/ontology#>
Then, when I want different entities, I will simply write:
:people_michael or :plants_1234.
Alternatively, your approach can also work, but in SPARQL you'll need to escape the /, so your query will be:
PREFIX myprefix: <https://myprefix.org/>
SELECT *
WHERE {
myprefix:people\/michael ?p ?o.
}
LIMIT 100
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 }
}
I am running a test query on SPARQL to test inferencing. My query is as follows:
PREFIX eem: <http://purl.org/eem#>
PREFIX ns: <http://purl.org/net/ns/>
PREFIX sc_data: <http://purl.org/net/ns/sc_data/>
PREFIX dbp: <http://dbpedia.org/resource/>
PREFIX dbpprop: <http://dbpedia.org/property/>
PREFIX ex: <http://www.example.org/rdf#>
SELECT ?roa
WHERE {
SERVICE <http://dbpedia.org/sparql>{
ex:vaccine a dbp:Polio_vaccine.
ex:vaccine dbpprop:routesOfAdministration ?roa.
}
}
I get no results for this query when trying at the snorql page. When I specify that something is polio vaccine, shouldn't it automatically inherit the properties specified for the vaccine? What do I need to change?
In your original query, ex:vaccine is a URI node, short for <http://www.example.org/rdf#vaccine>. It's very unlikely that DBpedia contains any information about it. While the DBpedia endpoint may (or may not) include information that is inferrable from the DBpedia data, it doesn't treat your SPARQL query as part assertion and part query.
You're literally saying "find values of ?roa such that ?roa is the route of administration of ex:vaccine and ex:vaccine is an instance of dbp:Polio_vaccine". ex:vaccine is a constant though, so it's kind of like saying, "find factors of 10, and by the way, 10 is the sum of 3 and 4." The "10 is the sum of 3 and 4" isn't in the data, though, so there won't be any matches, even if there are recorded factors of 10. On top of that, dbp:Polio_vaccine is an individual in DBpedia, not a class, so there won't be any instance of it.
Instead, you want to ask for any values of the dbpprop:routesOfAdministation property for the individual dbpedia:Polio_vaccine. The query you need here is (I'm using the prefixes that are defined at http://dbpedia.org/sparql, the public endpoint):
select ?routes where {
dbpedia:Polio_vaccine dbpprop:routesOfAdministration ?routes
}
SPARQL results
I am using SPARQL Query tab in Protege 5 to query an OWL ontology I have been constructing. I succeded in many kinds of queries, but when I use some specific class of my ontology inside the very same queries (that are apparently well formed) they return no results. Following, two of the problematic queries - assuming "Event" as one of the concepts of the ontology (http://www.semanticweb.org/ontologies/2014/5/MyOnto#Event):
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX onto: <http://www.semanticweb.org/ontologies/2014/5/MyOnto#>
SELECT ?a WHERE { ?a rdfs:subClassOf onto:Event }
and, with the same prefixes
SELECT ?a WHERE { ?a rdfs:range onto:Event }
Both return no results. However, if I substitute "onto:Event" for, let's say, ?b, both return a long list of results - inclunding Event as a match for ?b.
Is it something I'm misusing or forgetting (although I've seen this pattern in several links on internet with people claiming to have got results) or is it a limitation of SPARQL or some issue of the Protege tab?
The problem is that, in fact, although the URI of the ontology is:
<http://www.semanticweb.org/ontologies/2014/5/MyOnto#>
in the OWL document, the prefix used before class names is the IRI:
<http://www.semanticweb.org/ontologies/2014/2/untitled-ontology-662#>
Thus, replacing the old onto: by
PREFIX onto: <http://www.semanticweb.org/ontologies/2014/2/untitled-ontology-662#>
solves the issue.
(Thanks to #Csongor from Protégé Project mail list, who found the answer.)
P.S.: It's also worthy to note that it can't be taken for granted that all the terms in the ontology will be <current_ontology_URI#term> - e.g. if one includes some terms in the ontology and then changes ontology URI, these terms will be identified as <previous_ontology_URI#term> and the new ones as <current_ontology_URI#term> (which was exactly the cause of the problem above).
I had the same problem, whenever using an ontology specific class there were no results although there should have been. My ontology (pizza.owl) was loaded from a local file.
I found that it is required to add the file name in the PREFIX.
PREFIX : <http://www.co-ode.org/ontologies/pizza/pizza.owl#>
After that I got the information that I expected.
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