Shortcuts: WD:RAQ, w.wiki/LX

Wikidata:Request a query

From Wikidata
(Redirected from Wikidata:RAQ)
Jump to navigation Jump to search

Request a query
Fishing in the Wikidata river requires both an idea where to look for fish and a suitable fishing method. If you have the former, this page can help you find the latter.

This is a page where SPARQL 1.1 Query Language (Q32146616) queries can be requested. Please provide feedback if a query is written for you.

For sample queries, see Examples and Help:Dataset sizing. Property talk pages include also summary queries for these.

For help writing your own queries, or other questions about queries, see Wikidata talk:SPARQL query service/queries and Wikidata:SPARQL query service/query optimization.

Help resources about Wikidata Query Service (Q20950365) and SPARQL: Wikidata:SPARQL query service/Wikidata Query Help and Category:SPARQL.

To report an issue about the Query Service (interface, results views, export...) please see Wikidata:Contact the development team/Query Service and search.
On this page, old discussions are archived. An overview of all archives can be found at this page's archive index. The current archive is located at 2024/06.

Normalised truthy values

[edit]

Getting truthy values is easy with wdt:. Getting normalises values is possible with p: and psn: is also possible (as I learned in Wikidata:Request_a_query/Archive/2023/10#Height_in_a_single_unit). However, when using p: and psn: I get all values, with all ranks. How can I get only the truthy values?

For example, in this query Bac de Roda Bridge (Q3396457) has two values for length (P2043) and longest span (P2787) (one of them preferred). Using wdt I would get only that value (which is good) but if I want to make sure that I get values in meters, I get the two values for those dimensions.

# Ponts amb mides
SELECT DISTINCT ?item ?itemLabel ?llarg ?ample ?llum ?alt
 WHERE {
 VALUES ?tipus {wd:Q12280}
 ?item wdt:P17 wd:Q29.
 ?item wdt:P31/wdt:P279* ?tipus.
   ?item wdt:P166 [].
        OPTIONAL {?item p:P2043  ?sllarg.
               ?sllarg psn:P2043  ?sllargn.
                ?sllargn wikibase:quantityAmount ?llarg. 
              }
        OPTIONAL { ?item wdt:P2787 [].
          ?item p:P2787  ?sllum.
               ?sllum psn:P2787  ?sllumn.
                ?sllumn wikibase:quantityAmount ?llum. 
              }
        OPTIONAL {?item p:P2049  ?sample.
               ?sample psn:P2049  ?samplen.
                ?samplen wikibase:quantityAmount ?ample. 
              }
        OPTIONAL {?item p:P2048  ?salt.
               ?salt psn:P2048  ?saltn.
                ?saltn wikibase:quantityAmount ?alt. 
              }
   SERVICE wikibase:label {bd:serviceParam wikibase:language "[AUTO_LANGUAGE],ca,en,es,fr".}   
}
Try it!

I tried to use wdtn: but it didn't work (it seems that it is still to be implemented for values with units).

How can I get normalised truthy values? Pere prlpz (talk) 23:14, 25 May 2024 (UTC)[reply]

I believe the documentation uses the term 'truthy' incorrectly. What you get when you use "wdt:" i consistently call best-values to avoid confusion. This returns preferred rank values if they exist, if not, they return normal ranked values. Truthy values is really the set of preferred and normal ranked values. In your first optional add the line "?sllarg a wikibase:BestRank ." and do similarly on the other optionals. Infrastruktur (talk) 21:52, 26 May 2024 (UTC)[reply]
@Infrastruktur: Thank you. It works fine.--Pere prlpz (talk) 22:06, 26 May 2024 (UTC)[reply]

Find same codes sharing

[edit]

Hi, inside this query https://w.wiki/ACEF, how to filter out the unique identifiers (that is, get only those that share same identifiers) ? Bouzinac💬✒️💛 20:27, 26 May 2024 (UTC)[reply]

My try:
SELECT ?item ?itemLabel ?idnt ?numItems
WITH {
SELECT ?idnt (COUNT(DISTINCT(?item)) AS ?numItems) WHERE {
  ?item   wdt:P5696 ?idnt.
} 
GROUP BY ?idnt
} AS %1
WHERE {
  INCLUDE %1.
  ?item   wdt:P5696 ?idnt.
  FILTER(?numItems > 1)
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
Try it!
Does it work for you? Pere prlpz (talk) 22:18, 26 May 2024 (UTC)[reply]
Exactly what I needed. Thanks a lot ! Bouzinac💬✒️💛 07:18, 27 May 2024 (UTC)[reply]

English footballers data

[edit]

I am looking to create lists on wikidata of english football club players, their date of birth, year of debut, age at death and number of appearances. So far I have only been able to generate date of birth for players of each club. Is it possible to have all these parameters in one search / in one table? 123.208.182.177 09:55, 29 May 2024 (UTC)[reply]

Commons files with an inception date of 2015-08-15

[edit]

On the Commons query service, is it possible to query all files with a certain inception date (wdt:P571)? I'm not sure how to use dateTime, timeValue, timePrecision, etc. or even if those are necessary for this. Nosferattus (talk) 04:49, 30 May 2024 (UTC)[reply]

You mean like this: Try it!
? --Strahtw (talk) 07:50, 5 June 2024 (UTC)[reply]

What is the "main type" of each entity

[edit]

Hi. I'm updating OSM with the tag "name:etymology:wikidata", and I know howto export from OSM all those tags in a city (city's streets). But I can't imagine how to request Wikidata to retrieve for each Wikidata ID the "main type" and another main information, like it's a "human / gender", a "locality / human settlement / Country", a "war battle / country" ans so on. I know programming, so I can do a loop with each entity ID ;-)

For exemple "Q3261145" is a human of the male gender, "Q1686757" is a city of Belguim, "Q38789" is a battle in russia, "Q6565319" is a species of plant ...

Thanks a lot for your help <3 Cyrille37 (talk) 10:26, 2 June 2024 (UTC)[reply]

How to return a qualifier for a specific property

[edit]

Hello there. I am researching the National Register of Historic Places.

I've created a simple query that returns any item which has 'heritage designation' (P1435) of 'National Register of Historic Places listed place' (Q19558910). It results in about 73,425 items: https://w.wiki/AJMR

If you click on any of the Wikidata items for these NRHP listings, you'll see most (if not all) have a 'start time' qualifier listed under their 'National Register of Historic Places listed place' property. This is the date the building (or historic district) was added to the National Register sometime after its inception in 1966. 'start time' is also used for other heritage designation properties (National Historic Landmark, UNESCO, etc) for some of these 73,425 items.

What I want to do next is to include a column in the results that specifies the 'start time' qualifier for specifically the 'National Register of Historic Places listed place' (Q19558910) property.

I am trying the following query, which somehow only results in 48 items for me: https://w.wiki/AJMe

I know I could be doing something differently because: -there should be many more results of 'National Register of Historic Places listed place' items than 48 -some of the listed 'start times' are not the specific 'start times' I'm looking for. I only want start time for 'National Register of Historic Places listed place', not any other start time that might be used.

Any advice on tailoring this query would be much appreciated. I've searched a lot of tutorials for the past couple hours and can't find a solution.

Once I get a list of each 73,425 result, with its correct National Register heritage designation start time, I just want to create a simple tally of quantity per year. I can export the results and do this count in a spreadsheet, but if there is an easy way to formulate the correct query to do the count per year as well, that would be fantastic.

Thank you to anyone who can help! Openpreservation.xyz (talk) 00:49, 6 June 2024 (UTC)[reply]

The problem is that the start time (P580) is only created as a property for the 48 items you receive. For most of the others, the start time is stored as a qualifier of the heritage designation (P1435).
Here is a query that lists these: https://w.wiki/AJS7
However, the other 48 are missing, so perhaps this should be standardized.
Now, however, some entries are displayed several times if they have several heritage categories. As I am only moderately familiar with this myself, I can't help you any further. But if you have a solution for this, such as only the start times of the entry in the National Register of Historic Places listed place (Q19558910) let me know, because I also had the problem once and I have no solution for it so far. Strahtw (talk) 05:58, 6 June 2024 (UTC)[reply]
Thank you @Strahtw for giving it a shot.
Hopefully someone else can help us fine tune the query to get just National Register items with just National Register start dates. Openpreservation.xyz (talk) 16:01, 6 June 2024 (UTC)[reply]
I was looking at the documentation and found an example with filters which I thought it could help. I tried it and got the query you want:
SELECT ?item ?itemLabel ?start_time WHERE {
  ?item wdt:P1435 wd:Q19558910;
  p:P1435 ?Cat.
  optional { ?Cat pq:P580 ?start_time. } 
  FILTER EXISTS { ?Cat ps:P1435 wd:Q19558910 }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE]". }
}
Try it!
But now I get 74209 entries. But some results have two entries with National Register of Historic Places listed place (Q19558910). For example Broadway Bridge (Q4972421). This doubles have to be corrected maybe.
--Strahtw (talk) 07:38, 7 June 2024 (UTC)[reply]

A list of all museums in the German State of North-Rhine Westphalia

[edit]

This querry: SELECT DISTINCT ?item ?itemLabel WHERE {

 SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE]". }
 {
   SELECT DISTINCT ?item WHERE {
     ?item p:P31 ?statement0.
     ?statement0 (ps:P31) wd:Q33506.
     ?item p:P131 ?statement1.
     ?statement1 (ps:P131/(wdt:P131*)) wd:Q1198.
   }
   LIMIT 1000
 }

}

obviously doesn't list all the {{q| Q33506}} museums in {{q| Q1198}} North-Rhine Westphalia. 

For instance the {{q| Q1798475}} LWL-Museum für Kunst und Kultur is not listed. Why? Is something missing in the entry of the museum? Is it because the museum is listed as a {{q| Q207694}} Kunstmuseum?

In other word is it necessary to include some kind of deep-search into the querry?

When all this is done, I have a second wish: How do I visualize the results in a clickable map of North-Rhine Westphalia?

Thanks

--Wuselig (talk) 11:54, 6 June 2024 (UTC)[reply]

Hi, a more simpler query (but limited to Munster region)
#defaultView:Map
SELECT DISTINCT ?item ?itemLabel ?itemDescription ?coords ?image WHERE {  ?item (wdt:P31/(wdt:P279*)) wd:Q33506;#any type of museum
    wdt:P131* wd:Q7920;#in Munster or inside Munster
   wdt:P17 wd:Q183; #in Germany
   wdt:P625 ?coords.#WITH coordinates
 SERVICE wikibase:label { bd:serviceParam wikibase:language "de,en". }  OPTIONAL { ?item wdt:P18 ?image. }#possibly with images
}
Try it!
Bouzinac💬✒️💛 17:16, 9 June 2024 (UTC)[reply]

Flag more accurate coordinates // less accurate

[edit]

Hi, in this list, there are multiples coordinates at same rank. Is there a way to distinguish low precision P625 // good precision P625 [the more decimals ==> the more precise coordinates]. Bonus : is there a tool to set en masse the more precise P625 as preferred rank ? Bouzinac💬✒️💛 13:00, 8 June 2024 (UTC)[reply]

You can't trust the reported precision. Quickstatements sets the precision to any coordinates to 1.0e-6 about 11.1 centimeters. Commercial GPS typically gives you between 1-10 meters of accuracy. Gauging the coordinates off a map may be accurate within 100 metres. But I've seen coordinates off by 2 arcminutes which is several kilometers. Infrastruktur (talk) 08:15, 9 June 2024 (UTC)[reply]
Okay, let me rephrase my question. Would you know how to sparql items having multiple P625 statements (if only normal rank) and whose statements give P625 points very "distants" between them (I want to find suspicious/wrong P625 statements for data quality) ? Bouzinac💬✒️💛 17:01, 9 June 2024 (UTC)[reply]
Found that query in the archives which works well!
SELECT ?item ?itemLabel ?location1 ?location2 ?distance WHERE {
  ?item wdt:P31/wdt:P279* wd:Q3887;
    wdt:P625 ?location1, ?location2.
  BIND(geof:distance(?location1, ?location2) AS ?distance)
  FILTER(((geof:longitude(?location1)) < (geof:longitude(?location2))) || (((geof:longitude(?location1)) = (geof:longitude(?location2))) && ((geof:latitude(?location1)) < (geof:latitude(?location2)))))
  FILTER(?distance > 100 )
 SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}order by desc(?distance)
Try it!
Bouzinac💬✒️💛 18:53, 9 June 2024 (UTC)[reply]