Wikidata:Request a query/Archive/2024/04

From Wikidata
Jump to navigation Jump to search
This page is an archive. Please do not modify it. Use the current page, even to continue an old discussion.

Last names for Norwegians

I got this query from october 2023 https://w.wiki/7Xpu telling me all last names with a number of persons keeping this last name for each last name. Is it possible to have a new query showing the Q-value and an alphabetic list of family name (Q101352) having country (P17) and Norway (Q20). Pmt (talk) 14:59, 31 March 2024 (UTC)

@Pmt: Not very clear to me what you want. That the ?lastname is a Q101352 'family name' and that the 'family name' has P17 Q20? That does not get much.
SELECT ?lastnameLabel ?count with {
  SELECT (COUNT(*) AS ?count) ?lastname WHERE {
    ?person wdt:P27 wd:Q20 . hint:Prior hint:runFirst true.
    ?person wdt:P734 ?lastname . 
    ?lastname wdt:P31 wd:Q101352 . 
    ?lastname  wdt:P17 wd:Q20. 
       
  } GROUP BY ?lastname } as %i
WHERE
{
  INCLUDE %i
  ?lastname rdfs:label ?lastnameLabel. filter(lang(?lastnameLabel)="nn") 
}
ORDER BY DESC(?count)
Try it!
--Tagishsimon (talk) 13:39, 1 April 2024 (UTC)
[User:Tagishsimon|Tagishsimon]]. Sorry for being unclear. What I need is a list for norwegian persons lastname like; Q2712367 Hansen, then Q21501893 Andersen.... and the last one Q122839571 Zakarias as row no. 19974 as shown in https://w.wiki/7Xpu. Hope this is easier explained :) Pmt (talk) 19:33, 1 April 2024 (UTC)
@Pmt: This? The query is getting the P734 ?lastname of anyone who is a P27 citizen of Q20 Norway, and then doing a count ... and now there's a QId column?
SELECT ?lastname ?lastnameLabel ?count with {
  SELECT (COUNT(*) AS ?count) ?lastname WHERE {
    ?person wdt:P27 wd:Q20 . hint:Prior hint:runFirst true.
    ?person wdt:P734 ?lastname . 
  } GROUP BY ?lastname } as %i
WHERE
{
  INCLUDE %i
  ?lastname rdfs:label ?lastnameLabel. filter(lang(?lastnameLabel)="nn") 
}
ORDER BY DESC(?count)
Try it!
--Tagishsimon (talk) 01:21, 2 April 2024 (UTC)

African Cinema Content Lacking Wikipedia Pages in Wen

Hi there! I'd like to have a Sparql query for certain topics such as "Director, Actor, Actress, Cinematographer, Producer, Screenwriter, Sound editor, Animation, Film editor, Costume designer, Makeup artist, Film" of a particular country which does not have an article on English Wikipedia. This is to be used on the AfroCreatives Wikiproject. I will be very grateful to have this query. Thanks! Eugene233 (talk) 04:54, 30 March 2024 (UTC)

@Eugene233: The basic format for such a query is as below: find some items using whatever clause is of interest - e.g. here, occupation = screenwriter, and then check that there is not a sitelink to EN wikipedia using the rubric in the FILTER NOT EXISTS.
The issue you'll quickly run into is lack of time to complete the query. 76k screenwriters are being processed in 30-45 seconds. There are a couple of hundred thousand or more films, so the possibility is that you'd need to run the query with subsets of films, or of people having an occupational characteristic; or else run the queries in Qlever, a 3rd party SPARQL engine which has a wikidata data set - https://qlever.cs.uni-freiburg.de/wikidata/
SELECT ?item ?itemLabel 
WHERE 
{
  ?item wdt:P106 wd:Q28389 . 
  
  filter not exists {?article schema:about ?item ;
  schema:isPartOf <https://en.wikipedia.org/> .}
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }  
}
Try it!
--Tagishsimon (talk) 19:40, 1 April 2024 (UTC)
Much qucker if we look for occupation=screewriter, country of citizenship=Zambia...
SELECT ?item ?itemLabel 
WHERE 
{
  ?item wdt:P106 wd:Q28389 . 
  ?item wdt:P27 wd:Q953.
  
  filter not exists {?article schema:about ?item ;
  schema:isPartOf <https://en.wikipedia.org/> .}
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }  
}
Try it!
and then possibly more useful to list those that do & do not have sitelinks:
SELECT ?item ?itemLabel ?article ?sitelink
WHERE 
{
  ?item wdt:P106 wd:Q28389 . 
  ?item wdt:P27 wd:Q953.
  
  OPTIONAL {?article schema:about ?item ;
  schema:isPartOf <https://en.wikipedia.org/> ;
  schema:name ?sitelink .}
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }  
}
Try it!
--Tagishsimon (talk) 19:46, 1 April 2024 (UTC)
Is it possible to combine with an OR for the different occupation types? Eugene233 (talk) 19:13, 2 April 2024 (UTC)
@Eugene233: Yes; a couple of ways. Clauses in the SPARQL can be UNIONed, so {item wdt:P106 wd:12345.} UNION {item wdt:P106 wd:67890.} style, for as long a chain of unions as you like (always: remembering that eventually you'll probably hit a timeout. A perhaps better way is the VALUES ?variable {} approach, below, where the QIds of interest are listed within a VALUES statement. (the # comments are not necessary, merely useful).
In the example below I've also somewhat gratuitously changed the clause looking at P106 occupation, to return items that have a P31 value of the occupation, or a P31 value which is a subclass of the occuption (so it will get 'actor' but also 'television actor'). And then made various other changes so that we get to know which occupations related to the VALUES list of occupations the person has; and if they have more than one qualifying occupation, we group the labels so that we get ony one row per person. It makes the query more complicated, obviously. There are all sorts of ways of finessing the sort of query you're interested in, depending on exactly what you want.
SELECT ?item ?itemLabel ?article ?sitelink (GROUP_CONCAT(DISTINCT ?occupationLabel_;separator="; ") as ?occupationLabel)
WHERE 
{
  VALUES ?occ {                   # list of occupations
    wd:Q28389   # screenwriter
    wd:Q2526255 # film director
    wd:Q33999   # actor
  }
  
  ?item wdt:P106/wdt:P279* ?occ . # item has this occupation of a subclass thereof
  ?item wdt:P106 ?occupation .    # exactly which occupation does the item have
  ?occupation wdt:P279* ?occ .    # we're only interested in occupations which are related to the above list
  ?item wdt:P27 wd:Q953.          # country of citizenship
  
  OPTIONAL {?article schema:about ?item ;     # do they have an EN wiki article?
  schema:isPartOf <https://en.wikipedia.org/> ;
  schema:name ?sitelink .}
  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". 
                         ?item rdfs:label ?itemLabel .
                         ?occupation rdfs:label ?occupationLabel_ .}  
} GROUP BY ?item ?itemLabel ?article ?sitelink
Try it!
--Tagishsimon (talk) 21:07, 2 April 2024 (UTC)

item missing in query results: why?

Hello. I am just learning SPARQL by examples.

I don't remember where I found the wikibase:mwapi example which I adapted to this query:

https://w.wiki/9dU6


SELECT ?item ?itemLabel WHERE {

?item wdt:P31 wd:Q5 ; wdt:P106 wd:Q2374149 . # people which work as botanists

SERVICE wikibase:mwapi {

  bd:serviceParam wikibase:api "EntitySearch" .

  bd:serviceParam wikibase:endpoint "www.wikidata.org" .

  bd:serviceParam mwapi:search "Ortiz" .

  bd:serviceParam mwapi:language "en" .

  ?item wikibase:apiOutputItem mwapi:item .

}

SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }

} ORDER BY ASC(?itemLabel) LIMIT 50


OK, that returns several items (people which work as "botanist" and contain "Ortiz" in description).

But there are only 4 items returned when the limit is 50.

So, why doesn't it return this item?

http://www.wikidata.org/entity/Q16301809


As far as I can tell, it meets all requested conditions.


Side question: how can I make the above query be color-highlighted? (like other queries in this site)

Thanks a lot in advance for any help you can provide.


SANTherbarium (talk) 13:10, 1 April 2024 (UTC)

@SANTherbarium:
I think what's going on here is that the MWAPI "EntitySearch" searches items based on the full title of the item, so this works (although that is a poor explantion: why did your query come up with the 4 items it found? IDK.):
SELECT ?item ?itemLabel WHERE {
		?item wdt:P31 wd:Q5 ; wdt:P106 wd:Q2374149 . # people ; working as botanist 
		#?item  wdt:P21 wd:Q6581072 # female
		#?item  wdt:P21 wd:Q6581097 # male
		SERVICE wikibase:mwapi {
		  bd:serviceParam wikibase:api "EntitySearch" .
		  bd:serviceParam wikibase:endpoint "www.wikidata.org" .
		  bd:serviceParam mwapi:search "Santiago Ortiz Nuñez" .
		  bd:serviceParam mwapi:language "en" .
		  ?item wikibase:apiOutputItem mwapi:item .
		}
		SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
	} ORDER BY ASC(?itemLabel) LIMIT 50
Try it!
Meanwhile what you need for a free text search is the api "Search":
SELECT ?item ?itemLabel WHERE {
		hint:Query hint:optimizer "None".
		#?item  wdt:P21 wd:Q6581072 # female
		#?item  wdt:P21 wd:Q6581097 # male
		SERVICE wikibase:mwapi {
		  bd:serviceParam wikibase:api "Search" .
		  bd:serviceParam wikibase:endpoint "www.wikidata.org" .
		  bd:serviceParam mwapi:srsearch "Ortiz" .
          ?item wikibase:apiOutputItem mwapi:title .
		}
      ?item wdt:P31 wd:Q5 ; wdt:P106 wd:Q2374149 . # people ; working as botanist 
		SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
	} ORDER BY ASC(?itemLabel)
Try it!
THere are some details here: https://www.mediawiki.org/wiki/Wikidata_Query_Service/User_Manual/MWAPI#Supported_services --Tagishsimon (talk) 13:23, 1 April 2024 (UTC)
@Tagishsimon Thanks so much for the alternative api "Search".
Although it is much much slower. Any way to speed it up?
Regarding the much faster "EntitySearch", IMHO it is not doing a simple "full title matching" search.
I tried different family names (i.e. "Rivas") and it again returns several results which are contained in a longer title string.
Can anyone explain why?
I'd also like to know why my SPARQL code is not colour-highlighted like others I can see in this page.
(which also show a "Try it!" link below them)
Thank you very much.
_________ SANTherbarium (talk) 15:36, 1 April 2024 (UTC)
You need to wrap your code in a SPARQL template ... have a close look at the source / edit screen for this thread. The question about what EntitySearch actually does is interesting. Sadly the documentation I've found is mostly useless, so it's a mystery to me. (And no, no way to speed the 'Search' MWAPI.) --Tagishsimon (talk) 18:22, 1 April 2024 (UTC)
@SANTherbarium: I hazard a guess that EntitySearch will find items where either of the Label or the Alias string starts with Ortiz. --Tagishsimon (talk) 19:25, 1 April 2024 (UTC)
@SANTherbarium take a look here for syntax highlighting:
https://m.wikidata.org/wiki/Template:SPARQL 46.6.168.115 23:44, 1 April 2024 (UTC)
Hello,
@Tagishsimon's query returns 25 items, including Andres Ernesto Ortíz-Rodríguez.
I tried to do what @SANTherbarium was initially trying to do by writing this query: https://w.wiki/9dsz , which returns one fewer item (the missing item is Andres Ernesto Ortíz-Rodríguez).
This is because "Ortiz" and "Ortíz" are different.
This modified query looks for both "Ortiz" and "Ortíz": https://w.wiki/9dt7
The lesson here seems to be that bd:serviceParam mwapi:srsearch "Ortiz" . looks for both regular and i-acute i's, whereas the CONTAINS function is more restrictive. Vincent Tep (talk) 08:18, 2 April 2024 (UTC)
That works @Vincent Tep ... thanks for explaining those new techniques.
Thank you all for your helpful suggestions. Question: do w.wiki query links ever expire or are they permanent?
(so I don't need to save those queries and can always come back here to see the examples)
·
I think @Tagishsimon guess was correct and all returned items in my orginal query did contain aliases beginning with my EntitySearch string value ... whereas the item I was missing did contain the string in alias, but not at its begin.
·
Final question about EntitySearch: is it the same kind of query running when we type text in wikidata top right search box?
If it's not, then I'd like to see an example of SPARQL query equivalent to that one (same speed with same limitations: only a known text string, no properties, no filters).
·
Thanks a lot!! SANTherbarium (talk) 09:23, 2 April 2024 (UTC)
Hi, I need a query on LEXEMES files I can improve on Obedmakolo (talk) 10:03, 2 April 2024 (UTC)
do w.wiki query links ever expire or are they permanent? => they seem to be permanent, I've just gone through the archives and found one such link from 04/20 that still leads to a query.
Final question about EntitySearch: is it the same kind of query running when we type text in wikidata top right search box? => no idea. Vincent Tep (talk) 13:31, 2 April 2024 (UTC)
It's possible to speed up the query: https://w.wiki/9e8X . This first searches for botanists where there is a fulltext match for "Ortiz", then removes any matches where the english label doesn't contain "Ortiz". Infrastruktur (talk) 16:33, 2 April 2024 (UTC)
Thanks a lot @Infrastruktur
That's an amazing speed difference when using full words search!
Although for catching any kind of substrings @Vincent Tep's query is the only which works.
(i.e. you can put just part of a name i.e. "Orti" or "rti" and it still finds names like "Ortiz"). SANTherbarium (talk) 00:40, 3 April 2024 (UTC)
Yeah, it seems to search for whole words as you've pointed out. You can use "Orti*" to have it search for words starting with "Orti" and you can use "Ortiz~" to search for words that are just similar but not exact matches. What the search engine does not support is searching for words where the first letter is unknown, or at least I couldn't find that in the document when I was looking. More information at mw:Help:CirrusSearch. Remember to change the filter line in the query or it will remove any non-exact matches. Infrastruktur (talk) 12:00, 3 April 2024 (UTC)

Map of all places related to persons with layers by property of the place

I tried to get a map like Birth places of German poets combined with other places like place of death (P20), residence (P551), work location (P937) as separate layers. I was able to bring all this places on the map, but I didn't figure out how to divide them into separate layers with different colours.

#defaultView:Map{"hide": ["?coord"]}
SELECT DISTINCT ?subj ?subjLabel ?dob ?birthPlace ?birthPlaceLabel ?dod ?deathPlace ?deathPlaceLabel ?coord WHERE {
  ?subj ((wdt:P19|wdt:P20|wdt:P551|wdt:P1321|wdt:P937)/(wdt:P131*)) wd:Q11943.
  OPTIONAL {
    ?subj wdt:P19 ?birthPlace.
    ?birthPlace wdt:P625 ?coord.
  }
  OPTIONAL {
    ?subj wdt:P20 ?deathPlace.
    ?deathPlace wdt:P625 ?coord.
  }
  OPTIONAL { ?subj wdt:P569 ?dob. }
  OPTIONAL { ?subj wdt:P570 ?dod. }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
Try it!

Any help is appreciated! Rerumscriptor (talk) 12:58, 5 April 2024 (UTC)

Property paths can be nice to express something in a more terse way, but sometimes you just have to write the query out in a more basic form, e.g.:
SELECT DISTINCT ?subj ?subjLabel ?dob ?dod ?place ?placeLabel ?layer ?coord
WITH {
  SELECT DISTINCT ?place ?coord WHERE {
    ?place wdt:P131* wd:Q11943 .
    ?place wdt:P625 ?coord .
  }
} as %place # re-use results
WHERE {
  {
    INCLUDE %place
    ?subj wdt:P19 ?place .
    bind("birth place" as ?layer)
    OPTIONAL { ?subj wdt:P569 ?dob. filter(!wikibase:isSomeValue(?dob)) }
  } UNION {
    INCLUDE %place
    ?subj wdt:P20 ?place.
    bind("death place" as ?layer)
    OPTIONAL { ?subj wdt:P570 ?dod. filter(!wikibase:isSomeValue(?dod))  }
  } UNION {
    INCLUDE %place
    ?subj wdt:P551 ?place.
    bind("residence" as ?layer)
  } UNION {
    INCLUDE %place
    ?subj wdt:P1321 ?place.
    bind("place of origin" as ?layer)
  } UNION {
    INCLUDE %place
    ?subj wdt:P937 ?place.
    bind("work location" as ?layer)
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
Try it!
Infrastruktur (talk) 14:39, 5 April 2024 (UTC)
Thank you, @Infrastruktur, that helped me a lot! I adjusted it a bit, so the map shows places related to people related to Canton of Zürich (Q11943). My result is now:
#defaultView:Map{"hide": ["?coord"]}
SELECT DISTINCT ?subj ?subjLabel ?place ?placeLabel ?layer ?coord 
WITH {
  SELECT DISTINCT ?subj WHERE {
  ?subj ((wdt:P19|wdt:P551|wdt:P20|wdt:P1321|wdt:P937)/(wdt:P131*)) wd:Q11943.
  }
} as %person # re-use results
WHERE {
  {
    INCLUDE %person
    ?subj  wdt:P19 ?place.
    ?place wdt:P625 ?coord.
    BIND("Geburtsort" AS ?layer)
  } UNION {
    INCLUDE %person
    ?subj wdt:P20 ?place.
    ?place wdt:P625 ?coord.
    BIND("Sterbeort" AS ?layer)
  } UNION {
    INCLUDE %person
    ?subj wdt:P551 ?place.
    ?place wdt:P625 ?coord.
    BIND("Wohnsitz" AS ?layer)
  } UNION {
    INCLUDE %person
    ?subj wdt:P937 ?place.
    ?place wdt:P625 ?coord.
    BIND("Wirkungsort" AS ?layer)
  } UNION {
    INCLUDE %person
    ?subj wdt:P1321 ?place.
    ?place wdt:P625 ?coord.
    BIND("Bürgerort" AS ?layer)
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
Try it!
Rerumscriptor (talk) 13:27, 6 April 2024 (UTC)

Distance query not finding itself

Can anyone explain why this query returns itself for Dover Castle, but not for Hack Green bunker, when both have coordinate location (P625) the same? I'm completely baffled.

SELECT DISTINCT ?item ?itemLabel WHERE {
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en-GB,en,fr,de,es,pt,pl,nl,cs". }
  {
    SELECT DISTINCT ?item
                          WHERE {
#      hint:Query hint:optimizer "None"
wd:Q5637175 wdt:P625 ?targetLoc. # hack green bunker
#wd:Q950970 wdt:P625 ?targetLoc. # dover castle
SERVICE wikibase:around{
  ?item wdt:P625 ?location.
  bd:serviceParam wikibase:center ?targetLoc.
  bd:serviceParam wikibase:radius "0.1".
  bd:serviceParam wikibase:distance ?dist.
}
}
}
}
Try it!

Vicarage (talk) 16:13, 6 April 2024 (UTC)

@Vicarage: Makes no sense to me. Increasing the radius to 0.4km, the Hack Green query finds Hack House Farmhouse (Q62130029) ... putting that as ?targetLoc finds Hack Green Bunker, so we know its data is in the triplestore ... and finds itself, so we know wikibase:around finds items that have the coord of the wikibase:center (and the Dover Castle query showed us that). --Tagishsimon (talk) 19:54, 6 April 2024 (UTC)
The guy who wrote the code for that service left the WMF in 2019. You can try asking on Wikidata:Report_a_technical_problem if someone can write a Phabricator bugreport for you. Include the information you provided here. It this bug has existed for 8 years without anyone finding it, it must be something rare, so good thing it can be reproduced. Infrastruktur (talk) 21:39, 6 April 2024 (UTC)
I've done that: https://www.wikidata.org/wiki/Wikidata:Report_a_technical_problem#WDQS_wikibase:around_issue --Tagishsimon (talk) 21:52, 6 April 2024 (UTC)

Film directors

Could someone make a query of Norwegian film directors who died in 1953 or before? Trade (talk) 07:11, 7 April 2024 (UTC)

@Trade:
SELECT ?item ?itemLabel (YEAR(?dod) as ?year) WHERE 
{ 
  ?item wdt:P106 wd:Q2526255 .
  ?item wdt:P27 wd:Q20 . 
  ?item wdt:P570 ?dod . hint:Prior hint:rangeSafe true.
  FILTER("1953-12-31"^^xsd:dateTime >= ?dod) 
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],nn,en". } 
}
Try it!
--Tagishsimon (talk) 12:44, 7 April 2024 (UTC)

Extract qualifiers not working for me :(

I saw the following SPARQL query successfully requesting Publication date (P577) qualifiers (WDQS) :

SELECT ?title ?item ?date ?place ?placeLabel WHERE {
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
  ?item wdt:P161 wd:Q38111.
  ?item wdt:P1476 ?title.
  # Get qualifiers
  ?item p:P577 ?statement. 
  ?statement ps:P577 ?date. 
  ?statement pq:P291 ?place.
}
Try it!

I replicated this exact (?) grammar to request Pronunciation (P:P443) qualifiers, but the following fails (WDQS) so I keep it in an OPTIONAL block :

SELECT ?id ?idLabel ?audio ?audioLabel ?audioFile ?audioLangLabel ?speakerLabel
WHERE {
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
  ?id wdt:P443 ?audio.
  FILTER(CONTAINS(STR(?audio), "LL-Q117707514")) # occitan whistled -Q117707514
  # ?id wdt:P625 ?coord . # geocoordinates
  OPTIONAL {  
    ?id p:P443 ?audioStatement .
    ?audioStatement ps:P443 ?audioFile.
    ?audioStatement pq:P407 ?audioLang.
    ?audioStatement pq:P10894 ?speaker.
    }
}
Try it!

Exemple of item with that exact data I look for : Laruns (Q374876#P443 with qualifiers P:P407 = Occitan sifflé d'Aas (Q117707514) and P:P10894 = Philippe Biu (Q120142380) )

Any clue ? Yug (talk) 08:39, 8 April 2024 (UTC)

User:VIGNERON pointed out a typo p:443 -> p:P443. So I fixed it above. Thank you VIGNERON for your eagle eyes ! Yug (talk) 08:52, 8 April 2024 (UTC)
Alternative syntaxe :
SELECT ?id ?idLabel ?audioFile ?audioLangLabel ?speakerLabel
WHERE {
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
  ?id p:P443 ?audioStatement .
  ?audioStatement ps:P443 ?audioFile.
  FILTER(CONTAINS(STR(?audioFile), "LL-Q117707514")) # occitan whistled -Q117707514
  # ?id wdt:P625 ?coord . # geocoordinates
  ?audioStatement pq:P407 ?audioLang.
  ?audioStatement pq:P10894 ?speaker.
}
Try it!
Credit: VIGNERON. Yug (talk) 09:04, 8 April 2024 (UTC)

African Women

I want to kindly request query for list of items under this categories; women in Africa, Maternal health in Africa, women’s marches in Africa, African women in business, International Women’s Day in Africa around the world, women’s rights in Africa, and feminism in Africa. Thanks Bukky658 (talk) 12:17, 8 April 2024 (UTC)

@Bukky658: This is not a very good specification. It is unlikely to be answered. At one end, women in Africa -> probably a vast number of. At the other end, women’s rights in Africa, and feminism in Africa -> would need to know what sort of thinsg you actually mean. On this desk, you need to be fairly precise about your ask. Broad waving of arms does not cut it. --Tagishsimon (talk) 15:17, 9 April 2024 (UTC)
Pardon my broad ask, Specifically I would like to get items for each of the category for Women in Tanzania, Nigeria, & Ghana. I see that this categoies exist on Wikipedia and was wondering if I could get a query result for items in this categories with primary focus on the 3 mentioned countries. Bukky658 (talk) 15:24, 9 April 2024 (UTC)

Islands of the Baltic Sea

Hi. I kindly request a query about islands of the Baltic Sea, with a minimal area of 10 square kilometers, with an article at enwiki and no article at hewiki. Thanks. YoavR (talk) 13:41, 9 April 2024 (UTC)

@YoavR:
SELECT ?item ?itemLabel ?area ?unitLabel ?coord ?article WHERE {
  ?item wdt:P31 wd:Q23442 .                       # island
  ?item wdt:P206 wd:Q545 .                        # in Baltic Sea
  ?item p:P2046 ?stat .                           # area statement
  ?stat psn:P2046/wikibase:quantityAmount ?area . # normalised area
  ?stat psn:P2046/wikibase:quantityUnit ?unit .   # unit
  filter(?area >= 10000000)                       # more than or equal to 10 sq kmm
  OPTIONAL {?item wdt:P625 ?coord . }             # coordinate
  
  ?article schema:about ?item ;                   # article at EN wiki
           schema:isPartOf <https://en.wikipedia.org/> .
           
  filter not exists {?article1 schema:about ?item ; 
  schema:isPartOf <https://he.wikipedia.org/> .}  # no article at HE wiki

  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } 
}
Try it!
--Tagishsimon (talk) 15:12, 9 April 2024 (UTC)
@YoavR: But, if You want some more, try including parts of Baltic sea :) (/wdt:P361*)
SELECT * {
  {
    SELECT DISTINCT * {
      ?item wdt:P31 wd:Q23442;
            wdt:P206/wdt:P361* wd:Q545;
            wdt:P2046 ?area.
      FILTER(?area > 10)
      ?en_sitelink schema:about ?item ;
                schema:isPartOf <https://en.wikipedia.org/> .
      MINUS {?he_sitelink schema:about ?item ;
                             schema:isPartOf <https://he.wikipedia.org/> .}
    }
  }
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
    ?item rdfs:label ?label . ?item schema:description ?description
  }
}
ORDER BY DESC(?area)
Try it!
, regards Piastu (talk) 15:26, 9 April 2024 (UTC)

largest lakes no enwiki

Am I able to get the lakes with the largest surface area but have no enwiki sitelink 115.188.127.196 06:02, 10 April 2024 (UTC)

Hello,
Here is my attempt at writing your query: https://w.wiki/9kpa
It works but times out unless LIMIT 10 is set. Can anyone more knowledgeable take a look at it and suggest improvements? Thanks! Vincent Tep (talk) 19:49, 14 April 2024 (UTC)
As explained here, turning off this single line of code: SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } prevents the query from timing out. It returns 54,443 hits. Vincent Tep (talk) 19:57, 14 April 2024 (UTC)
Time is running out huh? Didn't the english band Muse write a song about that? :-) filter (not) exists can be slow some times - https://w.wiki/9kqs . Infrastruktur (talk) 21:23, 14 April 2024 (UTC)

Cross two variables in a table

Hi! This query

#title:Byzantinists by citizenship and gender
SELECT ?nLabel ?gLabel (COUNT(?item) AS ?number)
WHERE {
  ?item wdt:P106 wd:Q26132815 ; wdt:P27 ?n ; wdt:P21 ?g .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE]". }
}
GROUP BY ?nLabel ?gLabel
ORDER BY ?nLabel
Byzantinists by citizenship and gender

as of now gives in column 3 (?number) che counts of items combining the conditions in columns 1 (?nLabel) and 2 (?gLabel); in order to compact the view of the table, would it be possible to convert the values of column 2 (?gLabel) into headers of column, so as to have basically the various countries as the values of column 1, the values of sex or gender (P21) as headers of columns and all the numbers in the other cells? I.e. something like

- female (Q6581072) male (Q6581097)
Italy (Q38) 24 54
Greece (Q41) 14 58

Thanks in advance, --Epìdosis 13:23, 14 April 2024 (UTC)

I don't know if you're interested in queries, but I made several solutions just for fun.
1. Conditional counting.
#title:Byzantinists by citizenship and gender
SELECT ?nLabel (SUM(?male_) AS ?male) (SUM(?female_) AS ?female) (SUM(?other_) AS ?other) 
WHERE {
  ?item wdt:P106 wd:Q26132815 ; wdt:P27 ?n ; wdt:P21 ?g .
  bind (IF(?g = wd:Q6581097, 1, 0) as ?male_)
  bind (IF(?g = wd:Q6581072, 1, 0) as ?female_)
  bind (IF(?g not in (wd:Q6581097, wd:Q6581072), 1, 0) as ?other_)
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE]". }
}
GROUP BY ?nLabel
ORDER BY ?nLabel
Byzantinists by citizenship and gender
2. Split into mutually exclusive subsets.
#title:Byzantinists by citizenship and gender
SELECT ?nLabel (COUNT(?male_) AS ?male) (COUNT(?female_) AS ?female) (COUNT(?other_) AS ?other) 
WHERE {
  {
    ?item wdt:P106 wd:Q26132815 ; wdt:P27 ?n .
    ?item wdt:P21 wd:Q6581097 .
    bind ("m" as ?male_)
  } UNION {
    ?item wdt:P106 wd:Q26132815 ; wdt:P27 ?n .
    ?item wdt:P21 wd:Q6581072 .
    bind ("f" as ?female_)
  } UNION {
    ?item wdt:P106 wd:Q26132815 ; wdt:P27 ?n .
    ?item wdt:P21 ?g . filter (?g not in (wd:Q6581097, wd:Q6581072))
    bind ("o" as ?other_)
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE]". }
}
GROUP BY ?nLabel
ORDER BY ?nLabel
Byzantinists by citizenship and gender
3. Conditional binding.
#title:Byzantinists by citizenship and gender
SELECT ?nLabel (COUNT(?male_) AS ?male) (COUNT(?female_) AS ?female) (COUNT(?other_) AS ?other) 
WHERE {
  ?item wdt:P106 wd:Q26132815 ; wdt:P27 ?n ; wdt:P21 ?g .
  bind (coalesce(IF(?g = wd:Q6581097, 1, 1/0)) as ?male_)
  bind (coalesce(IF(?g = wd:Q6581072, 1, 1/0)) as ?female_)
  bind (coalesce(IF(?g not in (wd:Q6581097, wd:Q6581072), 1, 1/0)) as ?other_)
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE]". }
}
GROUP BY ?nLabel
ORDER BY ?nLabel
Byzantinists by citizenship and gender
Infrastruktur (talk) 17:58, 14 April 2024 (UTC)

How to list authors from 'Has Parts' of a legal decision?

Hello! There are many wikidata entries for Supreme Court decisions (from the US and Sweden, to name two) and I would like to do the same for Canada. It appears that the existing practice is to represent a 'Majority Opinion' from a 'Dissenting Opinion' by using the 'Has Parts' property. (see example: Q125349256)

I am trying to generate a query that will extract the author of a legal opinion from Has Parts but I am stuck. https://w.wiki/9jsP

I believe that one way I can collect this information is using PS or PQ to get the qualifiers from Has Parts, but I've been unable to formulate anything that works. Any hints or help is appreciated! Copystar (talk) 17:13, 12 April 2024 (UTC)

Does this work or do you need it tweaked?
SELECT ?item  ?itemLabel ?date ?qqLabel ?v ?vLabel
WHERE {
  ?item wdt:P31 wd:Q19930933. 
  ?item wdt:P577 ?date. FILTER(?date >= "2024-01-01"^^xsd:dateTime) 
  ?item p:P527 ?hp.    
  ?hp a wikibase:BestRank .
  ?hp ?q ?v . filter (?q in (pq:P50, pq:P7122))
  ?qq wikibase:qualifier ?q .

  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ORDER BY ASC(?date)
Try it!
Infrastruktur (talk) 20:43, 15 April 2024 (UTC)
This is wonderful - thank you so much for helping get past this roadblock! It does need some tweaking however.
Is it possible to extract the parent values of 'Parts of / P27' (Majority Opinion of) and (Dissenting Opinion of) so that the child values of 'author and name' have the necessary context?
The ideal end result would express (as in this example Q125275161) that the parent of Majority Opinion, had a child of Author "Andromache Karakatsanis", and three other people in that category of the 'opinion joined by.' At the moment, the results make it unable to determine if an opinion joined by is for the majority opinion or a dissenting opinion.
In Wikipedia, there have been several attempts to keep track of this information manually in table format https://en.wikipedia.org/wiki/2022_reasons_of_the_Supreme_Court_of_Canada
My hope is to make a query-based simplified version of this Wikipedia table that can be dynamically updated. Again, thank you @Infrastrukturso much for helping with this! Copystar (talk) 11:32, 16 April 2024 (UTC)
Second version: https://w.wiki/9n5T . Clicking on the claim links will take you directly to the claims, which is useful if the item is large. Infrastruktur (talk) 21:27, 16 April 2024 (UTC)
This is marvelous! Thank you so much for your help with this. This fits the bill! All the best! Copystar (talk) 01:24, 17 April 2024 (UTC)

results where items are Q items

I'm working with the following query to find items related. How can I change it to only return rows with a Q item? Also, I'd like to filter out "described by source" type relations as well as negative ones like "opposite of." Thanks, Marc Mason

SELECT ?wdLabel ?ps_Label ?ps_ ?ps {
  VALUES (?item) {(wd:Q197)}
  ?item ?p ?statement .
  ?statement ?ps ?ps_ .
  ?wd wikibase:claim ?p.
  ?wd wikibase:statementProperty ?ps.
  OPTIONAL {   ?statement ?pq ?pq_ .   ?wdpq wikibase:qualifier ?pq .   }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" } } 
ORDER BY ?wd ?statement ?ps_
Try it!

173.69.181.96 16:48, 15 April 2024 (UTC)

Something like that ?
SELECT ?wdLabel ?ps_Label ?ps_ ?ps {
  VALUES (?item) {(wd:Q197)}
  ?item ?p ?statement .
  ?statement ?ps ?ps_ .
  ?wd wikibase:claim ?p;
      wikibase:statementProperty ?ps;
      wikibase:propertyType wikibase:WikibaseItem .
  
  OPTIONAL {   ?statement ?pq ?pq_ .   ?wdpq wikibase:qualifier ?pq .   }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" } } 
ORDER BY ?wd ?statement ?ps_
Try it!
(I just used wikibase:propertyType which has the datatype of the property as value, here we want item datatype, wikibase:WikibaseItem author  TomT0m / talk page 10:56, 16 April 2024 (UTC)

checking whether a first name is male of female

I wanna check whether a given name is male or female (or both) in my pywikibot-script. My first idea was to import all the male names / female names into my script once and check then against these data. But the simple query:

#title:get all male given names
SELECT ?item ?itemLabel
WHERE {
  ?item wdt:P31 wd:Q12308941.
  SERVICE wikibase:label { bd:serviceParam wikibase:language 'de' }
}
get all male given names

runs into timeout. I can limit the number of items returned, but then how to get all names? As an alternative I could try to query for a specific name:

#title:get a specific male given name
SELECT ?item ?itemLabel
WHERE {
  ?item wdt:P31 wd:Q12308941.
  ?item rdfs:label ?itemLabel .
   FILTER (LANG(?itemLabel) = "de"). 
   FILTER (?itemLabel = "Franz").
}
get a specific male given name

which also runs into timeout.

Acc. to https://stackoverflow.com/questions/38527828/how-to-query-wikidata-items-using-its-labels I tried:

SELECT DISTINCT ?item ?label
WHERE
{
  SERVICE wikibase:mwapi
  {
    bd:serviceParam wikibase:endpoint "www.wikidata.org";
                    wikibase:api "Generator";
                    mwapi:generator "search";
                    mwapi:gsrsearch "inlabel:Franz"@de;
                    mwapi:gsrlimit "max".
    ?item wikibase:apiOutputItem mwapi:title.
  }
  ?item rdfs:label ?label. FILTER( LANG(?label)="de" )

  # … at this point, you have matching ?item(s) 
  # and can further restrict or use them
  # as in any other SPARQL query

  # Example: the following restricts the matches
  # to college towns (Q1187811) only

  ?item wdt:P31 wd:Q12308941 .
  }
Try it!

which gives me a list of names similar to the given name "Franz". I could work with this for the price of having to query each given name separately., e.g. accessing only items with label="Franz" or getting all in one query?

Is there any smarter solution? best --Herzi Pinki (talk) 20:58, 14 April 2024 (UTC)

Hello @Herzi Pinki,
Your first query doesn't time out if you turn off the label service. In order to get the labels, you can wrap your query in a WITH clause, and then use the label service in the main part of your query, like this. This query returns 48,861 hits in about 40 seconds.
What I cannot explain though is that this only works if the label service line is wrapped in an OPTIONAL clause, otherwise this approach fails too. Vincent Tep (talk) 19:42, 16 April 2024 (UTC)
@Vincent Tep: a lot of not straightforward tricks. and it still times out for me. :-( thanks anyhow --Herzi Pinki (talk) 22:36, 16 April 2024 (UTC)
I tried it multiple times and it timed out once too. I suggest you try again. If it doesn't work I can send you a .csv of the results. Vincent Tep (talk) 06:41, 17 April 2024 (UTC)
I want to embed the query in a script to check gender against names, so a static .csv will not really help. best --Herzi Pinki (talk) 09:51, 17 April 2024 (UTC)
your initial query works fine when you disable the label service. Maybe you can do this (retrieve only item IDs), and then make a separate call/query to get their labels? Vincent Tep (talk) 12:01, 17 April 2024 (UTC)
splendid idea:
SELECT ?item ?itemLabel
WHERE {
  ?item rdfs:label ?itemLabel .
   FILTER (LANG(?itemLabel) = "de"). 
VALUES ?item {

wd:Q741
wd:Q923
wd:Q1557
wd:Q4642
wd:Q20164
wd:Q20790
wd:Q24223
wd:Q29884
wd:Q37080
wd:Q42771
}.
  SERVICE wikibase:label { bd:serviceParam wikibase:language 'de' }
}
Try it!
I cannot paste the full query here, as urls get too long. But it seems to work in 1000 junks, or even in 10000 junks Query for first 1000. thanks a lot, --Herzi Pinki (talk) 13:48, 17 April 2024 (UTC)
@Herzi Pinki: In one query :
#title:get all male given names
SELECT ?item ?itemLabel
WHERE {
  {
      select * {
          ?item wdt:P31 wd:Q12308941.
      }
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language 'de' }
}
get all male given names
it works. The trick is to wrap the item retrieval into a subquery and call the query service outside. author  TomT0m / talk page 14:26, 17 April 2024 (UTC)
even better. there is some room above for more names to search for (estimated another +20% before the query breaks). thanks a lot --Herzi Pinki (talk) 15:04, 17 April 2024 (UTC)
Thanks @TomT0m, I had the same idea (pilfered from the Query Optimization page), but I wrapped my query in a WITH clause, whereas you didn't. Yours is shorter to write, more straightforward, runs twice as fast and seems to returns 4 more hits. Thank you! Vincent Tep (talk) 19:19, 17 April 2024 (UTC)
I think that this discussion is resolved and can be archived. If you disagree, don't hesitate to replace this template with your comment. Herzi Pinki (talk) 15:11, 17 April 2024 (UTC)

conncetions between basketball and hiphop

hi, I would like a query in which are explicated the possible connection between basketball and hiphop 87.0.83.82 14:20, 17 April 2024 (UTC)

One and only one external identifier

Hi !

Is it possible to create a query where I can get the items with one and only one, specific or not, external identifier ? As an example, Sam James Harper (Q98442698) only have one external identifier (INSPIRE-HEP author ID (P2930)). How can I got all the items with ONLY this external identifier and no other external identifiers ? How can I got all the items who have only a specific number of external identifiers values ?

Thank you ! Simon Villeneuve (talk) 11:06, 14 April 2024 (UTC)

I think this should work:
SELECT ?item ?itemLabel ?id WHERE {
  ?item wikibase:identifiers 1 .
  ?item wdt:P2930 ?id
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
Try it!

I found wikibase:identifiers by running

DESCRIBE wd:Q98442698
Try it!

Piecesofuk (talk) 15:24, 14 April 2024 (UTC)

Thank you for the reply and the additional information. It will be very helpful to me! Simon Villeneuve (talk) 17:08, 14 April 2024 (UTC)
I think that this discussion is resolved and can be archived. If you disagree, don't hesitate to replace this template with your comment. author  TomT0m / talk page 17:53, 21 April 2024 (UTC)

Number of items before a specific date

Kindly requesting the number/count of people with occupation (P106) = librarian (Q182436) worldwide added to Wikidata before 1st Feb 2024.

And, the number of people added with the same criteria above after 1st Feb 2024. Wallacegromit1 (talk) 19:46, 14 April 2024 (UTC)

Search gives 20713 librarians in total [1]. Ordering by creation date and counting manually there seem to have been added 158 since 1. February 2024, which means 20555 was added before that date. The dates listed are modification dates btw. The creation date can be found in page information. Infrastruktur (talk) 22:17, 14 April 2024 (UTC)
@Infrastruktur
Thank You So Much, this was really helpful. ✓ Done Wallacegromit1 (talk) 04:42, 15 April 2024 (UTC)
I think that this discussion is resolved and can be archived. If you disagree, don't hesitate to replace this template with your comment. author  TomT0m / talk page 17:52, 21 April 2024 (UTC)

Concat the URL with a name and not with all URL

I think that this discussion is resolved and can be archived. If you disagree, don't hesitate to replace this template with your comment. author  TomT0m / talk page 17:50, 21 April 2024 (UTC)

Hi! I've created this query that works perfectly. The only thing is that I would like the URL to appear under a title "This is a link" instead of the whole URL. I am using the code CONCAT but it doesn't work. Thanks! Leire

#defaultView:Map
#Fimmakers
SELECT DISTINCT ?filmmaker ?filmmakerLabel ?lugar ?coord ?birthdate ?year (CONCAT("[[", ?TabakaleraURL, "|This is a link]]") AS ?TabakaleraURL)
 
WHERE
{
       ?filmmaker wdt:P31 wd:Q5 .
       ?filmmaker wdt:P106 wd:Q2526255 . #zinemagilea
    ?filmmaker wdt:P19 ?lugar. 
  ?filmmaker wdt:P1344 wd:Q9081343.
  ?lugar wdt:P625 ?coord.
  
  ?filmmaker  wdt:P10069  ?tabakalera.
  OPTIONAL{?filmmaker wdt:P569 ?birthdate .} # P569 : Date de naissance
   BIND(year(?birthdate) as ?year)
  FILTER(?year > 1800)
  wd:P10069 wdt:P1630 ?formatterurl .
 BIND(IRI(REPLACE(?tabakalera, '^(.+)$', ?formatterurl)) AS ?TabakaleraURL).
 
 

       SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
 
}
Try it!

Lmerice (talk) 17:53, 18 April 2024 (UTC)

@Lmerice: From a discussion on phabricator I learned that in any view different of the table view, if there is a variable ?var and a variable ?varLabel (var suffixed by Label), the "?varLabel" is used for the label of the links. So here is the query, just rewrote a bit but the only real change is the introduction of ("this is a link " as ?TabakaleraURLLabel) in the "select" clause :
#defaultView:Map
#Fimmakers
SELECT DISTINCT ?filmmaker ?filmmakerLabel ?lugar ?coord ?birthdate ?year ?TabakaleraURL ("this is a link " as ?TabakaleraURLLabel)
 
WHERE
{
  ?filmmaker wdt:P31 wd:Q5 ;
             wdt:P106 wd:Q2526255 ; #zinemagilea
             wdt:P19 ?lugar ;
             wdt:P1344 wd:Q9081343.
  ?lugar wdt:P625 ?coord.
 
  
  OPTIONAL{ ?filmmaker wdt:P569 ?birthdate . } # P569 : Date de naissance
  BIND(year(?birthdate) as ?year)
  FILTER(?year > 1800)
  
  ?filmmaker  wdt:P10069  ?tabakalera.
  wd:P10069 wdt:P1630 ?formatterurl .
  BIND(IRI(REPLACE(?tabakalera, '^(.+)$', ?formatterurl)) AS ?TabakaleraURL).

  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
 
}
Try it!
author  TomT0m / talk page 09:35, 19 April 2024 (UTC)
That was just what I needed. Thanks! Lmerice (talk) 16:36, 21 April 2024 (UTC)

Query using all subproperties of parent (P8810)

Can I query for all parents of people living in a city like University of Oxford (Q34433) by using parent (P8810) in my query and get the information via subproperty of (P1647) without using child (P40), mother (P25), or father (P22) directly? ChristianKl21:47, 18 April 2024 (UTC)

@ChristianKl:_Yes but not simple, plus there are no person living in Oxford University right now on Wikidata so I tried with another city insteaD :
select distinct ?personne ?personneLabel ?parent ?parentLabel {
  ?personne ?parent_prop_c ?parent .                 # get the data with subproperties, the actual predicate is a variable ?parent_prop_c
  
  ?parent_prop wdt:P1647* wd:P8810 .                 # subproperties of "parent" entities 
  ?parent_prop wikibase:directClaim ?parent_prop_c . # main value "direct claim" predicate for those entities in ?parent_prop_c
  
  ?personne wdt:P551 wd:Q12191 . hint:Prior hint:runFirst true . #get the persons who lives in the place (directly, not the places located in it)
  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  
}
Try it!
author  TomT0m / talk page 09:13, 19 April 2024 (UTC)
Oh, and I forgot, it does not get simpler if you want to get say, the grandfathers, as you can't use propertypaths with variables. Getting grandfathers or, say, all male ascendants can be done in two lines if you don't use subproperties in SPARQL :
This get significantly harder or even impossible with the subproperties. author  TomT0m / talk page 18:29, 21 April 2024 (UTC)

Two or more statements on a certain property

I think that this discussion is resolved and can be archived. If you disagree, don't hesitate to replace this template with your comment. author  TomT0m / talk page 17:51, 21 April 2024 (UTC)

How to request a list of all elements where there are two or more statements on a certain property (without deprecated statements)? For example, list of all elements where more than one Great Chinese Encyclopedia code or Den Store Danske ID Proeksad (talk) 16:18, 19 April 2024 (UTC)

@Proeksad: There is a helper template for that : {{Multiple statements}}. Just {{sparql|query=select ?item { {{multiple statements|P10565|?item}} } }} gives :
select ?item { 
   {
     select distinct ?item {
       ?item p:P10565  ?itemP10565stmt1, ?itemP10565stmt2
                        filter(?itemP10565stmt1 != ?itemP10565stmt2) .
       ?itemP10565stmt1 a wikibase:BestRank .
              ?itemP10565stmt1 a wikibase:BestRank .
     } 
   } }
Try it!
You can combine with other criteria if you like. But Wikidata:Database reports/Constraint violations should do the same in this case. author  TomT0m / talk page 16:27, 19 April 2024 (UTC)
Thank you! Proeksad (talk) 17:04, 19 April 2024 (UTC)
How to request without deprecated statements? For example, Q1469#P4342. @TomT0m Proeksad (talk) 17:48, 19 April 2024 (UTC)
@Proeksad I fixed the template, you can retry the query and now it will use only better ranked statements and ignore deprecated values. If you want all valid values you can try to set the valid parameter :
select ?item { 
   {
     select distinct ?item {
       ?item p:P10565  ?itemP10565stmt1, ?itemP10565stmt2
                        filter(?itemP10565stmt1 != ?itemP10565stmt2) .
       ?itemP10565stmt1 wikibase:rank ?itemP10565stmt1_rank 
              filter (?itemP10565stmt1_rank != wikibase:DeprecatedRank) .
              ?itemP10565stmt2 wikibase:rank ?itemP10565stmt2_rank 
              filter (?itemP10565stmt2_rank != wikibase:DeprecatedRank) .
     } 
   } }
Try it!
author  TomT0m / talk page 11:33, 20 April 2024 (UTC)

Things both Japan and Russia

I think that this discussion is resolved and can be archived. If you disagree, don't hesitate to replace this template with your comment. author  TomT0m / talk page 17:51, 21 April 2024 (UTC)

Hello, how to query things having wdt:P17==Q17 AND wdt:P17==Q159 ? Bouzinac💬✒️💛 15:29, 19 April 2024 (UTC)

@Bouzinac: Like this :
select distinct ?item ?itemLabel {
  ?item wdt:P17 wd:Q17, wd:Q159 .
  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
Try it!
author  TomT0m / talk page 15:46, 19 April 2024 (UTC)
https://w.wiki/9ouJ ce sont des choses pas forcément fausses, dans la mesure où y a différent territorial entre les deux pays Bouzinac💬✒️💛 15:59, 19 April 2024 (UTC)
Point amusant : si tu t'amuses à requêter Japon+Brésil, tu te retrouves à Rome :) https://w.wiki/9ouS Bouzinac💬✒️💛 16:02, 19 April 2024 (UTC)
Si tu veux t'amuser plus efficacement, j'ai mis un formulaire dessus grace à la fonctionnalité "template" : https://w.wiki/9ouw author  TomT0m / talk page 16:14, 19 April 2024 (UTC)
If you would like to have also not present countryships: https://w.wiki/9qvi. --Infovarius (talk) 20:29, 22 April 2024 (UTC)

Find English labels only, but if no label in English allow any language

I'm basically getting all the data on a wikidata page, to use it for a tool. At the moment, I use this query to get that data:

SELECT ?item ?p_property ?p_propertyLabel ?statementLink ?simplevalue ?simplevalueLabel 
WHERE
{
  wd:Q1065 ?property ?statementLink . 
  ?statementLink ?simplevalueLink ?simplevalue .
  wd:Q1065 ?propdirect ?simplevalue.
  wd:Q1065 rdfs:label ?item.
  
  
  #find property label (thanks to tagishsimon)
  ?p_property wikibase:claim ?property .
  
  #find only properties & values with the right namespace
  FILTER(STRSTARTS(STR(?propdirect), STR(wdt:)))
  FILTER(STRSTARTS(STR(?property), STR(p:))) 
  FILTER(STRSTARTS(STR(?simplevalueLink),  STR(ps:)))
  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } # Helps get the label in your language, if not, then en language

  #only get English language item names
  FILTER(LANGMATCHES(LANG(?item), "en"))
}
Try it!

Originally I didn't have that bit at the end, but I would get for example Chinese or French labels for my item and very rarely English. Now it obviously filters out anything not English, but I'm concerned that if an item has no label in English the query will return nothing. I could just check for this in my code, and fire off a second request without the filter and without asking for the item name, but I would prefer to keep the number of requests low.

Is there a way to filter on English labels only, unless no English label exists in which case any label will do? Or should I just do another request? M.alten.tue (talk) 12:59, 25 April 2024 (UTC)