Fail to retrieve a wikidata item through SPARQL - sparql

I tried to search and get the ID of a item with a certain label: Teodor Bogdanov. I can search this name successfully through wikidata website. However, I failed to do so by searching through SPARQL. The code is here.
I also copied it here:
SELECT distinct ?item ?itemLabel ?itemDescription WHERE{
?item ?label "Teodor Bogdanov".
}
The same thing happens for Félix Anaut
Could anyone help me fix this issue? Thank you in advance.

THere are two issues in your query. The predicate in your triple pattern is a variable, while it should be a constant, rdfs:label. It asks about all items and properties linked to "Teodor Bogdanov". The second issue is the missing language tag. When these two are fixed, you get the following query
SELECT distinct ?item {
?item rdfs:label "Teodor Bogdanov"#en .
}
For "Félix Anaut", while this spelling with an acute accent is used in English Wikipedia, that's not the case in Wikidata.

Related

In a wikidata SPARQL query how to address a file?

How to address a commons Media File?
In wikidata want to find all objects, which have a commons media file attached through a specific property with a SPARQL query.
Example:
SELECT ?item
{
# get all objects which have this file as a LocatorMap
?item wdt:P242 commons:LocationPeru.svg
}
This does not work and neither do all variants like wd:commons:LocationPeru.svg, p:P242 [ps:P242 psv:commons:LocationCuba.svg] or everything else I tried. I also tried a FILTER with the label but rdfs:label ?label did not work for me on the fileobject.
So, how is the correct syntax?
Thanks.
Actually, I want to filter out specific ones from a more complex query with MINUS, but reduced my problem to this.
You can use the image's full URL:
SELECT ?item
{
?item wdt:P242 <http://commons.wikimedia.org/wiki/Special:FilePath/LocationPeru.svg>
}
Actually, from the above query it seems that no item indicates LocationPeru.svg as locator map. This is because in Q419#P242 there is an higher-ranked locator map.
For ignoring the statements' ranking, you can use:
SELECT ?item
{
?item p:P242 [ ps:P242 <http://commons.wikimedia.org/wiki/Special:FilePath/LocationPeru.svg> ]
}
For filtering only the normal rank, you can use:
SELECT ?item
{
?item p:P242 [
ps:P242 <http://commons.wikimedia.org/wiki/Special:FilePath/LocationPeru.svg> ;
wikibase:rank wikibase:NormalRank
]
}

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 }
}

Wikidata sparql query returns 0 result

I’m new to query languages and linked data so thanks a lot for the help. I also have a similar question about sparql on dbpedia
dbpedia sparql query returns 0 result
I would like to look up all the art movements in wikidata with the associated artists (founder/inventor/creator, known for), date start, date end, country. Here is my query:
PREFIX wdno: <http://www.wikidata.org/prop/novalue/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT ?art ?artLabel ?start ?end ?countryLabel ?influencebyLabel WHERE {
?art wdt:P31 wd:Q968159 ;
wdt:P571 ?start ;
wdt:P576 ?end;
wdt:P17 ?country ;
wdt:P737 ?influenceby .
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
When I run the query only for the artLabel, it shows 300s result but as only a few has start date, when I include the start date, my dataset shrank, and when I include the rest of the search terms, there’s few record that has all information. My question is how can I generate result where the empty cells also get recorded instead of discarded?
Also, what’s the difference between this wikidata result and the dbpedia result?
Thanks
Answered in the comments...
Ettore Rizza wrote:
You need to add optional clauses for the properties that are not always filled.

Querying DBpedia-Live with SPARQL does not give same answer as DBpedia

I want to query DBpedia with DBpedia Live endpoint.
I have this query :
SELECT *
WHERE {
?x a dbo:Person .
?x rdfs:label "Usain Bolt"#en .
}
This query gives the correct answer with most names I tried (for example “Teddy Riner"#en) but it fails with Usain Bolt and Rachid Badouri.
I don’t get why as their DBpedia pages (Teddy Riner, Usain Bolt) are constructed the same way: they both have a rdfs:label, which is written exactly like I did.
It seems to me that there is an incoherence between the endpoint and DBpedia. But I don’t think that it's because the endpoint is not to date.
Even more surprising, this query gives the correct answer:
SELECT *
WHERE {
?x rdfs:label "Usain Bolt"#en .
}
However, Usain Bolt is a dbo:Person! Same thing for Rachid Badouri.
Could someone explain me why the first query does not give answer?
Any help would be appreciated! Thanks
According to DBpedia-Live, at the time of writing, the entity with rdfs:label "Usain Bolt"#en has many types, but is not a dbo:Person. Similar for the entity with rdfs:label "Rachid Badouri"#en.
In contrast, the entity with rdfs:label "Teddy Riner"#en is a dbo:Person.
Note: DBpedia-Live content is a moving target, varying with Wikipedia content changes, adjustments in the templates, and other variables. The statements I made above may no longer be true when you read this.

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)