Shortcuts: WD:RAQ, w.wiki/LX

Wikidata:Request a query

From Wikidata
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/07.

Search for multiple (specific) types via wikibase:api "EntitySearch" running into 50 record limit?

I'm trying to let people search for anything, as long as it's something in the popular culture like an actor, book, movie, sports team, etc. So if I search "Patriots" I should get the NFL Team and the movie The Patriot. And I think I've gotten a good start with this:

SELECT distinct ?ordinal ?item ?itemLabel ?itemDescription ?image WHERE {
  SERVICE wikibase:mwapi {
    bd:serviceParam wikibase:api "EntitySearch";
                    wikibase:endpoint "www.wikidata.org";
                    mwapi:search "Patriots";
                    mwapi:limit 1000;
                    mwapi:language "en" .
    ?item wikibase:apiOutputItem mwapi:item .
    ?ordinal wikibase:apiOrdinal true .
  } 
  ?item wdt:P31/wdt:P279* ?type.
  OPTIONAL{?item wdt:P18 ?image .}
  FILTER( ?type in (wd:Q5, wd:Q17537576, wd:Q12973014))
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
} ORDER BY ASC (?ordinal) LIMIT 100
Try it!

I'm using the EntitySearch service so that I can get the :apiOrdinal value to help sort the results for relevance, and ?type contains the whole list of parent types so that I can just use "creative work" and "sports team" as catch-alls to filter on. (The FILTER list of Q types is incomplete, I was just starting to get the test going)

But, the problem happens when you replace "Patriots" with "Fellowship". In theory I should get the book and film Fellowship of the Ring. But the only result is for the "group" Fellowship of the Ring. If you take off the FILTER, you'll see it only returns 40 records from the EntitySearch for some reason? And if you change it to "Fellowship of the Ring" it will correctly find the book and film, so the EntitySearch can find those two. But for some reason it seems like EntitySearch is capping the results to a limit of 40?

Any ideas on what's going on? Or an alternative to do this search differently, preferably still with the :apiOrdinal so that the results are sorted by relevance?

Thanks!  – The preceding unsigned comment was added by Thomas.lumen (talk • contribs) at 17:16‎, 6. 7. 2019 (UTC).

Get all items that come under a particular category

I'm trying to find all items that can be marked as scientific items. For instance, photosynthesis, ohm's law, etc. Like, photosynthesis belongs to Biological Processes category but when I use the category in the below query I also get "death" as an item which is not an intended item. I think I am leaning more towards the concepts that one studies during his school years. Please let me know if there's a specific category that I should aim for?

SELECT ?item ?itemLabel WHERE {
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  ?item wdt:P31 wd:Q336.
}
LIMIT 200

 – The preceding unsigned comment was added by 204.246.162.35 (talk • contribs) at 22:35‎, 16 July 2019 (UTC).[reply]

WikiProject every politician

Could you please help to create a query which returns all politicians and the linked persons to them (like sibling, siblings-in-law, family, unusual family relationships etc.)? Can this be done with one query?  – The preceding unsigned comment was added by Danail Stoyanov (talk • contribs) at 13 août 2019 à 09:15‎ (EST) (UTC).

WikiData SPARQL query for plants data

I am a BE CSE undergrad student currently working on collecting information about plants so I am trying to query about all the plants from the wikidata Query Engine but I couldn't find a way. Any help on this is appreciableλ  – The preceding unsigned comment was added by 14.139.161.242 (talk • contribs) at 14 août 2019 à 10:06‎ (EST) (UTC).

Does this help you get started?

SELECT ?plant ?plantLabel
WHERE
{
         # any instance or subclass of plant
  ?plant wdt:P31/wdt:P279* wd:Q756
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE]". }
}
Try it!

Query of Species of Trees in different languages

I am an artists looking at the representation of species of trees in Wikidata, looking for a list that contains f.ex. Quercus Robur, Acacia_podalyriifolia etc.

It is interesting to see that this query gets all individual trees, not species, as a result: SELECT ?item ?itemLabel WHERE {

 ?item wdt:P31 wd:Q10884. #is instance of tree
 ?item wdt:P17 wd:Q30 . # specific for US, uses other code than 'citizenship' of a place specified non-human

}

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

}

Rather, I'm looking for a list like this: https://en.wikipedia.org/wiki/Category:Trees_of_Africa (without the location property)

I would like to see what kind of species of trees are represented in EN, FR, SP, NL. I started something like this, but as 'taxon' is a property with a wide variety of values, it gives me a time out. SELECT ?item ?itemLabel WHERE {

 ?item wdt:P31 wd:Q16521;
   wdt:P105 wd:Q7432.
 SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }

}

On the Wiki Data page of f.ex. Quercus Robur, everything refers to Quercus, which leads me to Genus/Family/Order etc. It would be wonderful to get some help on this. Many thanks in advance!

chemical substances used in plastics

I would like to retrieve the CAS number of all chemical substances that are used in plastics.

This is what I built with the Query Helper, however it returns nothing. Any suggestions?

#CAS number of all chemical substances that are used in plastics
   SELECT ?sitelink ?item ?CAS_Registry_Number WHERE {
   ?item wdt:P279 wd:Q79529.
   ?sitelink schema:about ?item.
   SERVICE wikibase:label { bd:serviceParam wikibase:language 
   "[AUTO_LANGUAGE],en". }
   ?item wdt:P366 wd:Q60082936.
   OPTIONAL { ?item wdt:P231 ?CAS_Registry_Number. }
}
ORDER BY (?itemLabel)|
Try it!

How many common article has a wikipedia with another wikipedia?

Plese help me count:

  • how many common articles the Ukrainian Wikipedia has with Polish Wikipedia?
  • how many common articles the Ukrainian Wikipedia has with Russian Wikipedia?

«Сommon article a wikipedia has with another wikipedia» means that the article has an interwiki link with the article in another wikipedia.

--Perohanych (talk) 16:28, 20 September 2019 (UTC)[reply]

If one of them was smaller, the below might not time-out. Maybe there is a way to optimize it:

SELECT (COUNT(*) as ?count) 
{
    ?uk schema:isPartOf <https://uk.wikipedia.org/> .
    ?uk schema:about ?item .
    ?ru schema:isPartOf <https://ru.wikipedia.org/> .
    ?ru schema:about ?item .  
}

Try it!

You could try to extrapolate from:

SELECT (COUNT(*) as ?count) 
{
    { SELECT ?item { ?uk schema:isPartOf <https://uk.wikipedia.org/> ; schema:about ?item } LIMIT 500000 } 
    ?ru schema:about ?item ; schema:isPartOf <https://ru.wikipedia.org/> .
}
Try it!

which gives you 288,000 ruwiki sitelinks per 500,000 items with a uksitelinks.

You need to extrapolate this to 1,194,917:

SELECT (COUNT(*) as ?count) 
{
    ?uk schema:isPartOf <https://uk.wikipedia.org/> ; schema:about ?item .
}
Try it!

Now you might want to refine this to exclude categories, templates and disambiguation items. --- Jura 16:55, 20 September 2019 (UTC)[reply]

Also, there are 225,227 items that only link to ukwiki:

SELECT (COUNT(*) as ?count) 
{
    ?uk schema:isPartOf <https://uk.wikipedia.org/> ; schema:about ?item . 
    ?item wikibase:sitelinks 1 
}
Try it!

--- Jura 16:58, 20 September 2019 (UTC)[reply]

@Jura1:, thank you! --Perohanych (talk) 18:10, 20 September 2019 (UTC)[reply]
@Jura1, Perohanych: It turns out you can manage this through Petscan, although it takes a few minutes - generate all items in ukwiki, then filter by those with a plwiki sitelink. It reports 413624 items fot ukwiki-plwiki (PSID 11357748); I'm not completely sure if that's filtering for namespace or not, though. Petscan normally filters to ns0 (articles) by default, but I don't know if the page property filters only apply to the category searches. Andrew Gray (talk) 13:58, 28 September 2019 (UTC)[reply]
Aha, figured it out - if you ask Petscan to give a TSV, it produces a file with every matching line in it. The namespace column is blank, but when I try looking for categories that I know are present in both wikis (eg Category:Stubs (Q2944440) or Category:1980 births (Q6647874), they're *not* found in the download, suggesting it is indeed only returning articles and so this is the value you're after. Andrew Gray (talk) 14:04, 28 September 2019 (UTC)[reply]
Great, Andrew Gray ! Thank you. --Perohanych (talk) 16:04, 28 September 2019 (UTC)[reply]

Trouble with nested town/state entities

There is a lighthouse (Q7084940) in Scituate (Q2415936), Massachusetts. Scituate is located within Plymouth County (Q54086). How come asking for lighthouses in Plymouth County doesn't show Scituate light? (other lighthouses do show however) This is the query I'm using:

SELECT DISTINCT ?item ?itemLabel ?coords ?image WHERE { ?item wdt:P31 wd:Q39715 ;

             wdt:P131 wd:Q54086 ;
             wdt:P625 ?coords

OPTIONAL { ?item wdt:P18 ?image } SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],nb,nn,en,fi" } } ORDER BY ?itemLabel


Neverind. I figured it out. Just add an asterisk after P131.

Get number of publications for authors with ORCID and working in the Czech Republic - with federated Query

I have this list of scientists working in the Czech Republic:

SELECT ?item ?itemLabel ?orcid {
  ?item wdt:P108/wdt:P17 wd:Q213 .
  ?item wdt:P496 ?orcid .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  }
Try it!

And I'd like to order them by number of publications. I am able to do it via publications already present in Wikidata, but that would be incomplete. Is it possible to connect to external SPARQL endpoints such as OpenCitations and get a more complete answer? Thank you very much for help, --Vojtěch Dostál (talk) 14:17, 25 September 2019 (UTC)[reply]

Federation with OpenCitations seems to be possible, according to Wikidata:SPARQL federation input/Archive#OpenCitations. Doing so is slightly above my pay grade, though; I'm not sure how data will be keyed between the two databases. --Tagishsimon (talk) 17:40, 25 September 2019 (UTC)[reply]

Impact Indicators for AfroCine 2.0

Good morning wikidata experts. I am one of the coordinators of the AfroCine project that will be starting in the month of October. For some time now, we have been looking at how we can quantitatively measure the impact of each project annually. Presently, we have identified three key indicators that we will be measuring the pre and post AfroCine variations. To this end, can i kindly request the following Wikidata queries?

  • A wikidata query that counts the number of films in English Wikipedia (indicator 1)
  • A Wikidata query that counts the number of African films in English Wikipedia (indicator 1)
  • A Wiki query that counts the number of women actors in English Wikipedia (indicator 2)
  • A Wikidata query that counts the number of African women actors in English Wikipedia (indicator 2)
  • A wikidata query that counts the number of African films in more than one language Wikipedia (indicator 3)

I have queries for all of the above, but I feel like mine is not optimized enough.

I look forward to your replies.HandsomeBoy (talk) 07:26, 26 September 2019 (UTC)[reply]

Number of Bundesliga matches

I am looking for the number of association football match (Q16466010) in each sports season (Q27020041) of Bundesliga (Q82595) (individually for each season between part of the series (P179): 1963–64 Fußball-Bundesliga (Q687048) and part of the series (P179): 2018–19 Bundesliga (Q47787804)). Steak (talk) 08:40, 27 September 2019 (UTC)[reply]

SELECT ?season ?seasonLabel (COUNT(?match) AS ?linked_matches) WHERE {
  ?season wdt:P3450 wd:Q82595 .
  OPTIONAL {
    ?match wdt:P179 ?season; wdt:P31 wd:Q16466010 .
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language 'en' }
} GROUP BY ?season ?seasonLabel ORDER BY ASC(?seasonLabel)
Try it!

 —MisterSynergy (talk) 17:55, 27 September 2019 (UTC)[reply]

Great, thanks! Steak (talk) 20:20, 27 September 2019 (UTC)[reply]

Get all WP articles that have a reference to a website

This article in WP https://en.wikipedia.org/wiki/Mastectomy uses as reference a reliable source - called MedlinePlus (it is the first reference in that article). It goes to this URL https://medlineplus.gov/mastectomy.html query A: Is it possible to write a query that produces a list WP articles that contain a reference where inURL there is string medlineplus.gov? (realted question, does WD import (like it does for all articles) also every reference ever used in WP? If that is hard, I need just a query B: list of all webcites in WP. references like these: <ref>{{cite web |url=

I found this article that generated it but the dataset on figshare is no longer there and is also now outdated. https://medium.com/freely-sharing-the-sum-of-all-knowledge/what-are-the-ten-most-cited-sources-on-wikipedia-lets-ask-the-data-34071478785a EncycloABC (talk) 14:12, 27 September 2019 (UTC)[reply]

I am also interested in this query, hopefully someone provides a solution. HandsomeBoy (talk) 16:24, 27 September 2019 (UTC)[reply]
@EncycloABC, HandsomeBoy: This is not something that Wikidata Query Service can do. I doubt there is a corpus of all references present in English Wikipedia, so your best chance is to search all links to https://medlineplus.gov via en:Special:LinkSearch and somehow manually sort out those which are inside references. Maybe you could write a search RegEx but I don't have the skills for that.Vojtěch Dostál (talk) 06:37, 2 October 2019 (UTC)[reply]
Thank you @Vojtěch Dostál:. HandsomeBoy (talk) 08:00, 2 October 2019 (UTC)[reply]

Hi, I'm interested in getting an overview of the cross-wiki content based on a WikiProject tag in one "seed" wiki. I know how to use PetScan to get a list of pages within the scope of a WikiProject on the English Wikipedia. For WikiProject African diaspora, this PetScan query gives the list, and the current results can be found via PetScan ID 11518507. I have tried to combine that with a SPARQL query (via the "Other sources/ SPARQL" form) of the kind

The following query uses these:

SELECT ?item WHERE {?sitelink schema:about ?item}

but they always time out, presumably because that SPARQL query is run on its own rather than based on the above PetScan query results. How can I combine the two? How can I get all the sitelinks for a WikiProject like this? Thanks for any pointers. --Daniel Mietchen (talk) 15:57, 27 September 2019 (UTC)[reply]

@Daniel Mietchen: If you use "other sources> use wiki", you can set it to give you the results for any specific wiki (eg PSID 11536702 is your query but generating all crosslinks to dewiki, 1345 results vs 7261 in the original). To do it for "all sitelinks in any wiki", I think this is beyond Petscan and you might have to start analysing dumps? (eg export all IDs for matching items from Petscan, crossref to the wikidatawiki-...-wb_items_per_site file) Andrew Gray (talk) 12:43, 28 September 2019 (UTC)[reply]

How many items with P1472 represent people vs. organizations?

Can someone write a query to return the count of items with Commons Creator page (P1472) that are instance of (P31) human (Q5) and instance of (P31) organization (Q43229) or one of its subclasses? Thanks! - PKM (talk) 21:01, 27 September 2019 (UTC)[reply]

@PKM: The generic answer, counting all types, is:
select ?typeLabel (count(distinct ?item) as ?count)
where
{ 
  ?item wdt:P31 ?type . ?item wdt:P1472 ?creator .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
} group by ?typeLabel order by desc(?count)
Try it!
For just humans
select (count(distinct ?item) as ?count)
where
{ 
  ?item wdt:P31 wd:Q5 . ?item wdt:P1472 ?creator .
}
Try it!
And for just organisations
select (count(distinct ?item) as ?count)
where
{ 
  ?item wdt:P31 ?type . ?item wdt:P1472 ?creator . ?type wdt:P279* wd:Q43229
}
Try it!
I'm not completely sure everything you'd want is in the organisation tree, which might explain why the numbers are so low. Andrew Gray (talk) 22:19, 27 September 2019 (UTC)[reply]
@Andrew Gray: thank you. I probably shouldn’t worry about a more sophisticated Wikidata Creator template for organizations just yet. :-) - PKM (talk) 02:15, 28 September 2019 (UTC)[reply]
@PKM: Yeah - I was surprised how few there were! Mind you, thinking back, when I did a lot of creator templates in 2013, I think I skipped organisations out of not being sure how best to deal with them, so maybe it's a chicken-and-egg thing...
For completeness, here is the very small number which have no P31 - looks like they're all just people who haven't been marked as such yet. Andrew Gray (talk) 12:36, 28 September 2019 (UTC)[reply]
I’ll do some cleanup on these. - PKM (talk) 18:17, 28 September 2019 (UTC)[reply]

Range of time

How to filter items by the range of time, e.g. list all items which were founded (have a statement with inception (P571)) in the second half of the 20th century (or between 1950 and 2000)? I know that items may have values exact year, range of years set by qualifiers start time (P580) end time (P582), or maybe earliest date (P1319). Juandev (talk) 08:52, 29 September 2019 (UTC)[reply]

Architectural structure

I am trying to list architectural structure (Q811979)s in Prague 2 (Q2444636). Unfortunately, my query cannot proceed before timeout. Why? Is my query correct? E.g. I have Centrální kotelna (Q48690925), where instance of (P31) = boiler house (Q1739809) and boiler house (Q1739809) has building (Q41176) as subclass of (P279) and building (Q41176) has architectural structure (Q811979) as subclass of (P279). So I want Centrální kotelna (Q48690925) on my list also.

SELECT ?archstruct ?archstructLabel ?something ?something2 WHERE {
  
 ?archstruct  wdt:P131 wd:Q2444636.  #architectural structure located in Prague 2
{ ?archstruct  wdt:P31 ?something. #architectural structure is something
 ?somehting wdt:P31 wd:Q811979.} #and "something" is architectural structure, or...
       UNION 
      {
    ?something wdt:P31 ?something2.  #...something2
    ?something2 wdt:P31 wd:Q811979. #something2 is srchitectural structure  
      } 
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],cs". }
}
LIMIT 100
Try it!

Juandev (talk) 10:24, 29 September 2019 (UTC)[reply]

Not sure how to answer. Currently, it repeats twice the same with Q811979. Maybe it's just the typo in "?somehting" --- Jura 10:37, 29 September 2019 (UTC)[reply]

Its not the typo, I don't know SPARQL and I am learning SPARQL. The goal is to list all items which are architectural structure (Q811979). --Juandev (talk) 13:09, 29 September 2019 (UTC)[reply]
SELECT DISTINCT ?archstruct ?archstructLabel ?something ?somethingLabel
WHERE
{
  ?archstruct  wdt:P131/wdt:P131* wd:Q2444636.  #architectural structure located in Prague 2
  ?archstruct  wdt:P31/wdt:P279* wd:Q811979 . #and "something" is architectural structure, or...
  ?archstruct  wdt:P31 ?something .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],cs". }
}
LIMIT 1000

Try it!

Sorry, try the above. The item would generally be an instance of a subclass of a structure, not an instance of an instance of a structure. Also, it might be indirectly in Q2444636. --- Jura 13:16, 29 September 2019 (UTC)[reply]

Identical external IDs

I am looking for all items where Transfermarkt player ID (P2446) and Transfermarkt manager ID (P2447) have the same value. Steak (talk) 20:20, 29 September 2019 (UTC)[reply]

SELECT ?item ?id WHERE { ?item wdt:P2446 ?id; wdt:P2447 ?id }
Try it!

 Easy one :-) —MisterSynergy (talk) 20:52, 29 September 2019 (UTC)[reply]

Indeed :) Thanks. Steak (talk) 06:57, 30 September 2019 (UTC)[reply]


Result of a sports match

How can I get out the result for the match from for example Hamburger SV versus SC Freiburg 2009–10 Fußball-Bundesliga (Q29877824) which is in participating team (P1923). --Balû (talk) 04:19, 1 October 2019 (UTC)[reply]

@Balû: Here is a query that gives you a table with the results for all 16 265 matches in the Bundesliga (Q82595) that have been entered in Wikidata. Results for the most recent seasons seem to be missing in Wikidata.
If you only want to have the results for one match, uncomment the VALUES line in the query.
SELECT ?match ?seriesLabel ?time ?home_teamLabel ?home_goals ?away_teamLabel ?away_goals {
# uncomment next line if you only want the match or matches specified within the { }  
# VALUES ?match { wd:Q29877824 }
  ?match wdt:P179 ?series . 
  ?series wdt:P3450 wd:Q82595 .
  ?match wdt:P585 ?time .  
  ?match p:P1923 ?p1923stm_home.
  ?p1923stm_home ps:P1923 ?home_team .
  ?p1923stm_home pq:P2868 wd:Q24633211 .
  ?p1923stm_home pq:P1351 ?home_goals . 
  ?match p:P1923 ?p1923stm_away.
  ?p1923stm_away ps:P1923 ?away_team .
  ?p1923stm_away pq:P2868 wd:Q24633216 .
  ?p1923stm_away pq:P1351 ?away_goals . 
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ORDER BY ?time ?home_teamLabel
Try it!
--Larske (talk) 07:52, 1 October 2019 (UTC)[reply]
@Larske: Wow! Thank you very much for the quick answer. --Balû (talk) 09:27, 1 October 2019 (UTC)[reply]

Ordered tree of military grades

Hello, for instance with colonel (Q104680), how to show the tree of grades general>colonel>lieutenant, etc? Perhaps with next lower rank (P3729) and next higher rank (P3730) but how ?Bouzinac (talk) 10:49, 2 October 2019 (UTC)[reply]

Bouzinac: Could you elaborate more? Are you interested in the full tree for a given initial item, such as colonel (Q104680)? Do you want all levels, or only the immediate higher and lower tank? --MarioGom (talk) 12:26, 2 October 2019 (UTC)[reply]
That's good point. Well, let's say I would tick colonel (Q104680) and get all the uppers and the lowers ranked grades, with colonel (Q104680) being somewhere in the middle of the tree ?
something like that ? author  TomT0m / talk page 14:49, 2 October 2019 (UTC)[reply]
Oui, quelque chose dans ce goût-là mais Q11993019 semble aberrant et il semble aussi que la hiérarchie des grades est bien plus complexe : Je m'attendais à voir par exemple Q48755225 mais en fait la fiche wikidata est vide :'| Bouzinac (talk) 15:27, 2 October 2019 (UTC)[reply]
Les données sont pas au niveau, encore, probablement. Je m’attends à un gros bazar et à des confusions, perso, vu qu’il doit y avoir des changements historiques et des grades de même noms qui sont dans des hiérarchies différentes … Faudrait que je ressorte les tentatives de visualisation des rangs tax(i·o)nomiques pour avoir une tentative de visualisation. author  TomT0m / talk page 15:42, 2 October 2019 (UTC)[reply]

Filtered descriptions

To get the items which have description in English ( for eg "human settlement in Malappuram district" )but don't have descriptions in "ml" language.--Akbarali (talk) 14:01, 2 October 2019 (UTC)[reply]

Petscan has filters to do that. But that query should do the trick for a sample of 1000. author  TomT0m / talk page 15:54, 2 October 2019 (UTC)[reply]

But in this qurey it shows different descriptions.--Akbarali (talk) 13:35, 3 October 2019 (UTC)[reply]

@Akbarali: It’s the same query as far as I can see. Only a sample of 1000 is shown, there is too many to find all of them. It may occur that from one query call to another different samples are shown. author  TomT0m / talk page 16:50, 3 October 2019 (UTC)[reply]

Filter according to Wikipedia category

Hi all! I have this query

SELECT DISTINCT ?author ?article WHERE {
 ?author wdt:P648 ?ol .
 ?author wdt:P3365 ?tr .
 ?article schema:about ?author .
 ?article schema:isPartOf <https://it.wikipedia.org/> .
}
Try it!

and I would like to obtain only the Wikipedia articles not contained in it:Category:P3365 letta da Wikidata. Is it possible? Thank you very much, --Epìdosis 12:01, 6 October 2019 (UTC)[reply]

@Epìdosis: Try this this PetScan query if you prefer links to the articles in itwp.
Or this PetScan query if you prefer links to the corresponding Wikidata objects.
--Larske (talk) 09:01, 7 October 2019 (UTC)[reply]

Removing double entities/tags from dutch municipalities

Is it possible to make a query that deletes the dutch municipality tag (Q2039348) from entitites that don't have a start (P580) or/and end time date set (P582)? And if yes, how would such a query look? if not, what's the best way to tackle this problem (clicking 2000 times is not really an option)? Antoni1626 (talk) 08:39, 7 October 2019 (UTC)[reply]

This is the query for the municipalities with a start date set:


SELECT ?municipalityLabel ?municipality ?begindatum ?einddatum ?CBS_gemeentecode WHERE {
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  ?municipality p:P31 ?statement.
  ?statement ps:P31 wd:Q2039348;
    pq:P580 ?begindatum;
 optional {  ?statement pq:P582 ?einddatum }
  
 optional { ?municipality wdt:P382 ?CBS_gemeentecode. } 

}
Try it!

Query for municipalities without start and end date:

SELECT ?municipalityLabel ?municipality ?begindatum ?einddatum ?CBS_gemeentecode WHERE {
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  ?municipality p:P31 ?statement.
  ?statement ps:P31 wd:Q2039348;
 minus {?statement pq:P580 ?begindatum;}
 minus {  ?statement pq:P582 ?einddatum }
  
 optional { ?municipality wdt:P382 ?CBS_gemeentecode. } }
Try it!

Here is an example: https://www.wikidata.org/wiki/Q2096012 (place), no start or end date, but the other entity https://www.wikidata.org/wiki/Q40671450 (municipality) has the correct dates. Antoni1626 (talk) 08:55, 7 October 2019 (UTC)[reply]

@Antoni1626: You can take the QIds from your second query, and use them in Quickstatements (help). In short you'll need to feed it a set of rows in the form -Q9769 [tab] P31 [tab] Q2039348. (Obvs, you need to be responsible for the goodness of your analysis...) --Tagishsimon (talk) 09:08, 7 October 2019 (UTC)[reply]
@Antoni1626, Tagishsimon: QS seems to remove the first statement that fulfils the criteria that instance of (P31) equals municipality of the Netherlands (Q2039348) without taking any qualifiers into consideration. See my experiments in Wikidata Sandbox (Q4115189), both using exactly the same QS syntax from above:
The above "QS syntax" will thus only work as long as the statement without qualifier(s), the one you want to remove,
  • is the first of the instance of (P31) statements and that
  • there are just one statement without qualifier(s).
In this particular case this may be fulfilled if all the faulty statements are "older" and the correct statements are "newer" and there is not more, or less, than one faulty statement per object, but in general you will have to check that these conditions before using QS to do such removal of statements. --Larske (talk) 09:38, 8 October 2019 (UTC)[reply]
Good point; hadn't occurred to me. --Tagishsimon (talk) 10:21, 8 October 2019 (UTC)[reply]

Reduce duplicates of Flanders Institute Arts Organization ID

Hi guys

Currently, I am contributing for the following WikiProject Wikidata:WikiProject_Performing_arts/Data_structure/Data_modelling_issues. I identified some duplicates. There are multiple records with a Flanders Art Institute organization ID who refer to the same organization.

I created a query to identify the number duplicates, but unfortunately, I am not able to make a list with the duplicates. The goal is to have a query, which could help to identify and tackle the duplicates.

Former query: try it

List should have at least the following attributes (with example records, see example):

Flanders Art Institute organization ID ItemIdentifier_1 ItemLabel_1 ItemIdentifier_2 ItemLabel_2
361416 Q54804772 Q54804772 Q55829416 De Ontmoeting

Thank you for your help.

@Boxomi: Something similar; does this work for you?
SELECT ?org ?item ?itemLabel ?item2 ?item2Label WHERE {
  ?item wdt:P5164 ?org.
  ?item rdfs:label ?itemLabel . filter(lang(?itemLabel)="en") 
  ?item2 wdt:P5164 ?org.
  ?item2 rdfs:label ?item2Label . filter(lang(?item2Label)="en") 
  filter(str(?item) < str(?item2) )
}
Try it!
--Tagishsimon (talk) 19:20, 7 October 2019 (UTC)[reply]

multiple optional conditions

Hi! we currently try to request a query for a list of q-numbers. The q-number is replaced from time to time. Depending on the requested q-number the given values of orcid, employer(s) and gender are given (or not) in the data set of the item. Therefore, those values should somehow be indicated as "optional".

SELECT  ?orcid ?employerLabel ?genderLabel ?parents ?parentsLabel
                        WHERE { 
                         OPTIONAL {?item wdt:P496 ?orcid }.  
                         OPTIONAL {?item wdt:P108 ?employer }. 
                         OPTIONAL {?item wdt:P21 ?gender }.
                               
                         Values ?item { wd:Q28360163 }. 
                         SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } 
                        }
Try it!

Can someone please correct my syntax? Thank you! Eva

@EvaSeidlmayer: It seem you have to include at least one non optional triple pattern to make the query work. As far as I can tell you’re interested into human items, so I added something related to the item being a human.
SELECT ?orcid ?employerLabel ?genderLabel ?parents ?parentsLabel
WHERE { 
  ?item wdt:P31 wd:Q5 .
  OPTIONAL {?item wdt:P496 ?orcid }.  
  OPTIONAL {?item wdt:P108 ?employer }. 
  OPTIONAL {?item wdt:P21 ?gender }.

  Values ?item { wd:Q28360163 }. 
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } 
 }
Try it!
author  TomT0m / talk page 11:40, 8 October 2019 (UTC)[reply]
Oh, reading the sparql doc on optional it seems that « optional » must just have something on the left. After testing, the « values » clause can serve as this something and just inversing stuffs in your original query works :
SELECT ?orcid ?employerLabel ?genderLabel ?parents ?parentsLabel WHERE {
  VALUES ?item {
    wd:Q28360163
  }
  OPTIONAL { ?item wdt:P496 ?orcid. }
  OPTIONAL { ?item wdt:P108 ?employer. }
  OPTIONAL { ?item wdt:P21 ?gender. }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
Try it!
author  TomT0m / talk page 11:46, 8 October 2019 (UTC)[reply]

Mayors of Dutch municipalities

Hello everyone. I am trying to construct a query for {{Wikidata list}} to request the mayors of Dutch municipalities. My current attempt is here User:Robin van der Vliet/Dutch mayors. It already shows a list of municipalities, their mayors and the start time and end time of a random mayor of the list.

I would like the query result to be sectioned by municipality, and below each section a table of all mayors of that municipalities with their start times, end times and birthdates.

Thank you for your help. Feel free to edit my subpage. Robin van der Vliet (talk) (contribs) 15:22, 8 October 2019 (UTC)[reply]