DBPEDIA + SPARQL Selecting films in function of their genre - sparql

Is it possible to get the list of films in function of their genre?
I tried this:
SELECT DISTINCT ?film_title ?film_abstract ?film_genre
WHERE {
?film_title rdf:type <http://dbpedia.org/ontology/Film> .
?film_title rdfs:comment ?film_abstract .
?film_genre <http://dbpedia.org/ontology/genre> ?film_genre .
FILTER(lang(?film_abstract) = "en" ).
}
LIMIT 20
But probably I've doing something wrong !
Thanks,
Danilo

Looks like a simple typo on your part. The third triple pattern should be the following:
?film_title <http://dbpedia.org/ontology/genre> ?film_genre
Also the FILTER you are using may make the query very slow, try using the following instead:
FILTER(LANGMATCHES(LANG(?film_abstract), "en"))
Though having played with your query there doesn't appear to be any data that actually matches your query in DBPedia. Essentially the genre property you are using appears only to be applied to music and not to films so you should remove the third triple pattern entirely if you actually want to get any results

Related

DBPedia SPARQL, return certain number of relevant page URIs for entity EXCEPT the URIs where the entity belongs to a set of subclasses of Owl:Thing

Looking for SPARQL query to do the following:
For example, I have the word Apple. Apple may refer to the organization Apple_Inc or the Species of Plants class as per the ontology. Owl: Thing has a subclass called Species, so I want to return those most relevant/maximum-hit URIs where the keyword Apple does not belong to the Species subclass. So when you return all the URIs, http://dbpedia.org/page/Apple should not be one of them, neither must ANY relevant link that comes under Species subclass.
By maximum-hit/most relevant I mean the top returned results that match the query! Like when you access the PrefixSearch (i.e. Autocomplete) API, it has the parameter called MaxHits.
For example http://lookup.dbpedia.org/api/search/PrefixSearch?QueryClass=&MaxHits=2&QueryString=berl is a link where you want to return the top 2 URIs that match the QueryString=berl.
Like I'm actually really struggling to even explain the work I've done so far because I'm not able to understand the structure and how to formulate a proper query..
with respect to negation in SPARQL, I found a relevant portion of the documentation in the link here.. But I do not know how and where to proceed from there, and cannot understand why keywords like ?person are used.. I can understand the person is used to selected well.. PEOPLE names, but I would like to know how and where to find these keywords like ?person, ?name to represent a specific entity..
SELECT ?uri ?label
WHERE {
?uri rdfs:label ?label .
filter(?label="car"#en)
}
I would really appreciate if someone could link me the part of the documentation I can clearly read and understand that ?uri is used to select a URI in the form www.dbpedia.org'/page/SomeEntity and what these ?person, ?name, ?label represent.
I'm actually so lost.. I will go up and start eating one elephant at a time. For now, I'll be very grateful if I get an answer to this.
If there is anyway you know where I can avoid learning and using SPARQL, that would work too! I know Python well enough, so leveraging an API to pull this information is also fine by me. This question was posted by me.
Answer posted by #Stanislav-Kravin --
SELECT DISTINCT ?s
WHERE
{ ?s a owl:Thing .
?s rdfs:label ?label .
FILTER ( LANGMATCHES ( LANG ( ?label ), 'en' ) )
?label bif:contains '"apple"' .
FILTER NOT EXISTS { ?s rdf:type/rdfs:subClassOf* dbo:Species }
}

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.

SPARQL RDFterm-equal FILTER

I am trying to validate concepts such that their respective categories are related by a parent/child relation (skos:broader). Getting the resources and their categories is trivial but then something is going on when I try to filter them with the relation:
select distinct *
where
{
<http://dbpedia.org/resource/Model-checking> dbo:wikiPageRedirect* ?conceptChild .
?conceptChild dbo:wikiPageRedirects* ?redirectedChild .
?redirectedChild dct:subject ?subjectChild .
?subjectChild skos:broader ?broaderThanSubjectChild .
<http://dbpedia.org/resource/Formal_methods> dbo:wikiPageRedirect* ?conceptParent .
?conceptParent dbo:wikiPageRedirects* ?redirectedParent .
?redirectedParent dct:subject ?subjectParent .
FILTER ( ?subjectParent = ?broaderThanSubjectChild )
}
This query has no results (via the Virtuoso SPARQL Query Editor on the public DBpedia endpoint) whereas the same query without the filter produces the expected results.
Any thoughts on this?
This does look like some kind of bug. Interestingly, if you replace the filter with a bind, e.g.,
bind((?subjectParent = ?broaderThanSubjectChild) as ?TEST)
you'll get 1 in one row, and 0 in the rest, so the comparison seems to be happening, but the filter is breaking for some reason.

Filtering results based on specific properties with specific values (cause timeout connection to DBpedia)

I'm trying to make a SPARQL query using Prolog and DBpedia. My objective is to tag in text all Persons, so for retrieving famous people I made this query that remove all results like Music groups(Band) and Organization, since I want to tag only real people and not abstract
select ?person where{
{
?person a dbpedia-owl:Person; rdfs:label "Name Surname" #it.
}
UNION
{
?person a dbpedia-owl:Person; foaf:name "Name"#it; foaf:surname "Surname"#it.
}
UNION
{
?person a dbpedia-owl:Person; foaf:name "Name Surname"#it.
}
FILTER NOT EXISTS {
{ ?subject <http://airpedia.org/ontology/type_with_conf#10> dbpedia-owl:Band .
?subject rdfs:label ?artistName .
FILTER ( str(?artistName) = "Name Surname" )
}
UNION
{
?subject <http://airpedia.org/ontology/type_with_conf#10> dbpedia-owl:Organisation .
?subject rdfs:label ?artistName .
FILTER ( str(?artistName) = "Name Surname" )
}
}
}
I use It. version of Dbpedia if you run this query use this version although the results will not be good for me.
So for example if I search "Metallica" as a person i don't want to get results cause is it a Band or(for me, but in this case is Metallica are an Organisation too) an Organisation
and it works good this are the results Metallica Query Results and those are for "Michael Jackson" Michael Jackson Query results
My problem is when i put someone that is not a Singer or a Music band for example if i try something like "Jim Carrey" i get " error transction timed out Jim Carrey.
I think I got this problem because those properties are Undefined for Jim Carrey, but i tried an to put an OPTIONAL marker in each subquery in the first filter, but i get too the same error
I put the code in a pastebin file so you can find all three query
I know that i should not use Static String in a query or there are a lot of better mode but i need that since i compose the query with prolog and than send to sparql online so i must do in this way.
TO #Joshua I tried to remove the FILTER(String) in the NOT EXIST (Filter) But I will not work anymore thanks however for helping me
Excuse me for too much editing but i resolved some part of the starting problem but didn't find a solution
First problem :Filtering results based on specific properties with specific values. (Works)
Second : The first works only for Things with that specific property (as show above) like(Metallica,Michael Jackson, The Beatles, ...) but not for thos without the properties in the filter.
(i can't use more than two link because I'm a newbe so i will put a link in the comments with a pastebin links with the 3 Query and the results of they)

Problem with a select SPARQL query on dbpedia

I try to get some data about a city using Sparql query on DBpedia. The problem is I can't get the query to work.
Currently I do something like this:
SELECT ?title,?name,?abs WHERE {
?title skos:subject
<http://dbpedia.org/resource/Category:Cities%2C_towns_and_villages_in_Slovenia>.
?title dbpprop:officialName ?name.
?title dbpprop:abstract ?abs
}
I get all the towns, villages from Slovenia with all the data. The problem is, I would like to get the data (officialName and/or abstract) only for one town, for example Ljubljana. So I tried some things like this:
SELECT ?name WHERE {
?name dbpprop:officialName
<http://dbpedia.org/resource/Ljubljana>.
}
Of course it does not work. I don't exactly know why, though :), but I've been experimenting a bit and noticed some things like if I put
?name skos:subject <http://dbpedia.org/resource/Category:Ljubljana>.
I get some results (which are not relevant to me, but anyway), but if I put
?name skos:subject <http://dbpedia.org/resource/Ljubljana>.
there are no results for anything though element skos:subject exists on the page http://dbpedia.org/resource/Ljubljana.
Could someone please explain why the second example does not work and how to get the result I would like to have?
Thanks,
Ablak
Thanks
You want to query for <http://dbpedia.org/resource/Ljubljana> as a subject, not an object; this would replace your ?title binding in the SPARQL query, for example:
SELECT ?name, ?abs WHERE {
<http://dbpedia.org/resource/Ljubljana>
skos:subject <http://dbpedia.org/resource/Category:Cities%2C_towns_and_villages_in_Slovenia> ;
dbpprop:officialName ?name ;
dbpprop:abstract ?abs .
}
This is why your graph match ?name skos:subject <http://dbpedia.org/resource/Ljubljana> does not return the expected results; the URI for Ljubljana should be the subject of the statement(s) you want to match.