Василиса▶ Я жду вашего обращения. Что Вы хотите узнать?
Wikidata:Request a query - Wikidata Shortcuts : WD:RAQ, w.wiki/LXWikidata:Request a queryFrom Wikidata
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 2021/02 .
ContentsItalian municipalities with latest population figures not set to preferred rank[ edit ]

I'm looking for instances of comune of Italy (Q747074) where there are multiple values for population (P1082) , but where the most recent ( point in time (P585) ) value is not set to preferred rank. - 4ing ( talk ) 09:56, 29 January 2021 (UTC)

@ 4ing : Two queries for you. First is the new dates that are not of BestRank, and the second is the old dates that are of BestRank. Both includes GUIDs for the claims, so that it becomes easy to use e.g. wikibase-cli to tweak the rank for the claims.SELECT?item?itemLabel?date?rank?statwith{SELECT?item(max(?date_)as?date)WHERE{?itemwdt:P31wd:Q747074.?itemp:P1082?stat.?statpq:P585?date_.}group by?item}as%iwhere{include%i?itemp:P1082?stat.?statpq:P585?date.filternot exists{?statawikibase:BestRank.}?statwikibase:rank?rank.SERVICEwikibase:label{bd:serviceParamwikibase:language"[AUTO_LANGUAGE],en".}} Try it! SELECT?item?itemLabel?date_old?rank?statwith{SELECT?item(max(?date_)as?date)WHERE{?itemwdt:P31wd:Q747074.?itemp:P1082?stat.?statpq:P585?date_.}group by?item}as%iwith{SELECT?itemwhere{include%i?itemp:P1082?stat.?statpq:P585?date.filternot exists{?statawikibase:BestRank.}?statwikibase:rank?rank.}}as%jwhere{include%j?itemp:P1082?stat.?statpq:P585?date_old.?statawikibase:BestRank.?statwikibase:rank?rank.SERVICEwikibase:label{bd:serviceParamwikibase:language"[AUTO_LANGUAGE],en".}} Try it! -- Tagishsimon ( talk ) 13:22, 29 January 2021 (UTC)@ Tagishsimon : Thanks for your swift response. The issue was less frequent than I expected - it applies to 419 out of 7918 instances of comune of Italy (Q747074) (I've manually corrected a few entries earlier today based on a list generated by ListeriaBot. Preferred rank shouldn't always be assigned to the latest value due to lack of source/poor source, lack of determination method (P459) etc. However, items with latest population figures dated 2018-01-01 (applies to most items), should have this value set as preferred rank since it is properly sourced and includes relevant qualifiers. I don't have the skills (yet) to use wikibase-cli to change the ranks. - 4ing ( talk ) 21:34, 29 January 2021 (UTC)@ 4ing : So these all look good; at the least we have determination and a reference URL. I can run wikibase-cli over these if you're happy, and remove preferred from prior dates.SELECT?item?itemLabel?date?determination?ref?rank?statwith{SELECT?item(max(?date_)as?date)WHERE{?itemwdt:P31wd:Q747074.?itemp:P1082?stat.?statpq:P585?date_.}group by?item}as%iwhere{include%i?itemp:P1082?stat.?statpq:P585?date.optional{?statpq:P459?determination.}optional{?statprov:wasDerivedFrom/pr:P854?ref.}filternot exists{?statawikibase:BestRank.}?statwikibase:rank?rank.SERVICEwikibase:label{bd:serviceParamwikibase:language"[AUTO_LANGUAGE],en".}} Try it! -- Tagishsimon ( talk ) 21:54, 29 January 2021 (UTC)@ Tagishsimon : No, not all of them are good. All with date 2018-01-10 should be good, but rank on e.g. Gela (Q39971) should not be changed, since the newest value of population (P1082) is missing both point in time (P585) , determination method (P459) and a reference. I think the query should be modified to instances of comune of Italy (Q747074) where there are multiple values for population (P1082) , the most recent value is dated 2018-01-01, but the most recent value does not have the preferred rank. It would would solve 95 % of the problem, the remaining 5 % could be checked manually. - 4ing ( talk ) 22:41, 29 January 2021 (UTC) @ 4ing : Here is a query which finds instances of comune of Italy (Q747074) where there is a value for P1082 with preferred rank, and another value for P1082 with normal rank that also meets these conditions: It must have a determination method (P459) qualifier, it must have a newer date, it must have a source with contains reference URL (P854) . For various reasons 3 comunes ( Avellino (Q13433) , Andria (Q13486) , Agnadello (Q42983) ) have more than one result in the query. You might want to fix these manually. Then maybe the rest can fixed by a tool if you like the results. SELECT?item?itemLabel?date_preferred_rank?date_newer?method_newerLabel?source_URLWHERE{?itemwdt:P31wd:Q747074.# Find a P1082 statement with preferred rank?itemp:P1082?stat_preferred_rank.?stat_preferred_rankwikibase:rankwikibase:PreferredRank.?stat_preferred_rankpq:P585?date_preferred_rank.# Find a P1082 statement with normal rank, P459 qualificator, source with P854, and a newer date?itemp:P1082?stat_newer.?stat_newerwikibase:rankwikibase:NormalRank.?stat_newerpq:P585?date_newer.FILTER(?date_newer>?date_preferred_rank)?stat_newerpq:P459?method_newer.?stat_newerprov:wasDerivedFrom?source_newer.?source_newerpr:P854?source_URL.SERVICEwikibase:label{bd:serviceParamwikibase:language"[AUTO_LANGUAGE],en,it".}} Try it! -- Dipsacus fullonum ( talk ) 05:00, 30 January 2021 (UTC)

@ Dipsacus fullonum : I've manually corrected the three items you listed, in addition to Verona (Q2028) , which had two values marked with preferred rank. The remaining 405 items should have corrected the rank. @ Tagishsimon : If you could run wikibase-cli on these, I would definitely be happy! - 4ing ( talk ) 21:34, 30 January 2021 (UTC)

@ 4ing : Doing that right now. You might want to check Alpette (Q8993) by hand - it had a 2017 and 2019 marked as preferred. I suspect you'll want 2018 to be preferred now, but I've not implemented that. -- Tagishsimon ( talk ) 14:19, 31 January 2021 (UTC) @ Tagishsimon : Thanks for excellent work. Alpette (Q8993) is actually taking us to the next issue: Istat (Q214195) is not a proper value for stated in (P248) , it should have been publisher (P123) . Relevant reference URL (P854) would be http://demo.istat.it/pop2017/index3.html for population (P1082) with point in time (P585) 2017-01-01, http://demo.istat.it/pop2018/index3.html for 2018-01-01, http://demo.istat.it/pop2019/index3.html for 2019-01-01 and http://demo.istat.it/pop2020/index3.html for 2020-01-01. In addition, many population (P1082) with point in time (P585) 2017-01-01 should have changed reference URL (P854) from http://www.demo.istat.it/pop2017/index3.html (dead link) to http://demo.istat.it/pop2017/index3.html . Would you be able to set up the relevant queries (it is limited to comune of Italy (Q747074) )? - 4ing ( talk ) 21:51, 31 January 2021 (UTC) In adition, I think there are instances of stated in (P248) and publisher (P123) , with value Istat (Q214195) , being set as qualifiers, not reference. - 4ing ( talk ) 21:58, 31 January 2021 (UTC) And last addition for today: Tavagnacco (Q53378) and several other items have two point in time (P585) for the same value of population (P1082) . - 4ing ( talk ) 22:08, 31 January 2021 (UTC)@ 4ing : I've sorted out items having two point in time (P585) for the same value of population (P1082) , and items having http://www.demo.istat.it/pop2017/index3.html . I'll have a look some more tomorrow. -- Tagishsimon ( talk ) 02:38, 1 February 2021 (UTC)Thanks, this looks excellent! Be aware that in instances like Bagnolo Mella (Q103462) , preferred rank should be set. - 4ing ( talk ) 08:07, 1 February 2021 (UTC) Inefficient to revisit rank until the underlying data is sorted out, was my thinking. -- Tagishsimon ( talk ) 10:53, 1 February 2021 (UTC)

@ Tagishsimon : Do you have any plans to complete this task? Most important is to correct the wrong use of stated in (P248) ? - 4ing ( talk ) 09:08, 15 February 2021 (UTC)

Show only the references that have a specific role[ edit ]#genera of Echinodermata showing potential: authors, fisrt description, Wikispecies links and synonymySELECTDISTINCT?item?itemLabel?author?firstDescription?speciesSitelink?isSynonymOf?isSynonymOfLabelWHERE{?itemwdt:P171+wd:Q44631.?itemwdt:P105?rank.?itemwdt:P105wd:Q34740.OPTIONAL{?itemp:P225?st.?stpq:P405?author.}OPTIONAL{?itemp:P225?statement.?statementprov:wasDerivedFrom?reference.?referencepr:P248?firstDescription.?referencepr:P6184wd:Q1361864.}OPTIONAL{?speciesSitelinkschema:about?item;schema:isPartOf<https://species.wikimedia.org/>.}OPTIONAL{?item^wdt:P1420?isSynonymOf.}SERVICEwikibase:label{bd:serviceParamwikibase:language"[AUTO_LANGUAGE],en".}}order by?itemLabel Try it! Hi, the query above works quite well (it was modified from a query given by @ Dipsacus fullonum :), my concern is that I would want to show only the references of taxon name (P225) where reference has role (P6184) = first description (Q1361864) . E.g. for Podasterias (Q105427222) , 2 references are available but only one interests me. Christian Ferrer ( talk ) 14:03, 12 February 2021 (UTC)@ Christian Ferrer : I made a change to the query above. It introduces the variable ?reference to make sure that the two triples with pr: predicates use the same reference. -- Dipsacus fullonum ( talk ) 14:27, 12 February 2021 (UTC) Excellent, thanks you. It's easier now for me to see where data is missing. Christian Ferrer ( talk ) 15:22, 12 February 2021 (UTC)Map in defined language[ edit ]


I'm looking at statues in Helsinki in Wikidata and what information is available about them in Finland's national language Swedish. If I put them on a map with this query , the map is in Finnish. Is there any way to get the map to show the Swedish names of the streets and neighbourhoods - which I know is available in OSM? If not, what is the right place to suggest this improvement?

Thanks! Robertsilen ( talk ) 08:51, 15 February 2021 (UTC)


Hello, I'have a probleme with a requete

when i write

SELECT?personnes?personnesLabel(GROUP_CONCAT(DISTINCT(?occupation);separator=", ")as?LeursoccupationsLabel)WHERE{SERVICEwikibase:label{bd:serviceParamwikibase:language"[AUTO_LANGUAGE],en".}VALUES?metier{wd:Q20814940wd:Q45748643wd:Q3542795}?personneswdt:P106?metier;wdt:P21wd:Q6581072.OPTIONAL{?personneswdt:P106?occupation.}}GROUP BY?personnes?personnesLabel Try it!

?LeursoccupationsLabel, I'have " http://www.wikidata.org/entity/Q191493 , http://www.wikidata.org/entity/Q897317 , http://www.wikidata.org/entity/Q16947675 , http://www.wikidata.org/entity/Q45748643 " and i want "caviste, oenologie...".

Can you help me ? Thanks

You cannot use a label obtained by the automatic mode of the label service as a function argument, but have to switch to the manual mode. It is explained in the user manual at mw:Wikidata Query Service/User Manual#Label service . SELECT?personnes?personnesLabel(GROUP_CONCAT(DISTINCT(?occupationLabel);separator=", ")as?LeursoccupationsLabel)WHERE{SERVICEwikibase:label{bd:serviceParamwikibase:language"[AUTO_LANGUAGE],fr,en".?personnesrdfs:label?personnesLabel.?occupationrdfs:label?occupationLabel.}VALUES?metier{wd:Q20814940wd:Q45748643wd:Q3542795}?personneswdt:P106?metier;wdt:P21wd:Q6581072.OPTIONAL{?personneswdt:P106?occupation.}}GROUP BY?personnes?personnesLabel?LeursoccupationsLabel Try it! -- Dipsacus fullonum ( talk ) 15:24, 15 February 2021 (UTC)thank you Silanoc ( talk ) 15:43, 15 February 2021 (UTC)Value without reference[ edit ]

Hello, I would like to find the list of woman dead in Paris before 1900 without reference for the date, but I don't succeed..

#Women dead in Paris before 1900 without reference for the dateSELECT?item?itemLabel?dateWHERE{?itemwdt:P21wd:Q6581072;wdt:P20wd:Q90;wdt:P570?date;MINUS{?itemwdt:P31wd:Q95074}.FILTER(year(?date)<1900).MINUS{?datepr:[]?reference}.SERVICEwikibase:label{bd:serviceParamwikibase:language"[AUTO_LANGUAGE],en".}}ORDER BYDESC(?date)LIMIT1000 Try it!

Thanks on advance for your help! -- 2le2im-bdc ( talk ) 19:57, 15 February 2021 (UTC)

@ 2le2im-bdc : #Women dead in Paris before 1900 without reference for the dateSELECT?item?itemLabel?dateWHERE{?itemwdt:P21wd:Q6581072.# female?itemwdt:P20/wdt:P131*wd:Q90.# dead in Paris or a place located within Paris?itemp:P570?date_statement.?date_statementawikibase:BestRank.# With a date of death statement of best rank?date_statementps:P570?date.hint:Priorhint:rangeSafetrue.FILTER(?date<"+1900-00-00T00:00:00Z"^^xsd:dateTime)# Dead before year 1900MINUS{?itemwdt:P31wd:Q95074.}MINUS{?date_statementprov:wasDerivedFrom[].}# No reference for the date of death statementSERVICEwikibase:label{bd:serviceParamwikibase:language"[AUTO_LANGUAGE],en".}}ORDER BYDESC(?date)LIMIT1000 Try it! -- Dipsacus fullonum ( talk ) 21:22, 15 February 2021 (UTC) Thanks a lot @ Dipsacus fullonum :! I have well done to ask : not so easy this query!-- 2le2im-bdc ( talk ) 14:30, 16 February 2021 (UTC)Finding all organizations in a geographical area (how to fix a query)[ edit ]

Hi folks! I previously had a search for all the cultural heritage organizations in a geographic area in Georgia, searching by county (see below). This query worked because I had (incorrectly) tagged all of the organizations with both their municipality and their county in the P131 field. The county values have since been removed from most of the organizations, leaving only the municipalities but not the county. My question is now, how do I change the below search to fix it so that it shows the organizations located in these counties, if we're not allowed to actually list the counties on the organizations' items?

SELECTDISTINCT?organization?organizationLabel?street_address?coordinate_location?phone_number?e_mail_address?website?Facebook_ID?Twitter_username?countyWHERE{VALUES(?located_in_the_administrative_territorial_entity?county){(wd:Q486843"Bleckley County")(wd:Q498301"Pulaski County")(wd:Q486791"Wilcox County")(wd:Q115272"Dodge County")(wd:Q691614"Telfair County")(wd:Q498332"Wheeler County")(wd:Q493125"Montgomery County")(wd:Q376822"Toombs County")(wd:Q505310"Tattnall County")(wd:Q111867"Ben Hill County")(wd:Q492057"Irwin County")(wd:Q156503"Coffee County")(wd:Q493071"Jeff Davis County")(wd:Q488186"Appling County")(wd:Q488219"Bacon County")(wd:Q488868"Berrien County")(wd:Q488194"Atkinson County")(wd:Q498353"Ware County")(wd:Q492070"Lanier County")(wd:Q493029"Echols County")(wd:Q486167"Clinch County")}VALUES?instance_of{wd:Q473972wd:Q3152824wd:Q210272wd:Q570116wd:Q57660343wd:Q2668072wd:Q188913wd:Q15243209wd:Q2867476wd:Q635719wd:Q7840289wd:Q42998wd:Q41710wd:Q51369558}FILTER(NOT EXISTS{?organizationwdt:P576_:b15.})?organization(wdt:P31/(wdt:P279*))?instance_of;wdt:P131?located_in_the_administrative_territorial_entity.hint:Priorhint:runFirst"true"^^xsd:boolean.OPTIONAL{?organizationwdt:P6375?street_address.}OPTIONAL{?organizationwdt:P625?coordinate_location.}OPTIONAL{?organizationwdt:P1329?phone_number.}OPTIONAL{?organizationwdt:P968?e_mail_address.}OPTIONAL{?organizationwdt:P856?website.}OPTIONAL{?organizationwdt:P2013?Facebook_ID.}OPTIONAL{?organizationwdt:P2002?Twitter_username.}SERVICEwikibase:label{bd:serviceParamwikibase:language"en".}OPTIONAL{}}ORDER BY(?organization)LIMIT10000 Try it!

Any help is much appreciated! Clifflandis ( talk ) 20:27, 15 February 2021 (UTC)

@ Clifflandis : The short answer is add "+" after wdt:P131 to make a property path of one or more instances of wdt:P131. The long answer is: SELECTDISTINCT?organization?organizationLabel?street_address?coordinate_location?phone_number?e_mail_address?website?Facebook_ID?Twitter_username?countyWHERE{VALUES(?located_in_the_administrative_territorial_entity?county){(wd:Q486843"Bleckley County")(wd:Q498301"Pulaski County")(wd:Q486791"Wilcox County")(wd:Q115272"Dodge County")(wd:Q691614"Telfair County")(wd:Q498332"Wheeler County")(wd:Q493125"Montgomery County")(wd:Q376822"Toombs County")(wd:Q505310"Tattnall County")(wd:Q111867"Ben Hill County")(wd:Q492057"Irwin County")(wd:Q156503"Coffee County")(wd:Q493071"Jeff Davis County")(wd:Q488186"Appling County")(wd:Q488219"Bacon County")(wd:Q488868"Berrien County")(wd:Q488194"Atkinson County")(wd:Q498353"Ware County")(wd:Q492070"Lanier County")(wd:Q493029"Echols County")(wd:Q486167"Clinch County")}VALUES?instance_of{wd:Q473972wd:Q3152824wd:Q210272wd:Q570116wd:Q57660343wd:Q2668072wd:Q188913wd:Q15243209wd:Q2867476wd:Q635719wd:Q7840289wd:Q42998wd:Q41710wd:Q51369558}FILTERNOT EXISTS{?organizationwdt:P576[].}?organizationwdt:P31/wdt:P279*?instance_of.?organizationwdt:P131+?located_in_the_administrative_territorial_entity.OPTIONAL{?organizationwdt:P6375?street_address.}OPTIONAL{?organizationwdt:P625?coordinate_location.}OPTIONAL{?organizationwdt:P1329?phone_number.}OPTIONAL{?organizationwdt:P968?e_mail_address.}OPTIONAL{?organizationwdt:P856?website.}OPTIONAL{?organizationwdt:P2013?Facebook_ID.}OPTIONAL{?organizationwdt:P2002?Twitter_username.}SERVICEwikibase:label{bd:serviceParamwikibase:language"en".}}ORDER BY(?organization)LIMIT10000 Try it! -- Dipsacus fullonum ( talk ) 21:38, 15 February 2021 (UTC)@ Dipsacus fullonum : Thanks again for your help, but unfortunately it's giving me duplicates -- is there any way to fix this? For example, the second and third items that show up in the results are both for the Blue and Gray Museum (Q16843368) in Fitzgerald (Q654046) , Georgia, USA. This is because the town of Fitzgerald exists in two counties, Ben Hill County (Q111867) and Irwin County (Q492057) . So the search results display the Blue and Grey Museum twice, once for each county. Is there a way to de-duplicate the results list? I'll also ping @ Mahir256 : in case they may know how to help since they automated the removal of the county information from some of these organization's items. Again, thanks in advance for your help! Clifflandis ( talk ) 13:24, 16 February 2021 (UTC) @ Clifflandis : It isn't possible to find out which county institutions in Fitzgerald City is located in if more detailed information than the city isn't provided. It was proposed last year to make a hierarchy switch qualifier to indicate the county in cases like these. I see that you supported the proposal, but unfortunately it is still not concluded so it seems there is no recommended way to handle this at the moment. P131 could be used as a qualifier in the same way as the proposed "hierarchy switch", or there could be two independent statements with P131. I can make queries to handle both methods, but I cannot make queries to extract data that isn't provided. -- Dipsacus fullonum ( talk ) 13:54, 16 February 2021 (UTC) @ Dipsacus fullonum : Okay, good to know -- I'll let the Federal Emergency Management Agency (Q503010) and Georgia Emergency Management and Homeland Security Agency (Q5547471) folks know that our queries will be broken until the community can reach a consensus on how to handle things like this.Unfortunately, just adding a "+" after wdt:P131 is giving me a server error. Is there something else I need to change in the query to make it work? Again, thanks for your continued help! Clifflandis ( talk ) 14:14, 16 February 2021 (UTC) @ Dipsacus fullonum :, whoops! Nevermind, I see the additional edit's after "FILTER NOT EXISTS". Thanks again! Clifflandis ( talk ) 14:22, 16 February 2021 (UTC)@ Clifflandis : So very sorry for inadvertently making your work more difficult! (I was under the mistaken impression that this issue of multiple-county cities ended up being resolved.) When I went through and removed the P131 statements I removed, I was checking for statements that were both of normal rank, which both lacked qualifiers, and where one value was wdt:P131/wdt:P131* the other value (which, it turns out, most of the Georgia items' statements satisfied). Seeing now that this also removed statements where the extra county value was actually useful, I used the query below to find places located in cities/towns in multiple Georgia counties and restored the county statements I removed (while adding a qualifier to them so that I don't touch them again later):SELECTDISTINCT?i?iLabelWITH{SELECT?c?cLabel{?cwdt:P131?a;wdt:P131?b.wd:Q13410428^wdt:P31?a,?b.wd:Q1428^wdt:P131?a,?b.FILTER(STR(?a)<STR(?b))}}AS%csWHERE{INCLUDE%cs.?iwdt:P131/wdt:P131*?c.SERVICEwikibase:label{bd:serviceParamwikibase:language"[AUTO_LANGUAGE],en".}} Try it! If there's anything I missed (which still shows up as duplicates in your original query, for instance), please let me know. Sorry for the trouble again! Mahir256 ( talk ) 15:53, 16 February 2021 (UTC) @ Mahir256 : thanks for restoring the counties with the new next level in hierarchy (Q105528942) qualifier. Right now, when I search using the search above that Dipsacus fullonum modified for me, it's still showing duplicate instances for any organization that is in a city with more than one county. Do you know how to modify the search based around the new qualifier, so that excludes those duplicate records with the incorrect county? For example, the search above is still showing the Blue and Gray Museum (Q16843368) twice -- is there a way to only show the single entry with the correct county ( Ben Hill County (Q111867) ? Thanks in advance for your help! Clifflandis ( talk ) 17:40, 16 February 2021 (UTC) @ Dipsacus fullonum : Is there a way to modify the query to only show the correct county, if the P131 field includes both the municipality and county (based around the county's qualifier of object has role (P3831) next level in hierarchy (Q105528942) )? For example, Blue and Gray Museum (Q16843368) . Right now it's showing up twice in search results based around Fitzgerald being in two counties (once for each county). I'm just not sure how the search logic should go if the query is using the typical P131 hierarchy for 1-to-1 city-to-county items (using wdt:P131+), but then have the query switch for 1-to-many items to only display the correct county if the county is declared in the item... I hope that makes sense. As always, thanks in advance for your help! Clifflandis ( talk ) 13:28, 17 February 2021 (UTC) @ Clifflandis : It is possible but the data model using object has role (P3831) next level in hierarchy (Q105528942) as introduced by Mahir256 isn't easy to query and gives rather complicated queries. I found this solution after much work and experimentation: SELECTDISTINCT?organization?organizationLabel?street_address?coordinate_location?phone_number?e_mail_address?website?Facebook_ID?Twitter_username?countyWITH{SELECTDISTINCT?organization?located_in_the_administrative_territorial_entity?countyWHERE{hint:Queryhint:optimizer"None".VALUES(?located_in_the_administrative_territorial_entity?county){(wd:Q486843"Bleckley County")(wd:Q498301"Pulaski County")(wd:Q486791"Wilcox County")(wd:Q115272"Dodge County")(wd:Q691614"Telfair County")(wd:Q498332"Wheeler County")(wd:Q493125"Montgomery County")(wd:Q376822"Toombs County")(wd:Q505310"Tattnall County")(wd:Q111867"Ben Hill County")(wd:Q492057"Irwin County")(wd:Q156503"Coffee County")(wd:Q493071"Jeff Davis County")(wd:Q488186"Appling County")(wd:Q488219"Bacon County")(wd:Q488868"Berrien County")(wd:Q488194"Atkinson County")(wd:Q498353"Ware County")(wd:Q492070"Lanier County")(wd:Q493029"Echols County")(wd:Q486167"Clinch County")}?organizationwdt:P131+?located_in_the_administrative_territorial_entity.FILTERNOT EXISTS{?organizationwdt:P576[].}VALUES?instance_of{wd:Q473972wd:Q3152824wd:Q210272wd:Q570116wd:Q57660343wd:Q2668072wd:Q188913wd:Q15243209wd:Q2867476wd:Q635719wd:Q7840289wd:Q42998wd:Q41710wd:Q51369558}?organizationwdt:P31/wdt:P279*?instance_of.hint:Priorhint:gearing"forward".}}AS%get_organization_and_county_candidatesWITH{SELECT?organization?located_in_the_administrative_territorial_entity?countyWHERE{INCLUDE%get_organization_and_county_candidates# The administrative unit (here county) is mentioned directly in the organization itemFILTEREXISTS{?organizationwdt:P131?located_in_the_administrative_territorial_entity.}}}AS%organizations_with_county_statementWITH{SELECT?organization?located_in_the_administrative_territorial_entity?countyWHERE{INCLUDE%get_organization_and_county_candidates# The administrative unit (here county) is deeper in the P131 hierarchy# AND there is no "next level in hierarchy" qualifier in another P131 statement FILTEREXISTS{?organizationp:P131?P131_statement.?P131_statementps:P131?first_level_adm_unit.?first_level_adm_unitwdt:P131+?located_in_the_administrative_territorial_entity.FILTERNOT EXISTS{?organizationp:P131?another_P131_statement.FILTER(?another_P131_statement!=?P131_statement)?another_P131_statementpq:P3831wd:Q105528942.}}}}AS%organizations_without_county_statementWHERE{{INCLUDE%organizations_with_county_statement}UNION{INCLUDE%organizations_without_county_statement}OPTIONAL{?organizationwdt:P6375?street_address.}OPTIONAL{?organizationwdt:P625?coordinate_location.}OPTIONAL{?organizationwdt:P1329?phone_number.}OPTIONAL{?organizationwdt:P968?e_mail_address.}OPTIONAL{?organizationwdt:P856?website.}OPTIONAL{?organizationwdt:P2013?Facebook_ID.}OPTIONAL{?organizationwdt:P2002?Twitter_username.}SERVICEwikibase:label{bd:serviceParamwikibase:language"en".}}ORDER BY(?organization) Try it! -- Dipsacus fullonum ( talk ) 13:51, 22 February 2021 (UTC) @ Dipsacus fullonum : Thanks for your help with this! I know it's a pain trying to work around the transitive property limitations of P131. I'm going to try rewriting the 168 queries we have for Georgia with this pattern, and hopefully everything will work. I'm a little concerned that this way of doing things makes the queries more likely to break over time, but since listing both the municipality and county at the same time in the P131 is against the rules, my hands are kind of tied. Regardless, thanks again for your tireless help!!! Clifflandis ( talk ) 20:29, 23 February 2021 (UTC) @ Clifflandis : That's many query to rewrite. I am sorry to say it, but I hope that they will break over time as I don't think the use of object has role (P3831) next level in hierarchy (Q105528942) is a good solution. The queries would be simpler and easier with a new qualifier to indicate the next level of hierarchy. The query is so complicated now because the info is spread over two statements. One statement with a qualifier would be easier to handle. -- Dipsacus fullonum ( talk ) 23:42, 23 February 2021 (UTC) @ Dipsacus fullonum : Okay, if this is a bad/inelegant solution, we should come up with a better one. We tried to get this problem addressed before through discussion, with no luck (please see 1 , 2 , 3 , 4 ). Maybe @ Mahir256 : can help since they're an admin. Mahir256, what do you recommend we do next to address this technical problem? Clifflandis ( talk ) 14:29, 24 February 2021 (UTC) The problem is that the layers are not strictly hierarchical. So adding several parallel ones (county and city) to an item is fine. I do find the part with the strings in the query odd though (county names). Why aren't these queried? --- Jura 16:02, 24 February 2021 (UTC) Jura wrote: "So adding several parallel ones (county and city) to an item is fine." No, it is not fine. When you have Blue and Gray Museum (Q16843368) located in the administrative territorial entity (P131) Fitzgerald (Q654046) with no qualifiers to alter the statement and Fitzgerald (Q654046) located in the administrative territorial entity (P131) Irwin County (Q492057) again with no qualifiers, you should be able to conclude that Blue and Gray Museum (Q16843368) also is in Irwin County (Q492057) which isn't the case. That information can be derived from a qualifier in another statement – but qualifiers should only the alter statement where they are placed and not other statements. Two different statements should be independent so one statement's qualifier doesn't affect how another statement should be interpreted. So this data model besides making queries difficult to construct, also is wrong from a data representation viewpoint. -- Dipsacus fullonum ( talk ) 16:27, 24 February 2021 (UTC) The problem in Georgia is that one city can be in several counties. So places are located in one city and a county different from another place in the same city. --- Jura 17:11, 24 February 2021 (UTC) @ Jura1 :, it sounds like @ Dipsacus fullonum : is leaning more toward the proposed solution of a qualifier like was proposed at Wikidata:Property_proposal/hierarchy_switch , as a way to make querying easier. Is that something you could agree to (as a practical, if not philosophical solution)? I've had difficulty trying to build consensus around a solution to this problem in the past, but I'm willing to keep trying until we get there together. Thanks! Clifflandis ( talk ) 13:26, 25 February 2021 (UTC)

──────────────────────────────────────────────────────────────────────────────────────────────────── I marked the proposal at Wikidata:Property_proposal/hierarchy_switch as ready for review/implementation since it's been over a year since it started and about six months since discussion ended, just FYI to folks who are taking part in this broader discussion. I'm trying to be bold, but let me know if that was a premature move. Thanks! Clifflandis ( talk ) 16:29, 26 February 2021 (UTC)

Sure. I'm aware that ruwiki contributors have some issues when using location data in their infoboxes. This is why we get "hierarchy switches" on countless people's place of birth/death etc. As for your Georgia issue, I think the statements would be clearer if "object has role" would just note "county" as value, similar to the approach chosen for Scotland. --- Jura 23:20, 26 February 2021 (UTC)I my opinion it would be a disaster if Jura 's proposal here was implemented. Not only will it make the interpretation of some statements dependent of another statement as it also is with object has role (P3831) next level in hierarchy (Q105528942) . It would also be even more difficult to supply a list of selected administrative units with both counties and municipalities, and then query which items of some kind are located in each of the administrative units in the list. -- Dipsacus fullonum ( talk ) 02:18, 27 February 2021 (UTC) Strange, I don't think I made a proposal to change anything. Nor do I think that Georgia cities are located within a given Georgia county. For territories that overlap, we do have a specific property. --- Jura 08:25, 27 February 2021 (UTC)All articles of a specific Wikipedia with their QIDs and current sitelinks[ edit ]

Hello everyone, I want a query to obtain all articles (no redirect pages) of ckbwiki with their QID and current sitelinks. Thanks, Aram ( talk ) 19:49, 16 February 2021 (UTC)

@ Aram : : something like this ? I don’t know if the redirects are correctly handled. It’s suppose to use the redirect badges but I don’t know if this is up to date yet.

selectdistinct?item?article?name{?articleschema:isPartOf<https://ckb.wikipedia.org/>;schema:about?item;schema:name?nameminus{?articleschema:isPartOf<https://ckb.wikipedia.org/>;wikibase:badge?badge.values?badge{wd:Q70893996wd:Q70894304}}} Try it!

Try it! author    TomT0m / talk page 17:19, 20 February 2021 (UTC)

@ TomT0m : Thank you for your great help! I think it excludes the redirect pages to articles successfully, but the query retrieves other namespaces such as category and template namespaces. Can you make it exclude all namespaces (except articles)? Thank you again! Aram ( talk ) 18:39, 20 February 2021 (UTC) Template:Pinq you are right. The namespace is not easily available in Wikidata, so instead I did this with a quarry querry . This should be more reliable and straightforward, and also catches the articles without items. If the querry is not wrong, this is my first quarry query - could you please double check with the known number of articles in this wiki ? author   TomT0m / talk page 20:55, 20 February 2021 (UTC) @ TomT0m : That's great! I just want another column for article sitelinks. Would be? Aram ( talk ) 20:57, 21 February 2021 (UTC) @ Aram : What do you mean "sitelinks" ? Do you want all articles titles in all wikis corresponding to those articles ? A link to ckbwiki url for the article ? The uris does not seem to actually be stored by the database tables, so if you want this it has to be retrieved from the sparql wikibase endpoint. author   TomT0m / talk page 12:32, 22 February 2021 (UTC) @ TomT0m : Oh, I'm sorry! I want to update all ckbwiki article labels on wikidata. And according to here , I just want the QIDs and the article names. Well done! We'll appreciate it! And Thank you very much! Aram ( talk ) 13:23, 22 February 2021 (UTC)Wikipedia articles with identifier here but no authority control template there[ edit ]

Here’s my attempt at a query to get everything with Internet Encyclopedia of Ukraine ID (P9070) and subtract everything in w:en: Category:Wikipedia articles with IEU identifiers . Some bits are cobbled from examples, but I don’t know how the FILTER BOUND and contents of the MINUS parts work. This times out. Thanks for any advice. — Michael   Z . 16:22, 18 February 2021 (UTC)

# Items with Internet Encyclopedia of Ukraine ID but no IEU identifier in en.WikipediaSELECTDISTINCT?item?itemLabel?itemDescription?IEU_link?enarticleWHERE{BIND('en'AS?lang).BIND(CONCAT(?lang,'.wikipedia.org')AS?project).?itemwdt:P9070?IEU_ID.# item’s IEU IDwd:P9070wdt:P1630?formatterurl.# get its formatter?enarticleschema:about?item;schema:inLanguage?lang;schema:isPartOf<https://en.wikipedia.org/>;schema:name?enname.FILTERBOUND(?enarticle)# Safeguard to not get a timeout from unbound items when using ?enarticle belowMINUS{# en.Wikipedia articles in Category:Wikipedia articles with IEU identifiersSERVICEwikibase:mwapi{bd:serviceParamwikibase:endpoint?project;# Set the project herewikibase:api"Generator";mwapi:generator"categorymembers";# Selects the content from a categorymwapi:gcmtitle"Category:Wikipedia articles with IEU identifiers";.# Specifies the category?enarticlewikibase:apiOutputItemmwapi:item.}}# derive the IEU URLBIND(IRI(REPLACE(REPLACE(?IEU_ID,'\\','\','q'),# percent-encode backslash'^(.+)$',REPLACE(?formatterurl,'\\','\','q')# percent-encode backslash))AS?IEU_link).SERVICEwikibase:label{bd:serviceParamwikibase:language"en,en"}} Try it! @ Mzajac : This seems to work. In your query, what emerges from the MWAPI service is not ?enarticle but ?item. Beyond that, quite why minus was not behaving is beyond me. So I've more struck upon the below as a solution, than arrived at it by deep understanding of SPARQL.# Items with Internet Encyclopedia of Ukraine ID but no IEU identifier in en.WikipediaSELECTDISTINCT?item?itemLabel?itemDescription?IEU_link?enarticlewith{select?item?IEU_link?enarticleWHERE{BIND('en'AS?lang).BIND(CONCAT(?lang,'.wikipedia.org')AS?project).?itemwdt:P9070?IEU_ID.# item’s IEU IDwd:P9070wdt:P1630?formatterurl.# get its formatter?enarticleschema:about?item;schema:inLanguage?lang;schema:isPartOf<https://en.wikipedia.org/>;schema:name?enname.# derive the IEU URLBIND(IRI(REPLACE(REPLACE(?IEU_ID,'\\','\','q'),# percent-encode backslash'^(.+)$',REPLACE(?formatterurl,'\\','\','q')# percent-encode backslash))AS?IEU_link).}}as%iwhere{include%ifilternot exists{select?itemwhere{# en.Wikipedia articles in Category:Wikipedia articles with IEU identifiersSERVICEwikibase:mwapi{bd:serviceParamwikibase:endpoint"en.wikipedia.org";wikibase:api"Generator";mwapi:generator"categorymembers";mwapi:gcmtitle"Category:Wikipedia articles with IEU identifiers";mwapi:gcmprop"ids|title|type";mwapi:gcmlimit"max".# out?itemwikibase:apiOutputItemmwapi:item.}}}FILTERBOUND(?item)# Safeguard to not get a timeout from unbound items SERVICEwikibase:label{bd:serviceParamwikibase:language"en"}} Try it! -- Tagishsimon ( talk ) 03:16, 19 February 2021 (UTC) Thank you! I’d never have managed that. — Michael   Z . 14:35, 19 February 2021 (UTC) @ Mzajac : Au contrete. As you can do the query you did, you can do the query I did. Have you met the query optimization page? -- Tagishsimon ( talk ) 14:56, 19 February 2021 (UTC)Query for events on days or array of years[ edit ]


I'm trying to do an historical research and I'd like to create a query searching for events happened on a specific date (like the "#All events that occured on 2001/09/11" query, that is fine), but also events happened on a specific day regardless the year, or in the same date but within a set of specified years.

I've tried to "merge" the "#All events that occured on 2001/09/11" query with the "#Eventi recenti" one, but with no luck: my knowledge of SPARQL is absolutely zero.


Thank you 08:08, 19 February 2021 (UTC)Marco

Basically, something like that #All events that occured on 09/11 any yearSELECT?item?itemLabelWHERE{?itemwdt:P585?date.filter(day(?date)=9)filter(month(?date)=11)SERVICEwikibase:label{bd:serviceParamwikibase:language"[AUTO_LANGUAGE],en".}} Try it! A bit rough probably, you may want to remove all days themselves, each day has its item and it’s not very interesting, and there is way more ways to add dates on events than just use the date property on an item. But surprisingly it does not timeouts. author   TomT0m / talk page 09:17, 19 February 2021 (UTC)

Seems nice though. Thank you. I'll try to manage the results. 09:32, 19 February 2021 (UTC)Marco

Women and LGBTQ+ Cartoonists with Stub, Start, or C Class Articles on English Wikipedia[ edit ]

Hello. I'm requesting a query of articles about women and LGBTQ+ cartoonists rated stub, start, or C class on English Wikipedia. Thank you. - clickhere21 ( talk ) 22:37, 19 February 2021 (UTC)

For a start, a complete listselect?item?itemLabel?genreLabel?article?badge?badgeLabel{?itemwdt:P31wd:Q5;wdt:P106/wdt:P279*wd:Q266569.optional{?itemwdt:P21?genre}filter(?genre!=wd:Q6581097).SERVICEwikibase:label{bd:serviceParamwikibase:language"[AUTO_LANGUAGE],en".}optional{?articleschema:about?item;schema:isPartOf<https://en.wikipedia.org/>.optional{?articlewikibase:badge?badge}}} . optional {?article wikibase:badge ?badge } } }<]<)+}"> Try it! with the persons without an article on enwiki included, and the one with unknown/without gender on Wikidata. author   TomT0m / talk page 15:35, 20 February 2021 (UTC)Combining with article rate is less easy to do, at least I don’t know how automatically : the categories are on the talk pages, and tools like Petscan could not deal with that last time I checked. author   TomT0m / talk page 15:48, 20 February 2021 (UTC)

@ clickhere21 : I think I managed to find something that works using mwapi though :

selectdistinct?item?itemLabel?genreLabel?article?name(lang(?name)as?lang)?category{?itemwdt:P31wd:Q5;wdt:P106/wdt:P279*wd:Q266569.optional{?itemwdt:P21?genre}filter(?genre!=wd:Q6581097).SERVICEwikibase:label{bd:serviceParamwikibase:language"[AUTO_LANGUAGE],en".}?articleschema:about?item;schema:isPartOf<https://en.wikipedia.org/>;schema:name?name########### find articles by their ratings on enwiki# compute the name of the talk page on enwikibind(concat("Talk:",?name)as?title)# find the categories of the talkpage using mwapiSERVICEwikibase:mwapi{# Categories that contain these pagesbd:serviceParamwikibase:api"Categories";wikibase:endpoint"en.wikipedia.org";mwapi:titles?title.# Output the page title and category#?otitle wikibase:apiOutput mwapi:title.?categorywikibase:apiOutputmwapi:category.}values?category{#### add relevant (sub?)categories if needed "Category:Start-Class biography articles""Category:Stub-Class biography articles""Category:C-Class biography articles"}} ; schema:name ?name ########### find articles by their ratings on enwiki # compute the name of the talk page on enwiki bind (concat("Talk:", ?name) as ?title) # find the categories of the talkpage using mwapi SERVICE wikibase:mwapi { # Categories that contain these pages bd:serviceParam wikibase:api "Categories"; wikibase:endpoint "en.wikipedia.org"; mwapi:titles ?title. # Output the page title and category #?otitle wikibase:apiOutput mwapi:title. ?category wikibase:apiOutput mwapi:category . } values ?category { #### add relevant (sub?)categories if needed "Category:Start-Class biography articles" "Category:Stub-Class biography articles" "Category:C-Class biography articles" } }<]<)+}"> Try it!

It might not work if some biographies are in subcategories of "Category:Start-Class biography articles" or the like, however. If it’s needed, there is a solution to this problem in a request above, so please ask. author    TomT0m / talk page 16:51, 20 February 2021 (UTC)

Sweet. -- Tagishsimon ( talk ) 17:32, 20 February 2021 (UTC)A second version to avoid the « distinct » select?item?itemLabel?genreLabel?article?name(lang(?name)as?lang)?category{?itemwdt:P31wd:Q5;wdt:P106/wdt:P279*wd:Q266569.optional{?itemwdt:P21?genre}filter(?genre!=wd:Q6581097).SERVICEwikibase:label{bd:serviceParamwikibase:language"[AUTO_LANGUAGE],en".}?articleschema:about?item;schema:isPartOf<https://en.wikipedia.org/>;schema:name?name########### find articles by their ratings on enwiki# compute the name of the talk page on enwikibind(concat("Talk:",?name)as?title)# find the categories of the talkpage using mwapiSERVICEwikibase:mwapi{# Categories that contain these pagesbd:serviceParamwikibase:api"Categories";wikibase:endpoint"en.wikipedia.org";mwapi:titles?title.# Output the page title and category?ocategorywikibase:apiOutputmwapi:category.}values?category{#### add relevant (sub?)categories if needed "Category:Start-Class biography articles""Category:Stub-Class biography articles""Category:C-Class biography articles"}filter(?category=?ocategory)} ; schema:name ?name ########### find articles by their ratings on enwiki # compute the name of the talk page on enwiki bind (concat("Talk:", ?name) as ?title) # find the categories of the talkpage using mwapi SERVICE wikibase:mwapi { # Categories that contain these pages bd:serviceParam wikibase:api "Categories"; wikibase:endpoint "en.wikipedia.org"; mwapi:titles ?title. # Output the page title and category ?ocategory wikibase:apiOutput mwapi:category . } values ?category { #### add relevant (sub?)categories if needed "Category:Start-Class biography articles" "Category:Stub-Class biography articles" "Category:C-Class biography articles" } filter (?category = ?ocategory) }<]<)+}"> Try it! author   TomT0m / talk page 11:39, 22 February 2021 (UTC) Wikimedia Commons Query Service [ edit ]Hi, I would want a query showing all the images depicting items that are instance of (P31) type specimen (Q51255340) , exemple: c:File:MA I317916 TePapa Diplodontias-robustus full.jpg depicts (P180) NMNZ EC.000109 (Q105585285) and showing only the items are coming from a specific collection, exemple: NMNZ EC.000109 (Q105585285) collection (P195) Museum of New Zealand Te Papa Tongarewa (Q915603) and if possible givin the values of the following property and qualifier: NMNZ EC.000109 (Q105585285) subject has role (P2868) **** of (P642) **** Christian Ferrer

Christian Ferrer ( talk ) 15:18, 21 February 2021 (UTC)

@ Christian Ferrer : There are 10 items in WDQS which meet your conditions, but currently no images in WCQS which depicts these items. This query finds the items and would show the files if there were any. I see that you edited the structured data for c:File:MA I317916 TePapa Diplodontias-robustus full.jpg two days ago, so it should be in the results after the next weekly update of WCQS. SELECT?file?item?itemLabel?role?roleLabel?for?forLabelWITH{# Get items for type specimens at Museum of New Zealand Te Papa Tongarewa from WDQSSELECT?item?itemLabel?role?roleLabel?for?forLabelWHERE{SERVICE<https://query.wikidata.org/sparql>{?itemwdt:P31wd:Q51255340.# Item is a type specimen?itemwdt:P195wd:Q915603.# Collection is Museum of New Zealand Te Papa TongarewaOPTIONAL{?itemp:P2868?stat.?statps:P2868?role.?statpq:P642?for.}SERVICEwikibase:label{bd:serviceParamwikibase:language"[AUTO_LANGUAGE],en".?itemrdfs:label?itemLabel.?rolerdfs:label?roleLabel.?forrdfs:label?forLabel.}}}}AS%get_items{INCLUDE%get_itemsOPTIONAL{?filewdt:P180?item.}} Try it! -- Dipsacus fullonum ( talk ) 17:12, 21 February 2021 (UTC)My version, all results but decomment the « values » section to include only one or several specific collections #defaultView:ImageGridSELECT?file?image?stype?stypeLabel?collec?collecLabel?role?roleLabel?de?deLabelwith{select?stype?stypeLabel?collec?collecLabel?role?de?roleLabel?deLabel{service<https://query.wikidata.org/sparql>{select?stype?stypeLabel?collec?collecLabel?role?de?roleLabel?deLabel{?stypewdt:P31/wdt:P279*wd:Q51255340SERVICEwikibase:label{bd:serviceParamwikibase:language"[AUTO_LANGUAGE],en".}optional{?stypewdt:P195?collec.}optional{?stypep:P2868[ps:P2868?role;pq:P642?de]}#enlevez les # au dessous pour préciser une ou des collections#values ?collec {# wd:Q122945 # exemple avec le Yale Peabody Museum of Natural History #}}}}}as%typesWHERE{?filewdt:P180?stype;schema:contentUrl?url.bind(iri(concat("http://commons.wikimedia.org/wiki/Special:FilePath/",replace(substr(str(?url),53),"_"," ")))AS?image).#?file wdt:P180 wd:Q105607273 .include%types} Try it! @ Dipsacus fullonum : hi, thanks you. The second query you give don't show results, and I'm not able to undesrtand it. For the first I did not know that there is a delay, so with a different collection we can get some resuls. However is there a way to display a gallery instead of a table? Christian Ferrer ( talk ) 17:45, 21 February 2021 (UTC) @ Christian Ferrer : Check mine, it did not work because I did forget to use the right endpoint in the template, but it should be OK now. author   TomT0m / talk page 17:50, 21 February 2021 (UTC) Yes excelent, thanks you. you did not sign so I was thinking the second query was made by Dipsacus fullonum. Yes the query works well and we can filter the results by collection e.g. with Yale Peabody Museum of Natural History (Q122945) , and that works well too. Great. Christian Ferrer ( talk ) 18:00, 21 February 2021 (UTC)@ Christian Ferrer : See c:Commons:SPARQL query service for the delay. I qoute: "The service is a beta endpoint that is updated via weekly dumps. ... The data will be reloaded weekly on Mondays from dumps taken on Sunday." -- Dipsacus fullonum ( talk ) 18:05, 21 February 2021 (UTC)PS. I can add that I didn't use an image grid because there were no images anyway for the selected collection. -- Dipsacus fullonum ( talk ) 18:14, 21 February 2021 (UTC)@ TomT0m : is it possible also to filter the type specimens of a specific taxon and of his child taxa? e.g. all the images depicting items of types specimens of Brachypoda (Q15711568) (and of its children). The relation parent/child is done with parent taxon (P171) , so I guess it is with a thing like that:wdt:P171/wdt:P171* wd:Q15711568 Christian Ferrer ( talk ) 18:35, 21 February 2021 (UTC) Sure @ Christian Ferrer :, you’re almost right the line should be ?de wdt:P171* wd:Q15711568 as you want to keep the parent taxon (your one selected only its children, not the parent itself): #defaultView:ImageGridSELECT?file?image?stype?stypeLabel?collec?collecLabel?role?roleLabel?de?deLabelwith{select?stype?stypeLabel?collec?collecLabel?role?de?roleLabel?deLabel{service<https://query.wikidata.org/sparql>{select?stype?stypeLabel?collec?collecLabel?role?de?roleLabel?deLabel{?stypewdt:P31/wdt:P279*wd:Q51255340SERVICEwikibase:label{bd:serviceParamwikibase:language"[AUTO_LANGUAGE],en".}optional{?stypewdt:P195?collec.}?stypep:P2868[ps:P2868?role;pq:P642?de].#enlevez les # au dessous pour préciser une ou des collections#values ?collec {# wd:Q122945 # exemple avec le Yale Peabody Museum of Natural History #}?dewdt:P171*wd:Q15711568.# choisir un taxon dont on cherche les types, incluant les types de ses sous-taxons}}}}as%typesWHERE{?filewdt:P180?stype;schema:contentUrl?url.bind(iri(concat("http://commons.wikimedia.org/wiki/Special:FilePath/",replace(substr(str(?url),53),"_"," ")))AS?image).#?file wdt:P180 wd:Q105607273 .include%types} Try it! author   TomT0m / talk page 11:21, 22 February 2021 (UTC)@ TomT0m : thanks, but it seems there is something wrong as there is no result, I chose that taxon because we should have at least two results c:File:Hutchinsoniella macracantha (YPM IZ 003617.CR) 002.jpeg and c:File:Hutchinsoniella macracantha (YPM IZ 003617.CR) 001.jpeg . Christian Ferrer ( talk ) 11:42, 22 February 2021 (UTC) (I’ll learn at some point) Problem in the template call, wrong sparql endpoint :) should be OK now @ Christian Ferrer : author   TomT0m / talk page 11:44, 22 February 2021 (UTC)@ TomT0m : Excellent, thanks you. Structured data for Commons has a great potential(and Wikidata in general), it is likely one of the most powerfull toll available to the public in the WEB, if not the most powerfull tool, to sort and find images. It lacks only the data on the files, and the imagination of those who make the requests will do the rest . Christian Ferrer ( talk ) 11:53, 22 February 2021 (UTC)Match a string in the description[ edit ]

I haven't been able to find an example query that does this. I want to find all instances of human that have "recusant" in the description. Can we do this? - PKM ( talk ) 21:49, 22 February 2021 (UTC)

Search for "haswbstatement:P31=Q5 recusant". You can use the normal search special page ( https://www.wikidata.org/w/index.php?search=haswbstatement:P31=Q5+recusant&title=Special:Search&ns0=1 ) or make a SPARQL query with a MWAPI call to do the search.@ PKM : I forgot my signature above. There is an example of MWAPI search at Wikidata:SPARQL query service/query optimization#Searching labels . Just change the search string to haswbstatement:P31=Q5 recusant and replace rdfs:label in the example with schema:description to search for descriptions instead of labels. -- Dipsacus fullonum ( talk ) 22:30, 22 February 2021 (UTC) @ Dipsacus fullonum : perfect, thanks! - PKM ( talk ) 22:33, 22 February 2021 (UTC)Question[ edit ]

I don't know why I have 126 results in the first query and 33 in the second for (wdt:P1037|wdt:P169|wdt:P8938) ?direction . Someone can explain this to me? I try to get all the direction entries and know the percentages of them who are male and female. Simon Villeneuve ( talk ) 14:51, 23 February 2021 (UTC)

SELECT?item?itemLabel?directionLabel?directionWHERE{?item?ppp?statement.?propertyawikibase:Property;wikibase:claim?ppp.?statement?qqq?value.?property2awikibase:Property;wikibase:statementProperty?qqq.?statementprov:wasDerivedFrom?autre_statement.#d'après la source ...?autre_statementpr:P248wd:Q100443909.SERVICEwikibase:label{bd:serviceParamwikibase:language"[AUTO_LANGUAGE],en".}?itemwdt:P31/wdt:P279*wd:Q43229;(wdt:P1037|wdt:P169|wdt:P8938)?direction.} Try it! #Tous les éléments distincts sourcés avec le CQT avec les pourcentages de certaines natures, pays, naissance, etc..SELECT(COUNT(DISTINCT?item)AS?total)(COUNT(DISTINCT?membre_CQT)AS?est_membre_CQT)(?est_membre_CQT/?total*100.0AS?pct_membre_CQT)(COUNT(DISTINCT?item_a_pays)AS?a_pays)(?a_pays/?total*100.0AS?pct_pays)(COUNT(DISTINCT?item_a_image)AS?a_image)(?a_image/?total*100.0AS?pct_image)(COUNT(DISTINCT?item_est_géolocalisé)AS?est_géolocalisé)(?est_géolocalisé/?total*100.0AS?pct_géolocalisé)(COUNT(DISTINCT?item_est_organisation)AS?est_organisation)(?est_organisation/?total*100.0AS?pct_organisation)(COUNT(?organisation_a_direction)AS?a_direction)(?a_direction/?est_organisation*100.0AS?pct_direction)(COUNT(DISTINCT?directionféminin)AS?direction_féminin)(?direction_féminin/?a_direction*100.0AS?pct_direction_féminin)(COUNT(DISTINCT?directionmasculin)AS?direction_masculin)(?direction_masculin/?a_direction*100.0AS?pct_direction_masculin)(COUNT(DISTINCT?item_est_oeuvre)AS?est_oeuvre)(?est_oeuvre/?total*100.0AS?pct_oeuvre)(COUNT(?item_est_humain)AS?est_humain)(?est_humain/?total*100.0AS?pct_humain)(COUNT(?item_est_féminin)AS?est_féminin)(?est_féminin/?est_humain*100.0AS?pct_féminin)(COUNT(?item_est_masculin)AS?est_masculin)(?est_masculin/?est_humain*100.0AS?pct_masculin)(COUNT(?item_est_nonsexué)AS?est_nonsexué)(?est_nonsexué/?est_humain*100.0AS?pct_nonsexué)#non précisé(COUNT(DISTINCT?item_a_naissance)AS?a_naissance)(?a_naissance/?est_humain*100.0AS?pct_naissance)(COUNT(DISTINCT?item_a_mort)AS?est_mort)(?est_mort/?est_humain*100.0AS?pct_mort)(COUNT(DISTINCT?date_décennie)AS?a_décennie)(?a_décennie/?est_humain*100.0AS?pct_décennie)(COUNT(DISTINCT?occupation)AS?a_occupation)(?a_occupation/?est_humain*100.0AS?pct_occupation)(COUNT(DISTINCT?fonction)AS?a_fonction)(?a_fonction/?est_humain*100.0AS?pct_fonction)(COUNT(DISTINCT?item_a_langueoeuvre)AS?a_langueoeuvre)(?a_langueoeuvre/?est_oeuvre*100.0AS?pct_langue)(COUNT(DISTINCT?oeuvre_est_fr)AS?est_fr)(?est_fr/?est_oeuvre*100.0AS?pct_fr)(COUNT(DISTINCT?oeuvre_est_en)AS?est_en)(?est_en/?est_oeuvre*100.0AS?pct_en)WITH{SELECTDISTINCT?itemWHERE{# Trouver les éléments avec le CQT en référence?autre_statementpr:P248wd:Q100443909.?statementprov:wasDerivedFrom?autre_statement.# Quelles propriétés sont sourcées par le CQT?propertyawikibase:Property;wikibase:claim?ppp.?item?ppp?statement.}}AS%items_CQTWHERE{INCLUDE%items_CQTOPTIONAL{?itemwdt:P463wd:Q64402570.BIND(?itemAS?membre_CQT)}OPTIONAL{?item(wdt:P17|wdt:P27)?pays.BIND(?itemAS?item_a_pays)}OPTIONAL{?itemwdt:P18?image.BIND(?itemAS?item_a_image)}OPTIONAL{?itemwdt:P625?géolocalisé.BIND(?itemAS?item_est_géolocalisé)}OPTIONAL{?itemwdt:P31/wdt:P279*wd:Q43229.hint:Priorhint:gearing"forward".BIND(?itemAS?item_est_organisation)}OPTIONAL{?itemwdt:P31/wdt:P279*wd:Q43229;(wdt:P1037|wdt:P169|wdt:P8938)?direction.BIND(?itemAS?organisation_a_direction)}OPTIONAL{?itemwdt:P31/wdt:P279*wd:Q43229;(wdt:P1037|wdt:P169|wdt:P8938)?direction.?directionwdt:P21wd:Q6581072.BIND(?itemAS?directionféminin)}OPTIONAL{?itemwdt:P31/wdt:P279*wd:Q43229;(wdt:P1037|wdt:P169|wdt:P8938)?direction.?directionwdt:P21wd:Q6581097.BIND(?itemAS?directionmasculin)}OPTIONAL{?itemwdt:P31/wdt:P279*wd:Q386724.hint:Priorhint:gearing"forward".BIND(?itemAS?item_est_oeuvre)}OPTIONAL{?itemwdt:P31wd:Q5.BIND(trueAS?item_est_humain)}OPTIONAL{?itemwdt:P31wd:Q5.minus{?itemwdt:P21?sexe.}BIND(trueAS?item_est_nonsexué)}OPTIONAL{?itemwdt:P21wd:Q6581072.BIND(trueAS?item_est_féminin)}OPTIONAL{?itemwdt:P21wd:Q6581097.BIND(trueAS?item_est_masculin)}OPTIONAL{?itemwdt:P569?naissance.BIND(?itemAS?item_a_naissance)}OPTIONAL{?itemwdt:P570?mort.BIND(?itemAS?item_a_mort)}OPTIONAL{?item(p:P569/psv:P569|p:P570/psv:P570)[wikibase:timePrecision?datePrecision;wikibase:timeValue?naissance].filter(?datePrecision=8)BIND(?itemAS?date_décennie)}OPTIONAL{?itemwdt:P106?occupation.BIND(?itemAS?item_a_occupation)}OPTIONAL{?itemwdt:P39?fonction.BIND(?itemAS?item_a_fonction)}OPTIONAL{?itemwdt:P407?langueoeuvre.BIND(?itemAS?item_a_langueoeuvre)}OPTIONAL{?itemwdt:P407wd:Q150.BIND(?itemAS?oeuvre_est_fr)}OPTIONAL{?itemwdt:P407wd:Q1860.BIND(?itemAS?oeuvre_est_en)}} Try it! Note that while the first query do have 126 results, there are only 11 distinct results. There are many duplicate results because the (few) found items each have many statements with CQT used as reference. -- Dipsacus fullonum ( talk ) 16:36, 23 February 2021 (UTC) Thank you for your answer. I knew there was undistinct results. I thought that without DISTINCT, the 2 queries will give me the same number of undistincts results, but it's not the case. Simon Villeneuve ( talk ) 14:20, 24 February 2021 (UTC) @ Simon Villeneuve : The two queries find the same 7 distinct items for organizations which have statements using CQT as reference and values for ?direction, but the undistinct numbers are different in the two queries. The first query finds the 7 items multiple times. The seconds finds the items with CQT references only once due the use "distinct" in the subquery, but then the optional patterns in main query causes duplication of the items in the results. -- Dipsacus fullonum ( talk ) 14:55, 24 February 2021 (UTC)The First Human and the Label Service: What's going on here?[ edit ]

Not sure if this is the best place to ask, don't recall seeing this being mentioned before but something strange seems to be happening with the Label Service in the follow query:

The following query uses these:

Items: human (Q5)    View with Reasonator   View with SQID Properties: instance of (P31)    View with Reasonator   View with SQID SELECT?x?xLabelWHERE{?xwdt:P31wd:Q5.SERVICEwikibase:label{bd:serviceParamwikibase:language"[AUTO_LANGUAGE],en".}}LIMIT1 Try it!

I would expect George Washington to return almost immediately but 1) It takes a long time to run, sometimes even times out 2) It's not returning George Washington The following works as expected:

The following query uses these:

Items: human (Q5)    View with Reasonator   View with SQID Properties: instance of (P31)    View with Reasonator   View with SQID SELECT?x?xLabelWHERE{?xwdt:P31wd:Q5.?xrdfs:label?xLabel.FILTER(LANG(?xLabel)="en")}LIMIT1 Try it! Piecesofuk

Piecesofuk ( talk ) 17:53, 23 February 2021 (UTC)

@ Piecesofuk : The problem is that the label service is applied before the limit so many labels are found. You can optimize the query by using a standard subquery: SELECT?x?xLabelWHERE{{SELECT?xWHERE{?xwdt:P31wd:Q5.}LIMIT1}SERVICEwikibase:label{bd:serviceParamwikibase:language"[AUTO_LANGUAGE],en".}} Try it! You can also use a named subquery. It isn't standard SPARQL, but a little faster: SELECT?x?xLabelWITH{SELECT?xWHERE{?xwdt:P31wd:Q5.}LIMIT1}AS%1WHERE{INCLUDE%1SERVICEwikibase:label{bd:serviceParamwikibase:language"[AUTO_LANGUAGE],en".}} Try it! By the way, you shouldn't expect the result to be George Washington. There is no guaranteed order of query results and any entity with a truthy P31 Q5 statement can be returned. -- Dipsacus fullonum ( talk ) 23:17, 23 February 2021 (UTC) Thanks for the reply, surprised that there is no guaranteed order, I've always assumed there was, must remember that. What was really weird was that the label service usually returned the same item Mikhail Bulgakov (Q835) , but sometimes it returned a deleted lexeme invalid ID (L411867) Piecesofuk ( talk ) 07:00, 24 February 2021 (UTC)@ Dipsacus fullonum : actually when I try both your queries they're returning that deleted lexeme!? Piecesofuk ( talk ) 07:04, 24 February 2021 (UTC) @ Piecesofuk : There are deleted entities (items and lexemes) which remain in the query service because there is bug in the WDQS updating system at the moment so entities aren't automatically removed from WCQS when deleted but have to be manually removed at regular intervals. It is discussed in the thread Wikidata:Contact the development team/Query Service and search#Q104776498 deleted but still on WQS (2021-02-14) . -- Dipsacus fullonum ( talk ) 07:56, 24 February 2021 (UTC) Ah ok, thanks. I just "DESCRIBE"d it and see it does have P31 Q5 Piecesofuk ( talk ) 08:09, 24 February 2021 (UTC)Items satisfying one property statement, but not having one qualifier[ edit ]

Example: English alphabets (part of Q754673) items not having unicodehex (P4213) as qualifiers in the item page Vis M ( talk ) 09:13, 24 February 2021 (UTC)

@ Vis M : # Unicode characters for parts of English Alphabet without Unicode hex codepoint qualifierSElECT?item?itemLabel?unicode_character?unicode_character_statementWHERE{?itemwdt:P361wd:Q754673.# ?item is part of English Alphabet?itemp:P487?unicode_character_statement.?unicode_character_statementps:P487?unicode_character.MINUS{?unicode_character_statementpq:P4213[].}# Only results without Unicode hex codepoint qualifierSERVICEwikibase:label{bd:serviceParamwikibase:language"en".}} Try it! -- Dipsacus fullonum ( talk ) 09:30, 24 February 2021 (UTC) Thank you very much!! Vis M ( talk ) 10:12, 24 February 2021 (UTC)Query not returning data for one object out of thousands[ edit ]

Hi, I am looking for objects based on their Netflix ID (P1874) returning their title (P1476) and if available also IMDb ID (P345) , Rotten Tomatoes ID (P1258) and Metacritic ID (P1712) . Query provided below works for over a year and provided correct data to over few thousands of queries/objects and Space Sweepers (Q65267432) is the first object that I found, that contains data (in this case IMDb ID (P345) ) that I am trying to get, but query will not return them. Just to clarify, query still works with only exception of Space Sweepers (Q65267432) object. Is there an error in my query that I don't see? I am quite new to SPARQL so if you see any way how to make this shorter/more optimal I am open for suggestions. Thank you.

SELECT(?itemAS?url)(COALESCE(?title,"")AS?title)(COALESCE(?idIMDB,"N/A")AS?idIMDB)(COALESCE(?idRT,"N/A")AS?idRT)(COALESCE(?idMETA,"N/A")AS?idMETA)WHERE{?itemwdt:P1874"81094067".OPTIONAL{?itemwdt:P1476?title.}OPTIONAL{?itemwdt:P345?idIMDB.}OPTIONAL{?itemwdt:P1258?idRT.}OPTIONAL{?itemwdt:P1712?idMETA.}} Try it! KayaNatsumi

KayaNatsumi ( talk ) 10:19, 24 February 2021 (UTC)

@ KayaNatsumi : When you use predicates with the prefix wdt: you only get values of "best rank", i.e. the values of preferred rank if any exist, and else the values of normal rank. You will never get results of deprecated rank. The value for IMDb ID (P345) in Space Sweepers (Q65267432) has deprecated rank. That is why your query doesn't return it. Use p:P345/ps:P345 to get all results independent of rank. -- Dipsacus fullonum ( talk ) 10:36, 24 February 2021 (UTC)@ Dipsacus fullonum : Amazing! It works. Is there some manual/guide page that I could read about wdt and p/ps to understand it better? Again, thank you for help. KayaNatsumi ( talk ) 11:11, 24 February 2021 (UTC) @ KayaNatsumi : Yes, it is described in mw:Wikibase/Indexing/RDF Dump Format . -- Dipsacus fullonum ( talk ) 11:20, 24 February 2021 (UTC)

-- 16:52, 24 February 2021 (UTC)

Bilingual URL-syntaxes for Yle Topic ID P8309[ edit ]


I am trying to query items which have a Yle ID (Finnish public broadcaster company) to get the link to the topic on Yle's page. Yle has two URL-syntaxes, one for articles in Finnish and one for Swedish.

This wikidata SPARQL-query

This wikidata SPARQL-query for all objects with P8309 only gives the Yle-iID without any URL at all. How can I query so that it gives me the full URL to both the Swedish and Finnish articles for each item?

For example Finland's president Niinistö has articles in Finnish at https://yle.fi/aihe/t/18-194072 and in Swedish at https://svenska.yle.fi/t/18-194072 - both have the same ID.

Those URL-syntaxes are defined at Yle Topic ID P8309 with URL Format P1630 which has two separate entries for URL-syntax for language P407 Finnish and Swedish.

However, at Niinistös wikidata-object you will see that he only has a link to the Finnish URL for P8309. How can I get the Swedish URL to be shown here too? Is this set up correctly, or is this a "bug" in the wikidata.org UI?

Thank you for help with this! Robertsilen ( talk ) 09:25, 26 February 2021 (UTC)

@ Robertsilen : You can get links to the Swedish and Finnish pages with this query. I cannot answer the second question. # all objects with a YLE-ID P8309 definedSELECT?item?itemLabel?yleid?link_fi?link_svWHERE{?itemwdt:P8309?yleid.BIND(URI(CONCAT("https://yle.fi/aihe/t/",?yleid))AS?link_fi)BIND(URI(CONCAT("https://svenska.yle.fi/t/",?yleid))AS?link_sv)SERVICEwikibase:label{bd:serviceParamwikibase:language"[AUTO_LANGUAGE],sv,fi,en".}} Try it! -- Dipsacus fullonum ( talk ) 10:20, 26 February 2021 (UTC)Updating data that was imported in 2018/ adding references[ edit ]


I hope this message finds you well. Being an intern at Kunstenpunt, an organization that imported its database in 2018, I am to update some of that data and add references to some of the properties that have been created in 2018. To do so, I need to make sure those properties were not edited by someone else to make sure of the integrity of the data that I want to make changes to. I have been trying to do this using schema: dateModified feature of sparql language in Wikidata query service. However, the data that I receive is in conflict with the items's Wikidata history page. Here is the query I have been trying out:

SELECT?itemLabel?countryLabel?changeWHERE{?itemwdt:P5164?id;wdt:P17?country.?countryschema:dateModified?change.SERVICEwikibase:label{bd:serviceParamwikibase:language"[AUTO_LANGUAGE],nl,en".}} Try it!

I do not know where the problem is. I would appreciate any form of feedback. Thank you very much.

Hello. The schema:dateModified predicate tells the date of the latest change to an entity, so your query gives dates for when the country entities was last changed. If you instead want to know when the entities bound to ?item was last changed, use ?item schema:dateModified ?change. You cannot query when a single statement was last changed. It is only recorded at the entity level. So you have to compare a statement to previous known value to find out if it is changed. -- Dipsacus fullonum ( talk ) 17:36, 26 February 2021 (UTC)Alumnae/alumni query[ edit ]

Dear people. I would like a query that lists people who were educated at (P69) at any university in Canada and also educated at any university in Belgium. People with degrees from both of these countries. Thank you!-- Jetam2 ( talk ) 19:45, 26 February 2021 (UTC)

@ Jetam2 : should be something like that selectdistinct?person?personLabel?universityCanada?universityCanadaLabel?universityBelgium?universityBelgiumLabel{?personwdt:P69?universityCanada,?universityBelgium.?universityCanadawdt:P31/wdt:P279*wd:Q3918;wdt:P17wd:Q16.?universityBelgiumwdt:P31/wdt:P279*wd:Q3918;wdt:P17wd:Q31.SERVICEwikibase:label{bd:serviceParamwikibase:language"[AUTO_LANGUAGE],en".}} Try it! May not work if some school is not a university … please if you notice any miss come back ! author   TomT0m / talk page 20:40, 26 February 2021 (UTC)@ Jetam2 : Slightly different take from me, dealing with the issue of individuals who went to two BE or CA institutions and which show up in TomT0m's query as duplicate rows. Sadly mine will give duplicate rows if someone went to three BE or CA institutions, so it's not a very good solution.SELECTdistinct?item?itemLabel?university_beLabel?university_be2Label?university_caLabel?university_ca2Labelwith{SELECT?item?university_be?university_be2?university_ca?university_ca2WHERE{?itemwdt:P69?university_ca.?itemwdt:P69?university_be.?university_bewdt:P17wd:Q31.?university_cawdt:P17wd:Q16.optional{?itemwdt:P69?university_be2.?university_be2wdt:P17wd:Q31.?university_be2wdt:P31/wdt:P279*wd:Q3918.filter(str(?university_be2)>str(?university_be))}optional{?itemwdt:P69?university_ca2.?university_ca2wdt:P17wd:Q16.?university_ca2wdt:P31/wdt:P279*wd:Q3918.filter(str(?university_ca2)>str(?university_ca))}}}as%iwhere{include%ifilternot exists{?itemwdt:P69?university_bez.?university_bezwdt:P17wd:Q31.filter(str(?university_bez)<str(?university_be))}filternot exists{?itemwdt:P69?university_caz.?university_cazwdt:P17wd:Q16.filter(str(?university_caz)<str(?university_ca))}SERVICEwikibase:label{bd:serviceParamwikibase:language"[AUTO_LANGUAGE],en".}?university_bewdt:P31/wdt:P279*wd:Q3918.?university_cawdt:P31/wdt:P279*wd:Q3918.} Try it! -- Tagishsimon ( talk ) 20:51, 26 February 2021 (UTC) One solution could be to forget the universities :) author   TomT0m / talk page 21:02, 26 February 2021 (UTC)@ Tagishsimon , Jetam2 : With a default tree view (same for a graph) it’s easier to get rid of the duplicates #defaultView:Treeselect?person?personLabel?university?universityLabel?country?countryLabelwith{selectdistinct?person{?personwdt:P69?universityCanada,?universityBelgium.?universityCanadawdt:P31/wdt:P279*wd:Q3918;wdt:P17wd:Q16.?universityBelgiumwdt:P31/wdt:P279*wd:Q3918;wdt:P17wd:Q31.SERVICEwikibase:label{bd:serviceParamwikibase:language"[AUTO_LANGUAGE],en".}}}as%personwith{select?person?university?country{include%person?personwdt:P69?university.?universitywdt:P17?country.}}as%results{include%results.SERVICEwikibase:label{bd:serviceParamwikibase:language"[AUTO_LANGUAGE],en".}} Try it! a group_concat on the labels (with losing the university items) could do the trick as well with the university label. One other solution could be to use a « sparql construct » to output a rdf graph but as far as I know there is not wmuch interesting visualisations for rdf graphs in the query service. author   TomT0m / talk page 21:43, 26 February 2021 (UTC)@ TomT0m , Tagishsimon :Thank you very much!-- Jetam2 ( talk ) 04:58, 27 February 2021 (UTC)Finding the Wikipedia URL[ edit ]

Hello, I have the following functioning query:

SELECT?build?buildLabel?countryLabel?placeLabel?heritLabel?location# gives the archaeological sites around AvignonWHERE{SERVICEwikibase:box{?buildwdt:P625?location.bd:serviceParamwikibase:cornerWest"Point(4.29 43.6)"^^geo:wktLiteral.bd:serviceParamwikibase:cornerEast"Point(5.31 44.3)"^^geo:wktLiteral.}# bbox for Avignon map?buildwdt:P31/wdt:P279*wd:Q839954.# a buildingOPTIONAL{?buildwdt:P17?country.}OPTIONAL{?buildwdt:P131?place.}OPTIONAL{?buildwdt:P1435?herit.}SERVICEwikibase:label{bd:serviceParamwikibase:language"en".}#SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE]". }} Try it!

The output gives me Wikidata URLs such as:


Question: is there a way to have the URL of the Wikipedia entry included (provided there is one)?

Many thanks, tiha

Hi. You can use this query with one more OPTIONAL clause added assuming you mean the English Wikipedia: SELECTDISTINCT?build?buildLabel?countryLabel?placeLabel?heritLabel?location?wikipedia# gives the archaeological sites around AvignonWHERE{SERVICEwikibase:box{?buildwdt:P625?location.bd:serviceParamwikibase:cornerWest"Point(4.29 43.6)"^^geo:wktLiteral.bd:serviceParamwikibase:cornerEast"Point(5.31 44.3)"^^geo:wktLiteral.}# bbox for Avignon map?buildwdt:P31/wdt:P279*wd:Q839954.# a buildingOPTIONAL{?buildwdt:P17?country.}OPTIONAL{?buildwdt:P131?place.}OPTIONAL{?buildwdt:P1435?herit.}OPTIONAL{?wikipediaschema:about?build.?wikipediaschema:isPartOf<https://en.wikipedia.org/>.}SERVICEwikibase:label{bd:serviceParamwikibase:language"en".}#SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE]". }} . } SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } #SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE]". } }<]<)+}"> Try it! -- Dipsacus fullonum ( talk ) 10:25, 27 February 2021 (UTC)

Many thanks: this works perfectly. tiha

Wikidata query into page map[ edit ]

Hi! I've created this wikiquery to gather all the segments of the London Wall together, however, am finding it difficult to understand how to edit it to function as a map based on the en:Template:Graph:Street map with marks page. I would be extremely grateful if anyone knew how to adapt this into a useable map!

#DefaultView:MapSELECT?London_Wall?London_WallLabel?instance_of?instance_ofLabel?coordinate_location?heritage_designation?heritage_designationLabel?imageWHERE{SERVICEwikibase:label{bd:serviceParamwikibase:language"[AUTO_LANGUAGE],en".}?London_Wallwdt:P361wd:Q60308.OPTIONAL{?London_Wallwdt:P31?instance_of.}OPTIONAL{?London_Wallwdt:P625?coordinate_location.}OPTIONAL{?London_Wallwdt:P1435?heritage_designation.}OPTIONAL{?London_Wallwdt:P18?image.}}LIMIT100 Try it! Jamzze

Jamzze ( talk ) 09:08, 27 February 2021 (UTC)

@ Jamzze : If you just want the map and not an inclusion into a wikipage it is trivial work : something like that ? https://w.wiki/32tT (I just added a line #defaultView:Map. author   TomT0m / talk page 10:57, 27 February 2021 (UTC)If not, I got a beginning of stuff that works on a sandbox on enwiki . Did not manage to make the image works yet but the texts could in principle work. author   TomT0m / talk page 11:57, 27 February 2021 (UTC) TomT0m

TomT0m - blimey thank you so much! That map is great! Yeah trying to create a map for the page so people can see the individual locations of the ruins. As the London Wall is no longer a wall anymore, rather a collection of broken walls, it would be great to have a map that showed this. With what you linked to, can I add that straight to the page under the infoxbox? Best, Jamzze ( talk ) 12:51, 27 February 2021 (UTC)

@ Jamzze : Maybe you can try copypasting something like that ?

See source Wikidata query .. See this map in big, interactive, with illustrations and more

author   TomT0m / talk page 14:39, 27 February 2021 (UTC) TomT0m

TomT0m - thank you so much this is perfect! I am not used to the language of this, how would I position this to the right on the page?

Would it be possible to add this to an infox box?

Thank you again for all your help! Jamzze ( talk ) 15:29, 27 February 2021 (UTC)

Excellent. Good to see that this finally works. --- Jura 16:22, 28 February 2021 (UTC)Query overcounts when grouping[ edit ]

I have a query that works, and I made it count cases grouped by several fields. However, the resulting query multiplies by 4 the counts. I suspect that the problem comes from the OPTIONAL clauses, but I can't solve it:

The query without grouping. Please notice that there are 8 registers with ?lloclabel as "Torà".

# Categories per origen de llocs i nombre d'articles (1 nivell P131)SELECTDISTINCT?lloc?llocLabel?cat?categoria?catnat?categorianat?persona?personaLabel?artWHERE{?personawdt:P19/wdt:P131??lloc.?llocwdt:P131*wd:Q12733.?artschema:about?persona.?artschema:isPartOf<https://ca.wikipedia.org/>.OPTIONAL{?llocwdt:P1464?catnat.OPTIONAL{?categorianatschema:about?catnat.?categorianatschema:isPartOf<https://ca.wikipedia.org/>.}}OPTIONAL{?llocwdt:P1792?cat.OPTIONAL{?categoriaschema:about?cat.?categoriaschema:isPartOf<https://ca.wikipedia.org/>.}}SERVICEwikibase:label{bd:serviceParamwikibase:language"[AUTO_LANGUAGE],ca,en,es".}}ORDER BY?llocLabel Try it!

Now, trying to group by ?llocLabel and related fields, 32 cases are counted with ?llocLaber as "Torà" (4 fold overcounting).

# Categories per origen de llocs i nombre d'articles (1 nivell P131)SELECTDISTINCT?lloc?llocLabel?cat?categoria?catnat?categorianat(COUNT(?persona)AS?totpers)WHERE{?personawdt:P19/wdt:P131??lloc.?llocwdt:P131*wd:Q12733.?artschema:about?persona.?artschema:isPartOf<https://ca.wikipedia.org/>.OPTIONAL{?llocwdt:P1464?catnat.OPTIONAL{?categorianatschema:about?catnat.?categorianatschema:isPartOf<https://ca.wikipedia.org/>.}}OPTIONAL{?llocwdt:P1792?cat.OPTIONAL{?categoriaschema:about?cat.?categoriaschema:isPartOf<https://ca.wikipedia.org/>.}}SERVICEwikibase:label{bd:serviceParamwikibase:language"[AUTO_LANGUAGE],ca,en,es".}}GROUP BY?lloc?llocLabel?cat?categoria?catnat?categorianat?categoriaLabel?categorianatLabelORDER BYDESC(?totpers)?llocLabel Try it!

-- Pere prlpz ( talk ) 19:36, 27 February 2021 (UTC)

@ Pere prlpz : You can solve the problem by using (COUNT(DISTINCT ?persona) AS ?totpers) instead of (COUNT(?persona) AS ?totpers). -- Dipsacus fullonum ( talk ) 21:18, 27 February 2021 (UTC) @ Dipsacus fullonum : Thank you. It works great.-- Pere prlpz ( talk ) 21:29, 27 February 2021 (UTC) Retrieved from " https://www.wikidata.org/w/index.php?title=Wikidata:Request_a_query&oldid=1372416887 " Categories : Wikidata shortcut box first parameter needs fixing Wikidata:Request a query Hidden category: Pages with graphs Navigation menuPersonal toolsNot logged in Talk Contributions Create account Log in Namespaces Project page Discussion VariantsViews Read Edit Add topic View history MoreSearch
Navigation Main page Community portal Project chat Create a new Item Recent changes Random Item Query Service Nearby Help Donate Lexicographical data Create a new Lexeme Recent changes Random Lexeme Tools What links here Related changes Special pages Permanent link Page information Wikidata item Print/export Create a book Download as PDF Printable version In other projects Wikipedia In Wikipedia English עברית Edit links This page was last edited on 28 February 2021, at 16:22.All structured data from the main, Property, Lexeme, and EntitySchema namespaces is available under the Creative Commons CC0 License ; text in the other namespaces is available under the Creative Commons Attribution-ShareAlike License ; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy. Privacy policy About Wikidata Disclaimers Mobile view Data access Developers Statistics Cookie statement Wikimedia Foundation Powered by MediaWiki
© 2014-2021 ЯВИКС - все права защищены.
Наши контакты