For simplicity I use wikidata as example: I have a query:
SELECT ?item ?itemLabel ?mastoadress
WHERE
{
?item wdt:P4033 ?mastoadress.
?item wdt:P106 wd:Q1930187. # occupation journalist
?item wdt:P27 wd:Q183. # country of citizenship germany
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ORDER BY ?itemLabel
How can I achieve the result list to include a column where each entry gets its own unique integer index.
Related
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?
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)
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". }
}
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
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)").
}