SPARQL query not inferencing properties after class specified - sparql

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

Related

How can I get list of all articles with ingredient property:?

I would like to get list of all articles containing ingredient property. I tried to figure it out on my own but the query I used did not work.
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT *
WHERE ingredient{
?ingredient a dbo:ingredient.
}
I would appreciate if you could show me how I can get list of all articles having ingredient property and the list of the ingredients in another column.
Your SPARQL query asks for instances of the class dbo:ingredient. However, if you actually visit http://dbpedia.org/ontology/ingredient, you'll see that this is a property, not a class.
You'll need to reformulate your query to ask for "all things that have the ingredient property", something like this:
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT DISTINCT ?x
WHERE {
?x dbo:ingredient ?ingredient.
}
That will give you the resources that have an ingredient property. If you're after the actual wikipedia article link, you can further query for, for example, the value of the foaf:isPrimaryTopicOf property for each resource.
Generally speaking, it helps to use the DBPedia browser to get a feel for how the data is modeled: what properties are available, and which classes are used. That will inform you how to formulate your SPARQL queries.

Use SPARQL property path on DBpedia

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

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

Extract Named Enities that are listed in dbpedia pages but there is no informatiotion about them

I am trying to collect Albums and the list of songs per Album. For example for the Album
River_of_Tuoni, the dbpprop:title property provides the list of the songs but only two of them are in DBpedia.
so when i do the following query , I only get two, (My_Only_car,River_of_Tuoni_(song)).
SELECT ?songs
WHERE {
:River_of_Tuoni dbpprop:title ?songs. ?songs a dbpedia-owl:Song .
}
How can i get all the songs (Lullaby, Sunrise,...)?
dbpprop:title property provides the list of the songs but only two of
them are in DBpedia.
The dbprop:title property doesn't provide any list; there just happen to be a number of triples with that property. All the data is in DBpedia; the values you've shown in the screenshot indicate that two of the values happen to be URIs, while other values happen to be strings. In general, the data with the dbpprop: properties is "dirtier" than the dbpedia-owl: properties, so getting two different types of values is not very surprising.
The simple query
select ?title where {
dbpedia:River_of_Tuoni dbpprop:title ?title
}
SPARQL results
returns all the titles. However, because the dbpedia-owl: properties have cleaner data, I'd usually suggest that you consider using one of those instead of dbpprop:title, but in this case it doesn't look like there's an alternative. You might consider this alternate query to get just strings, though:
select ?title where {
dbpedia:River_of_Tuoni (dbpprop:title/rdfs:label)|dbpprop:title ?title
filter isLiteral(?title)
}
SPARQL results
For the cases where the value is another resource, taking the rdfs:label of the resource provides a string. (I think that this should also be achievable with dbprop:title/(rdfs:label?), but that doesn't work with the DBpedia endpoint.)

How do I query DBPedia to obtain all owl:sameAs links?

I have a direct link to a DBPedia page (e.g. Argentina) and I'd like to retrieve some or all links with the owl:sameAs label (e.g. wikidata, freebase, etc.)
All the tutorials that I've read focus on retrieving group of object with particular features (e.g., French films).
I've also read this but it just returns one result instead of the entire list of owl:sameAs.
How do I do this?
The following query returns what you're looking for:
PREFIX dbpedia: <http://dbpedia.org/resource/>
SELECT ?obj WHERE {
dbpedia:Argentina (owl:sameAs|^owl:sameAs) ?obj
}
Note that the URI of the resource is actually http://dbpedia.org/resource/Argentina, not page/Argentina. When you put the first URI into a web browser, though, you get redirected to the latter. Be sure to use the former in your query (or just use the prefix dbpedia:).