Find people whose name start with a particular letter with sparql Wikidata? - sparql

This is my query but I don't get any results for records starting with "n"
SELECT ?item ?itemLabel
WHERE
{
?item wdt:P31/wdt:P279* wd:Q5.
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
FILTER regex (?itemLabel, "^(n)").
}

Related

Wikidata SPARQL filter properties by id

I have the following sparql:
#Cats
SELECT ?item ?itemLabel ?prop
WHERE
{
?item ?prop wd:Q7206.
filter not exists {?prop **FILTER** wdt:P921 }
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
# Helps get the label in your language, if not, then en language
}
I want to return relations excluding P921. What should I enter instead of FILTER?

How to handle case-sensitive SPARQL for Wikidata Query Service

Im trying to perform searchs on wikidata, but my query its a little weird. Some searchs are case-sensitive
EG: using "maradona" match perfectly but "cristiano ronaldo" don't. "Cristiano Ronaldo" match OK.
wikidata
SELECT DISTINCT ?item ?itemLabel (SAMPLE(?RIP) AS ?RIP) (SAMPLE(?image) AS ?image) WHERE {
?item wdt:P31 wd:Q5;
?label "cristiano ronaldo"#en.
?article schema:about ?item;
schema:inLanguage "en".
OPTIONAL { ?item wdt:P570 ?RIP. }
OPTIONAL { ?item wdt:P18 ?image. }
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
GROUP BY ?item ?itemLabel
I expect to be able to search all with lowercase (or other way to handle it better)

How to return null results in SPARQL?

I'm using the Wikidata SPARQL Query Service with the following query:
SELECT ?item ?itemLabel ?class ?classLabel ?projectLabel WHERE {
VALUES ?item { wd:Q1 wd:Q367204 }
?item wdt:P31 ?class;
wdt:P18 ?project.
SERVICE wikibase:label { bd:serviceParam wikibase:language "en,en". } }
link to the query
When running the query there is a result for Q1 because there is an image, but there is no result for Q367204 because there isn't an image.
My question: How can I get results for both Q1 and Q367204 regardless if there is an image available or not?
wd:Q367204 is missing from the results because "there isn't an image", but also because there isn't an "instance of" statement (P31). Therefore, you can get results for both instances by wrapping both of these in an OPTIONAL block, with just ?item and ?itemLabel for Q367204, and all variables for Q1:
SELECT ?item ?itemLabel ?class ?classLabel ?projectLabel WHERE {
VALUES ?item { wd:Q1 wd:Q367204 }
OPTIONAL {
?item wdt:P31 ?class;
wdt:P18 ?project.
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "en,en". }
}

Query for EU universities from Wikidata times out

Asking the Wikidata service for all universities works. But when restricted to only EU universities, this query times out.
WHERE {
?item wdt:P31/wdt:P279* wd:Q3918 ;
wdt:P17 ?country.
?country wdt:P463 wd:Q458 .
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
Any idea?
Strangely, using FILTER EXISTS is returns the result (although quite slow).
SELECT ?item ?itemLabel ?countryLabel ?country
WHERE {
?item wdt:P31/wdt:P279* wd:Q3918 ;
wdt:P17 ?country.
FILTER EXISTS { ?country wdt:P463 wd:Q458 }
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
Here's a link to the second query.

how to get list of the cities from certain country

I'm trying to get list of the cities of Ukraine for example.
I tried next code:
SELECT ?item ?itemLabel
WHERE {
?item wdt:P17 wd:Q212.
?item wdt:P31 wd:Q515
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
But it only outputs weird 3 results. I think i'm doing something wrong