Open main menu

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. 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.

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

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 2019/04.

Contents

Getting a company's hierarchyEdit

Hi,

Is there a way to query for a complete organization's hierarchy traversing through parent Organization property or any other property?  – The preceding unsigned comment was added by Srini6teen (talk • contribs) at 12:08, 27 February 2019‎ (UTC).

Cannot get simple qualifier value of P31, plus: timeouts …Edit

I would like to query a list of church building (Q16970) in Cologne (Q365). Simple, isn't it? Actually, I need all subclasses of church building (Q16970) in any admin level (located in the administrative territorial entity (P131)) of Cologne (Q365). This reliably runs in a timeout. So I started without the first "wdt:P31/wdt:279*" and created some unions of subclasses, like

SELECT DISTINCT ?item ?itemLabel ?enddate WHERE {
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  #hint:Query hint:optimizer "None"  (I thought this is the magic bullet against timeout?)
  {?item wdt:P31 wd:Q16970.} # [[d:Q16970|church building <small>(Q16970)</small>]]
   UNION 
  {?item wdt:P31 wd:Q317557} #[[d:Q317557|parish church <small>(Q317557)</small>]]
}

Try it!

so far so good. Second, I'd like to distinguish the churches that don't exist anymore from the others. For this, the P31 statement has an end time (P582) qualifier of which I'd need the value. No idea how to get this in combination with the P31 variations. I tried dozens of p/ps/pq statements and played around with the Mona Lisa examples, but don't get it. I manage to get it to a point of no error, but then the result is zero ;-)

Any idea? I would greatly appreciate an answer that explains the solution so I can understand what's going on.

Thanks, --Elya (talk) 06:02, 21 March 2019 (UTC)

SELECT DISTINCT ?item ?itemLabel ?enddate WITH {
  SELECT DISTINCT ?item WHERE {
    ?item wdt:P131* wd:Q365 .
  }
} AS %subquery WHERE {
  INCLUDE %subquery .
  ?item p:P31 ?statementNode .
  ?statementNode ps:P31/wdt:P279* wd:Q16970 .
  OPTIONAL {
    ?statementNode pq:P582 ?enddate .
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language 'de,en' }
}
Try it!  Here, we have used a "named subquery" to select all entites located in Cologne first (~1300 items). Subsequently, the main query selects church buildings and optional end dates, based only on the slim results set from the subquery.
Generally, as there aren't that many items involved, I would have expected that a simpler version without the named subquery would also work, but it does time out for me. But now you have some results at least ;-) —MisterSynergy (talk) 06:15, 21 March 2019 (UTC)
Beautiful, thank you so much! --Elya (talk) 06:31, 21 March 2019 (UTC)
@MisterSynergy: you could add the "magic bullet" to your second query :). -- Luitzen (talk) 09:11, 21 March 2019 (UTC)
Any idea why this query does not seem to work in Listeria? I suppose it's the Subquery, but is this by design or is it my mistake? --Elya (talk) 20:37, 21 March 2019 (UTC)
}} macht die Vorlage zu, deshalb lieber ein Leerzeichen dazwischen machen ;-) —MisterSynergy (talk) 20:56, 21 March 2019 (UTC)
@Elya: (EC) There were two issues - the columns line needed a ? on ?enddate, and the double curly brackets needed a space between them to stop them being interpreted as the end of the template. All fixed now. (diff) --Tagishsimon (talk) 20:57, 21 March 2019 (UTC)
wow, thanks! --Elya (talk) 20:59, 21 March 2019 (UTC)

Well, next step … the query was very helpful to reconcile the existing churches against an import list I created from a source. I hopefully imported all catholic and protestant churches with architects and a couple of other properties Updated Query. Unfortunately, I can't get the duplicates out of the result – although there is already a double "DISTINCT". What causes the duplicates are multiple values in one property – e.g. in instance of (P31) or architect (P84). How can I cluster them to get the correct number of items? It's not crucial to have the correct (multiple) property values in the columns, although it would be nice. If it's easier, we can filter out all items with an enddate (26 items). The number of existing churches should be around 256/259. Thanks & regards, --Elya (talk) 08:01, 31 March 2019 (UTC)

Oldest paper to enter public domainEdit

Applying the 70-year-rule, what's the oldest academic paper that we know of, to enter the public domain? i.e. the paper with the longest period between publication and the death of the author; where that death was before 1 January 1948.

Ditto for the oldest artwork. Andy Mabbett (Pigsonthewing); Talk to Andy; Andy's edits 13:58, 22 March 2019 (UTC)

SELECT DISTINCT ?author ?authorLabel ?death ?article ?articleLabel ?publication {
  hint:Query hint:optimizer "None" .
  ?author wdt:P570 ?death . hint:Prior hint:rangeSafe true .
  FILTER (?death < "1948-01-01T00:00:00"^^xsd:dateTime && ?death >= "1947-01-01T00:00:00"^^xsd:dateTime)
  ?article wdt:P50 ?author .
  ?article wdt:P1433?/wdt:P577 ?publication .
  ?article wdt:P31/(wdt:P279*)/(wdt:P527?) wd:Q4119870
  SERVICE wikibase:label {bd:serviceParam wikibase:language "en"}
} ORDER BY ASC(?publication)
Try it!  – The preceding unsigned comment was added by Luitzen (talk • contribs) at 18:04, 22 March 2019‎ (UTC).
This isn't simple, as there may be multiple authors for a publication. Ignoring this problem for now, I would offer this query:
SELECT DISTINCT ?item ?deathDate ?pubDate ?diff_in_years WITH {
  SELECT DISTINCT ?item ?deathDate WHERE {
    ?item wdt:P50/wdt:P570 ?deathDate .
    FILTER(YEAR(?deathDate) <= 1947) .
  }
} AS %subquery WHERE {
  INCLUDE %subquery .
  VALUES ?class { wd:Q4119870 wd:Q13442814 }
  ?item wdt:P31/wdt:P279* ?class; wdt:P1433?/wdt:P577 ?pubDate .
  BIND((?deathDate - ?pubDate)/365.2425 AS ?diff_in_years) .
} ORDER BY DESC(?diff_in_years) LIMIT 100
Try it!  According to this query, Planck's doctoral thesis Q55713946 was published 68.75 years before his death in 1947. The query would theoretically work for artworks as well, but it times out. —MisterSynergy (talk) 22:02, 22 March 2019 (UTC)

Thank you, both. How about a slight variation: oldest paper not yet in the public domain? Andy Mabbett (Pigsonthewing); Talk to Andy; Andy's edits 21:47, 30 March 2019 (UTC)

This would be the query: tinyurl.com/y4dq7fsk; but the results are contaminated by rather a lot of papers we claim were published before one of the authors was even born. Jheald (talk) 22:34, 30 March 2019 (UTC)
Scrap the above, because it was comparing the date of author death with the date of the journal being founded, rather than the paper being published. Jheald (talk) 22:37, 30 March 2019 (UTC)
A simple query finds about 20,000 items apparently published before the author was born, of which here are the first 10,000: tinyurl.com/y4vkwgcu -- but in many cases this is because eg "20th century" is being recorded as "1 January 2000". Both data and query could use some improvement here. Jheald (talk) 23:08, 30 March 2019 (UTC)
@Jheald: Thank you. Would discarding anything with a "1 January" date be an effectve work-around, for now? Andy Mabbett (Pigsonthewing); Talk to Andy; Andy's edits 16:01, 2 April 2019 (UTC)
@Pigsonthewing: Try this, for items published before author's birth: tinyurl.com/y2zs2peo Now checking both dates have at least year-level precision.
Not quite what you asked for, but something that definitely needs to be cleaned out. For further items, uncomment the OFFSET statement in line 6 and try stepping through in 500,000s. Jheald (talk) 17:16, 2 April 2019 (UTC)

Sum only when months, not yearEdit

Hello Given that JNB airport (and some other, like the Indian ones) publishes only fiscal year stats, I downloaded each month, so that it would be easy to compute a civil year total. here's the code

SELECT ?item ?itemLabel  
?year (sum(?number) as ?number) 
WHERE {  {?item wdt:P238 ?IATA
VALUES ?IATA {"JNB"}.}.  
  ?item p:P3872 ?statement.
  ?statement pq:P585 ?time.
  bind (YEAR(?time) AS ?year) 
  ?statement ps:P3872 ?number.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "fr,en". }
  MINUS { ?statement wikibase:rank wikibase:DeprecatedRank }
  FILTER (?year >1985)
} group by ?year ?item ?itemLabel
order by ?item desc (?year)

Try it!

The challenge is that I do not wish to melt data with other sources that can give a total year and not each month. In other terms : I only wish to sum when months exists. Thanks!

@Bouzinac: I think it would be smarter and easier to use quantities with unit to determine if the number refers to a whole year or just a month, for a start : I just created passenger per year (Q62603273) and passenger per month (Q62603280) for example. Alternatively we could use
subject > patronage (P3872)   < 1 000 000 >
valid in period (P1264)   < May 2013 (Q2159002)     >
and filter if May 2013 (Q2159002) is a month. Would be doable without such tricks but trickier and less well modelled and structured. author  TomT0m / talk page 13:14, 31 March 2019 (UTC)
Just a sample edit to show an example of quantity with units, see this edit : https://www.wikidata.org/w/index.php?title=Q821750&diff=898815443&oldid=898803319 (cancelled for now, just for the show) author  TomT0m / talk page 13:29, 31 March 2019 (UTC)
Hi there TomT0m (talkcontribslogs), I think the date qualifier should be smarter than that. If it's a year, then the quantity should be understood valid for whole year, if a month, should be understood valid for whole month and thus the addition of jan, feb, mar....dec should be computed as a total year. Bouzinac (talk) 13:42, 31 March 2019 (UTC)
@Bouzinac: It’s possible to use the precision for this of course, but a date is not supposed to be a duration, we have valid in period (P1264) for durations. The precision around a date is supposed to mean an uncertity around the exact date, and not a duration. In this case this definitely falls under the unit usecase, if we have a quantity with actually different units, it’s way better to indicate the unit used if the units are not consistent. author  TomT0m / talk page 13:56, 31 March 2019 (UTC)
(just checking the property page, it seems it’s the intended model for this property : https://www.wikidata.org/wiki/Property:P3872#P1855 not to use the « date » qualifier ) author  TomT0m / talk page 14:04, 31 March 2019 (UTC)
Phew, it would mean I would have to reimpute all patronage data using valid in period (P1264) instead of point in time (P585) :-(  – The preceding unsigned comment was added by Bouzinac (talk • contribs) at 14:17, 31 March 2019‎ (UTC).
@Bouzinac: Just created a list of the months item : Wikidata:WikiProject_Calendar_Dates/lists/months. I can do this without much problems if you want. author  TomT0m / talk page 14:34, 31 March 2019 (UTC)

A possible (elaborated) solution, using the initial modelEdit

Computes the sums of the months of a year if they exists, and also takes the values of the total year if they exists as well. Takes whichever is available for a year. If both are presents, computes the mean of both available values, and the max difference to the mean of some available value.

SELECT ?item ?itemLabel (avg(?number) as ?passenger) (max(avg(?number) - ?number) as ?plus_minus) ?year 
with {
  select ?item ?statement ?year ?timevalue ?numberperperiod{
    ?item wdt:P238 ?IATA
    VALUES ?IATA {"JNB"}.
    ?item p:P3872 ?statement.
    ?statement pqv:P585 ?timevalue 
               ; ps:P3872 ?numberperperiod
               .
    ?timevalue wikibase:timeValue ?date .
               
    MINUS { ?statement wikibase:rank wikibase:DeprecatedRank }
    bind (YEAR(?date) AS ?year) 
    FILTER (?year >1985) .
  }
} as %airport
 
where {
  {
    select ?item ?year (sum(?numberperperiod) as ?number) {
      include %airport .
      ?timevalue wikibase:timePrecision ?prec filter ( ?prec > 9 )
    } group by ?item ?year
  } union {
      ?timevalue wikibase:timePrecision 9 .
    bind (?numberperperiod as ?number)
      include %airport
  } .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
} group by ?item ?itemLabel ?year 
  order by ?item desc (?year)

Try it! . author  TomT0m / talk page 16:46, 31 March 2019 (UTC)

It does the job! Thanks TomT0m!  – The preceding unsigned comment was added by Bouzinac (talk • contribs) at 19:11, 31 March 2019‎ (UTC).
Hi there again, would you be kind to add the missing french label (tried but got an error), try with for example {"PUJ" "SDQ"}. ? Bouzinac (talk) 08:52, 2 April 2019 (UTC)
Woops, the service obviously was deleted somewhere in the process :)   Done @Bouzinac: author  TomT0m / talk page 09:19, 2 April 2019 (UTC)
Thanks, there you go with the result [1] :)  – The preceding unsigned comment was added by Bouzinac (talk • contribs) at 14:22, 2 April 2019‎ (UTC).

Cologne churches againEdit

Hi, I'm not sure if I should have started a new question: added some updated questions, so please don't perceive this new request as pushing for attention, just in case it wasn't noticed … ;-) Thanks for your help. --Elya (talk) 16:42, 31 March 2019 (UTC)

@Elya: What's going on is, your DISTINCT asks that each row be distinct from the next. But for an ?item that has two different architects, the results show one row with architect A and one with architect B. And they are two distinct rows. The solution is to identify which columns are causing the duplicates, and to aggregate the results using, for instance, GROUP_CONCAT (or SAMPLE, depending on the aim of the query - GROUP_CONCAT concatenates all the values; SAMPLE gives you a single sample value from all of the possible values). I've done that for your query on two columns, alhtough I suspect only the architect column was causing the issues ... I didn't check. At least one duplicate remains, which is Deutschordenskirche St. Katharina (Köln) (Q1206440) and at a quick glance, the ?item p:P31 ?statementNode . ?statementNode ps:P31/wdt:P279* wd:Q16970 . ?statementNode pq:P582 ?enddate . is bringing back two rows because both P31s fit the pattern; one row has a null end date for the second P31 value for this item. It, too, could be group_concatted into a single row, but I thought I'd leave it for now.
SELECT DISTINCT ?item ?itemLabel ?enddate (group_concat(distinct ?denomLabel;separator=", ") as ?denomination) ?inception (group_concat(distinct ?architectLabel;separator=", ") as ?architects) WITH {
  SELECT DISTINCT ?item ?denom ?inception ?architect WHERE {
    ?item wdt:P131* wd:Q365 .
    OPTIONAL { ?item wdt:P140 ?denom .
    ?item wdt:P571 ?inception .
    ?item wdt:P84 ?architect.}
  }
} AS %subquery WHERE {
  INCLUDE %subquery .
  ?item p:P31 ?statementNode .
  ?statementNode ps:P31/wdt:P279* wd:Q16970 .

  OPTIONAL {
    ?statementNode pq:P582 ?enddate .
   
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language 'de,en'.
  ?item rdfs:label ?itemLabel.
  ?denom rdfs:label ?denomLabel.
  ?architect rdfs:label ?architectLabel.  }
} group by ?item ?itemLabel ?enddate ?inception
Try it! --Tagishsimon (talk) 19:02, 31 March 2019 (UTC)
Tagishsimon, thank you very much and sorry for the delayed response. This helps a lot!--Elya (talk) 18:11, 7 April 2019 (UTC)

Double GROUP_CONCATEdit

Hello,

Why the double GROUP_CONCAT don't work? And it's possible to have a ORDER BY who follow the numeric order?

SELECT ?institution ?institutionLabel ?twitter (COUNT(distinct (?item)) AS ?total) (GROUP_CONCAT(DISTINCT(?LieuLabel); separator=", ") as ?Lieux) (GROUP_CONCAT(DISTINCT(?departementLabel); separator=", ") as ?departements) ?pop
WHERE 
{
  ?institution wdt:P31/wdt:P279* wd:Q166118;
               wdt:P17 wd:Q142.
    OPTIONAL {?institution wdt:P2002 ?twitter .}
  OPTIONAL {
    ?institution wdt:P131 ?Lieu.
    OPTIONAL {?Lieu rdfs:label ?LieuLabel. filter(lang(?LieuLabel)="fr") }
    ?Lieu wdt:P131 ?departement.
    ?departement wdt:P31 wd:Q6465;
                 wdt:P1082 ?pop.
    OPTIONAL {?departement rdfs:label ?departementLabel. filter(lang(?departementLabel)="fr") }
           }
  OPTIONAL {
      ?item wdt:P485 ?institution .
           }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en".}        
} 
group by ?institution ?institutionLabel ?twitter ?lieux ?departements ?pop
HAVING (?total < 5)
ORDER BY ?institution

Try it!

Thanks in advance --2le2im-bdc (talk) 19:34, 31 March 2019 (UTC)

@2le2im-bdc: The cause seems to have been multiple twitters. See the discussion in the question above. You can add more columns to the order - e.g. ORDER BY ?institution ?pop but because ?institution values are unique, a second order sort such as ?pop will have no effect. So I'm not sure what you're aiming for here.
SELECT ?institution ?institutionLabel (GROUP_CONCAT(DISTINCT ?twitter; separator=", ") as ?twit) (COUNT(distinct (?item)) AS ?total) (GROUP_CONCAT(DISTINCT(?LieuLabel); separator=", ") as ?Lieux) (GROUP_CONCAT(DISTINCT(?departementLabel); separator=", ") as ?departements) ?pop
WHERE 
{
  ?institution wdt:P31/wdt:P279* wd:Q166118;
               wdt:P17 wd:Q142.
    OPTIONAL {?institution wdt:P2002 ?twitter .}
  OPTIONAL {
    ?institution wdt:P131 ?Lieu.
    OPTIONAL {?Lieu rdfs:label ?LieuLabel. filter(lang(?LieuLabel)="fr") }
    ?Lieu wdt:P131 ?departement.
    ?departement wdt:P31 wd:Q6465;
                 wdt:P1082 ?pop.
    OPTIONAL {?departement rdfs:label ?departementLabel. filter(lang(?departementLabel)="fr") }
           }
  OPTIONAL {
      ?item wdt:P485 ?institution .
           }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en".}        
} 
group by ?institution ?institutionLabel ?lieux ?departements ?pop
HAVING (?total < 5)
ORDER BY ?institution
Try it! --Tagishsimon (talk) 19:47, 31 March 2019 (UTC)
Thanks @Tagishsimon: we don't need no more ?pop and it's work great. --2le2im-bdc (talk) 19:58, 31 March 2019 (UTC)
SELECT ?institution ?institutionLabel (GROUP_CONCAT(DISTINCT ?twitter; separator=", ") as ?twit) (COUNT(distinct (?item)) AS ?total) (GROUP_CONCAT(DISTINCT(?LieuLabel); separator=", ") as ?Lieux) (GROUP_CONCAT(DISTINCT(?departementLabel); separator=", ") as ?departements)
WHERE 
{
  ?institution wdt:P31/wdt:P279* wd:Q166118;
               wdt:P17 wd:Q142.
    OPTIONAL {?institution wdt:P2002 ?twitter .}
  OPTIONAL {
    ?institution wdt:P131 ?Lieu.
    OPTIONAL {?Lieu rdfs:label ?LieuLabel. filter(lang(?LieuLabel)="fr") }
    ?Lieu wdt:P131 ?departement.
    ?departement wdt:P31 wd:Q6465.
    OPTIONAL {?departement rdfs:label ?departementLabel. filter(lang(?departementLabel)="fr") }
           }
  OPTIONAL {
      ?item wdt:P485 ?institution .
           }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en".}        
} 
group by ?institution ?institutionLabel ?lieux ?departements
HAVING (?total < 5)
ORDER BY ?institution
Try it!

BTVA video game IDEdit

Hi, I want import the all missing video games from https://www.behindthevoiceactors.com/video-games/ to Behind The Voice Actors video game ID (P4965), and I don't know how to do right query for that. So far, I have tried this one, but It's not working. Any help appreciated! Kirilloparma (talk) 01:10, 1 April 2019 (UTC)

@Kirilloparma: It's not completely clear to me what you want the report to show. Your report looks at described at URL (P973), so are you wanting, for instance, video game items on wikidata which have a 'behindthevoiceactors' url in P973? (spoiler: there don't seem to be any.) Or do you want a list of items that have a Behind The Voice Actors video game ID (P4965) property, such that you can compare that list with one drawn from the website? Here's a starter for ten query from which the query you actually want might be derived. Come back & talk more about what you actually want.
SELECT ?item ?itemLabel ?P4965 ?url
WHERE 
{
  ?item wdt:P31/wdt:P279* wd:Q7889 .
  hint:Prior hint:gearing "forward".
  ?item wdt:P973 ?url.
  optional {?item wdt:P4965 ?P4965 .}
#  filter(bound(?P4965)=false)
#  filter(contains(str(?url),"behindthevoiceactors"))  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
Try it! --Tagishsimon (talk) 01:45, 1 April 2019 (UTC)
@Tagishsimon: Ok, I will try to explain. I want to find all missing video games that I have not added yet from BTVA website (as reference URL (P854)) from each letter (from A to Z) and import for video games that have not Behind The Voice Actors video game ID (P4965). For example letter A, B, C and and so on ... such that I can add all missing items with a batch if it is possible. Kirilloparma (talk) 09:04, 1 April 2019 (UTC)

In other words (example):

Already added:

Item itemLabel value
Q150294 Mortal Kombat Mortal-Kombat

Not added yet (to find out with a query):

Item itemLabel value
Q925253 Mortal Kombat 3
@Kirilloparma: I'm still having some understanding issues; example: you talk of "as reference URL (P854)" but I don't see that anywhere in Mortal Kombat (Q150294). If it is the case that you want to ensure that a) there is a wikidata item for each video game listed on the behindthevoiceactors website and b) that for each item, you want to ensure that there is a Behind The Voice Actors video game ID (P4965) then I think we can make some progress.
The process would seem to be 1) grab listings from behindthevoiceactors 2) identify which have items, and 3) which have items and P4965 values and thus 4) which have no items and 5) which have items but are missing P4965 values. The query below provides answers to (2), (3) & (5), and the VALUES data in it is essentially (1) - albeit only for the A page. It's only a short hop from this to get an answer for (4), but that's best done in a spreadsheet.
If this is heading down the path you want, then I can do some more work on it and, very probably, come up with results which allow the data population exercise to be attacked through QuickStatements. Let me know.
SELECT ?item ?itemLabel ?P4965 where
  {
  ?item wdt:P31/wdt:P279* wd:Q7889 .
  hint:Prior hint:gearing "forward".
  ?item rdfs:label ?itemLabel . filter(lang(?itemLabel)="en")
  filter (?itemLabel in ("A Hat in Time"@en, "A Way Out"@en, "A.W.: Phoenix Festa"@en, "Abe Speak"@en, "Accel World VS Sword Art Online: Millennium Twilight"@en, "Accel World: Awakening of the Silver Wings"@en, "Accel World: The Peak of Acceleration"@en, "Ace Combat 3: Electrosphere"@en, "Ace Combat 5: The Unsung War"@en, "Ace Combat 7: Skies Unknown"@en, "Ace Ventura Pet Detective: The Case of the Serial Shaver"@en, "Ace Ventura: The CD-Rom Game"@en, "Acme Animation Factory"@en, "Adventure Time: Finn and Jake Investigations"@en, "Adventure Time: Hey Ice King! Why'd You Steal Our Garbage?!!"@en, "Adventure Time: Secret of the Nameless Kingdom"@en, "Adventures of Hyperman"@en, "Aeon Flux"@en, "Afro Samurai: The Video Game"@en, "Agatha Christie: And Then There Were None"@en, "Agatha Christie: Evil Under the Sun"@en, "Agatha Christie: Murder on the Orient Express"@en, "Age of Amazones"@en, "Ah! My Goddess"@en, "Ai Cho Aniki"@en, "AI: The Somnium Files"@en, "Air"@en, "AirBlade"@en, "Akai Ito"@en, "Akiba's Beat"@en, "Akiba's Trip"@en, "Akiba's Trip: Undead & Undressed"@en, "Aladdin in Nasira's Revenge"@en, "Alex Kidd in the Enchanted Castle"@en, "Alice in Wonderland"@en, "Alice in Wonderland (CD-i)"@en, "Lexis Numerique's Alice in Wonderland"@en, "Alice Order"@en, "Alien: Isolation"@en, "Aliens vs. Predator"@en, "Aliens vs. Predator 2"@en, "Aliens: Colonial Marines"@en, "Alone in the Dark (2008)"@en, "Alpha Protocol"@en, "Altered Beast"@en, "Alvin and the Chipmunks"@en, "Alvin and the Chipmunks: Chip-Wrecked"@en, "Alvin and the Chipmunks: The Squeakuel"@en, "Amaneka of Dawn and the Deep-Blue Golem"@en, "American McGee's Alice"@en, "Amerzone: The Explorer's Legacy"@en, "Amnesia"@en, "Amnesia Crowd"@en, "Amnesia Later"@en, "Amnesia World"@en, "Amnesia: A Machine for Pigs"@en, "Amnesia: The Dark Descent"@en, "Amy"@en, "Anarchy Reigns"@en, "Angel Beats!"@en, "Angelique"@en, "Angelique Etoile"@en, "Angelique Retour"@en, "Angelique Special 2"@en, "Angelique Trois"@en, "Angelique: Six Knights of Love"@en, "Animaniacs Game Pack"@en, "Animaniacs Splat Ball"@en, "Animaniacs: Ten Pin Alley"@en, "Animorphs: Know the Secret"@en, "Anohana: The Flower We Saw That Day"@en, "Ant Bully: The Video Game"@en, "Anthem"@en, "Aoi Shiro"@en, "Ape Escape"@en, "Ape Escape 2"@en, "Ape Escape 3"@en, "Ape Escape: On the Loose"@en, "Ape Escape: Pumped & Primed"@en, "Apex Legends"@en, "Apocalypse"@en, "Apollo Justice: Ace Attorney"@en, "Aqua Teen Hunger Force Zombie Ninja Pro-Am"@en, "Aquapazza: Aquaplus Dream Match"@en, "Ar nosurge: Ode to an Unborn Star"@en, "Ar tonelico: Melody of Elemia"@en, "Ar tonelico II: Melody of Metafalica"@en, "Ar tonelico Qoga: Knell of Ar Ciel"@en, "Arc Rise Fantasia"@en, "Arc the Lad"@en, "Arc the Lad II"@en, "Arc the Lad III"@en, "Arc the Lad: Twilight of the Spirits"@en, "La storia della Arcana Famiglia"@en, "La storia della Arcana Famiglia -The Ghost Ship Magician-"@en, "La storia della Arcana Famiglia 2"@en, "Arcana Heart"@en, "Suggoi! Arcana Heart 2"@en, "Arcana Heart 3: LOVE MAX!!!!!"@en, "Area 51"@en, "Armikrog"@en, "ARMS"@en, "Army of Darkness: Defense"@en, "Arslan: The Warriors of Legend"@en, "Art of Fighting"@en, "Art of Fighting 2"@en, "Art of Fighting 3"@en, "Arthur's 1st Grade"@en, "Arthur's Camping Adventure"@en, "Arthur's Computer Adventure"@en, "Arthur's Kindergarten"@en, "Arthur's Reading Games"@en, "Arthur's Sand Castle Contest"@en, "Arthur's Thinking Games"@en, "Arthur’s Preschool"@en, "ASH: Archaic Sealed Heat"@en, "Asphalt Overdrive"@en, "Assassin's Creed"@en, "Assassin's Creed II"@en, "Assassin's Creed III"@en, "Assassin's Creed IV: Black Flag"@en, "Assassin's Creed Odyssey"@en, "Assassin's Creed Origins"@en, "Assassin's Creed: Brotherhood"@en, "Assassin's Creed: Revelations"@en, "Assassin's Creed: Syndicate"@en, "Assassin's Creed: Unity"@en, "Assassination Classroom: Assassin Training Plan"@en, "Assassination Classroom: Grand Siege on Korosensei"@en, "Asterix & Obelix XXL"@en, "Asterix & Obelix XXL2: Mission: Las Vegum"@en, "Astral Chain"@en, "Asura's Wrath"@en, "Atelier Ayesha: The Alchemist of Dusk"@en, "Atelier Elie: The Alchemist of Salburg 2"@en, "Atelier Elkrone: Dear for Otomate"@en, "Atelier Escha and Logy: Alchemists of the Dusk Sky"@en, "Atelier Firis: The Alchemist and the Mysterious Journey"@en, "Atelier Iris: Eternal Mana"@en, "Atelier Iris 2: The Azoth of Destiny"@en, "Atelier Iris 3: Grand Phantasm"@en, "Atelier Judie: The Alchemist of Gramnad"@en, "Atelier Lilie: The Alchemist of Salburg 3"@en, "Atelier Lulua: The Scion of Arland"@en, "Atelier Lydie and Suelle: The Alchemists and the Mysterious Paintings"@en, "Atelier Marie: The Alchemist of Salburg"@en, "Atelier Meruru: The Apprentice of Arland"@en, "Atelier Rorona: The Alchemist of Arland"@en, "Atelier Shallie: Alchemists of the Dusk Sea"@en, "Atelier Sophie: The Alchemist of the Mysterious Book"@en, "Atelier Totori: The Adventurer of Arland"@en, "Atelier Violet: The Alchemist of Gramnad 2"@en, "Atlantis II: Beyond Atlantis"@en, "Atlantis III: The New World"@en, "Atlantis: The Lost Tales"@en, "Atlantis: The Lost Empire: The Video Game"@en, "Atomic Bomberman"@en, "Attack on Titan"@en, "Attack on Titan 2"@en, "Attack on Titan: Escape from Certain Death"@en, "Attack on Titan: Humanity in Chains"@en, "Austin Powers: Operation Trivia"@en, "Avalon Code"@en, "Avatar: The Last Airbender - Into the Inferno"@en, "Avatar: The Last Airbender - The Burning Earth"@en, "Avatar: The Last Airbender - The Video Game"@en, "Avengers Initiative"@en, "The Avengers: Battle for Earth"@en, "The Awakened Fate Ultimatum"@en, "The Awesome Adventures of Captain Spirit"@en, "Awesome Possum Kicks Dr. Machino's Butt"@en, "Azure Striker Gun-volt"@en, "Azure Striker Gunvolt"@en, "Azure Striker Gunvolt 2"@en ))
  optional {?item wdt:P4965 ?P4965 . }
}
Try it! --Tagishsimon (talk) 03:29, 2 April 2019 (UTC)

largest human settlement articles that doen't exist yet on the Hebrew WikipediaEdit

A list of all the largest human settlement articles on the English Wikipedia that have over 300,000 residents and don't exist yet on the Hebrew Wikipedia. WikiJunkie (talk) 06:02, 1 April 2019 (UTC)

@WikiJunkie: Something like
SELECT ?item ?itemLabel ?pop with 
{ SELECT DISTINCT ?item ?pop WHERE 
  {
    ?item wdt:P31/wdt:P279* wd:Q702492.
    hint:Prior hint:gearing "forward".
    ?item wdt:P1082 ?pop.
    filter(?pop>300000)
  }  
} as %i
where
{
  include %i
  SERVICE wikibase:label {bd:serviceParam wikibase:language "en","he" . }
  filter not exists {?article schema:about ?item ;
          schema:isPartOf <https://he.wikipedia.org/> .}  
} order by ?itemLabel
Try it! --Tagishsimon (talk) 15:44, 1 April 2019 (UTC)
You may want to add the following line at the end of the query to satisfy the requirement on "articles on English Wikipedia". That will exclude the 10 objects, e.g. Tokyo (Q7473516), that don't have an article in enwp.
?enarticle schema:about ?item; schema:isPartOf <https://en.wikipedia.org/>
--Larske (talk) 16:16, 1 April 2019 (UTC)

Useless sortingEdit

In Wikidata:WikiProject Chess/Lists/GM, the bot keeps changing the order of entries without changing anything else. Is it possible to modify the query to fix the order? The listeria list currently sorts by family name, but in case of identical names, this seems not to be unique. 84.57.193.85 18:37, 1 April 2019 (UTC)

Usually it’s enough to impose an arbitrary order on the sparql query on this kind of problems, by item Qid for example. I made an attempt. If listeria’s sorting is stable, it should do the trick. author  TomT0m / talk page 19:03, 1 April 2019 (UTC)
Thanks User:TomT0m. But now it sorts according to the Q-Id, right? Is it possible to sort the query by family name? 178.7.47.58 19:38, 2 April 2019 (UTC)
Yes, but to do this correctly we should have the family name property filled for every grand masters. There is a lot of them missing:
SELECT distinct ?item ?itemLabel  WHERE {  
  ?item wdt:P2962 wd:Q105269 
  optional { ?item rdfs:label ?itemLabel filter (lang(?itemLabel) = "en")  . }
  filter not exists { 
    ?item wdt:P734 ?familyname .
    ?familyname wdt:P1705 ?nom
  }
}
Try it! (1000, that’s a bit much to do all the work by hand)
so we will have to do an approximation such as « taking the label, and choose the string after the first space as a family name » for those missing. It will be an incorrect family name for some players. One problem to use family name (P734) is that there is no item yet for much of the family WikiProject Names for the remaining grandmasters. I’ll try something. author  TomT0m / talk page 13:21, 4 April 2019 (UTC)
All of that supposes that Listeria honours the sort established in the query, rather than implementing a sort based on the template's Sort parameter (or a default of ?item in its absence). It might be worth testing the proposition that the query sort is honoured, or, at least, having in mind that it might not be. --Tagishsimon (talk) 13:26, 4 April 2019 (UTC)
@Tagishsimon:_From my experience, it does. It’s currently not available but I did a query attempt on the page (still not perfect because the sort is done according to the name in the original language, so chinese names are regrouped in the end. author  TomT0m / talk page 13:50, 4 April 2019 (UTC)
@Tagishsimon, TomT0m: One thing I've found useful for dealing with the problem of listeria making null edits to change the order of names is using two order by ?... ?... elements - so family name, then item-qid as a backup. Even if the names are the same, the quids will always be different and always sort in the same way. And hopefully it will look reasonable to the end user, as they won't really worry about what order all the Smiths are sorted in. Andrew Gray (talk) 21:23, 4 April 2019 (UTC)

ProblemEdit

I seem to be having problems in understanding the filter function in the Wikidata Query service and I hope that someone can get me started.

Suppose I want to get all beneficial insects (Q81942940) that have an identification code from Invasive Species Compendium Datasheet-identificationcode (Invasive Species Compendium Datasheet ID (P5698)).

From the selection, I would also like to have the labels in all languages, the EPPO code (EPPO Code (P3031)) and an image.

However, when I run the query, I also get species of plant, countries and animals along, so obviously the filter is not working.

The query I made I copy below:

#Sample query to start a list of values for property P5698
#Remove some of the "#" below to see if it helps you
#sample variables defined below (but commented out)
#item wdt:P569 ?dob . 
#	?item wdt:P17 ?country .
SELECT ?item ?itemLabel ?value ?beneficial_insects ?parent_taxon ?parent_taxonLabel WHERE {
  ?item wdt:P5698 ?value.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en,en". }
  ?beneficial_insects wdt:P301 wd:Q8194294.
  OPTIONAL { ?beneficial_insects wdt:P171 ?parent_taxon. }
}
LIMIT 100

Try it!

 – The preceding unsigned comment was added by Jan de Wit6 (talk • contribs). @Jan de Wit6: For a start, it seems Q81942940 is not a real item. author  TomT0m / talk page 13:54, 4 April 2019 (UTC)

beneficial insects (Q8194294) is a real item, but has only three uses - https://www.wikidata.org/wiki/Special:WhatLinksHere/Q8194294 - so I've yet to see evidence that wikidata supports categorisation of insects as beneficial, which would be a problem. --Tagishsimon (talk) 14:00, 4 April 2019 (UTC)
@Jan de Wit6: In the interests of making a little progress, this query lists all insects with an Invasive Species Compendium Datasheet ID (P5698) value; no filter required:
select ?item ?itemLabel ?value with
{
  SELECT ?item ?value where 
  {
    ?item wdt:P5698 ?value.
  }  
} as %i where
{ 
  include %i
  ?item wdt:P171* wd:Q1390.   # parent taxon eventually reached insect
  hint:Prior hint:gearing "forward".
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en,en". }
}
Try it! --Tagishsimon (talk) 20:36, 4 April 2019 (UTC)


Thanks man, that works indeed. Much appreciated. I tried to copy your setup via the Query helper: In the query helper I made a filter on parent taxon insect. Under show, I added the P5698 value.

Yes, it gives me loads of results. I check a couple of items, and come to a disappointing conclusion. Results include plants, not only insects. Even weirder, the first result is wd:Q15473278 which is a plant (Calopogonium caeruleum). It also give a taxon_common_name: Ohrwürmer. Ohrwürmer is an insect, but what it has to do with the Calopogonium caeruleum is completely unclear to me?

So probably the question should be how that Query helper is realy functioning (or rather, is it functioning at all)?  – The preceding unsigned comment was added by Jan de Wit6 (talk • contribs) at 08:22, 11 April 2019‎ (UTC).

Creación de una ficha anterior mente borradaEdit

Anterior mente he creado una ficha de un Artista que pienso que puede interesar por la razones que tiene una larga trayectoria por sus obras, exposiciones individuales, colectivas, libros publicados, artículos publicados en revistas. Actualmente Doctorado en varias Universidades y profesor de universidad. Hoy ha sido eliminada. Merece la pena la divulgación ya que el Artista da su consentimiento, y da la opción de insertarla en la Wikipedia. Me refiero João Wesley de Souza. Más Información

Muy atentamente.  – The preceding unsigned comment was added by Coleccionwesley (talk • contribs) at 08:07, 4 April 2019‎ (UTC).

This is a forum for discussing reports on Wikidata. Deletion of an article on a language wikipedia is not something we can help with. Perhaps find a forum on the language wikipedia in which to raise your concern - perhaps https://es.wikipedia.org/wiki/Wikipedia:Caf%C3%A9. --Tagishsimon (talk) 12:37, 4 April 2019 (UTC)
I think that this discussion is resolved and can be archived. If you disagree, don't hesitate to replace this template with your comment. Andy Mabbett (Pigsonthewing); Talk to Andy; Andy's edits 17:52, 18 April 2019 (UTC)

All book articles published between 1990 to 1999 that exist on the English Wikipedia but don't exist yet on the Hebrew WikipediaEdit

I tried to create the code by myself but haven't succeded so far. WikiJunkie (talk) 20:29, 4 April 2019 (UTC)

@WikiJunkie: Need to start with a caveat that books are a bit of a mess on wikidata. They /should/ be represented as at least two items, one for the work, and one (or more) for editions. This query looks for version, edition, or translation (Q3331189) but in doing so, will miss items which do not follow the Functional Requirements for Bibliographic Records (FRBR) model - see, for instance Wikidata:WikiProject Books.
SELECT ?item ?itemLabel ?pop with 
{ SELECT DISTINCT ?item ?pop WHERE 
  {
    ?item wdt:P31/wdt:P279* wd:Q3331189.
    hint:Prior hint:gearing "forward".
    ?item wdt:P577 ?published.
    hint:Prior hint:rangeSafe true.
    FILTER("1990-00-00"^^xsd:dateTime <= ?published &&
           ?published < "1999-12-31"^^xsd:dateTime)  }  
} as %i
where
{
  include %i
  SERVICE wikibase:label {bd:serviceParam wikibase:language "en","he" . }
  filter not exists {?article schema:about ?item ;
          schema:isPartOf <https://he.wikipedia.org/> .} 
  ?article1 schema:about ?item ;
          schema:isPartOf <https://en.wikipedia.org/> .
} order by ?itemLabel
Try it! --Tagishsimon (talk) 20:48, 4 April 2019 (UTC)
It gave me only 95 results. WikiJunkie (talk) 16:41, 5 April 2019 (UTC)
@WikiJunkie: Yes. That's mainly because of the stipulation that there must be an en.wiki article. As I said, the representation of books is not good because of the work/edition dichotomy and the poor implementation thereof. There are amendments I can think of to the report, such as to look for editions published in the timeframe, link them to their work, and look for an article on the work rather than the edition; or different reports that presume that no work/edition split has been made. meanwhile, if you remove the en.wiki stipulation, you get about 3,800 hits, iirc. --Tagishsimon (talk) 17:18, 5 April 2019 (UTC)
@WikiJunkie: If we substitute in book (Q571) rather than version, edition, or translation (Q3331189) you get 2,500 hits.
SELECT ?item ?itemLabel ?pop with 
{ SELECT DISTINCT ?item ?pop WHERE 
  {
    ?item wdt:P31/wdt:P279* wd:Q571.
    hint:Prior hint:gearing "forward".
    ?item wdt:P577 ?published.
    hint:Prior hint:rangeSafe true.
    FILTER("1990-00-00"^^xsd:dateTime <= ?published &&
           ?published < "1999-12-31"^^xsd:dateTime)  }  
} as %i
where
{
  include %i
  SERVICE wikibase:label {bd:serviceParam wikibase:language "en","he" . }
  filter not exists {?article schema:about ?item ;
          schema:isPartOf <https://he.wikipedia.org/> .} 
  ?article1 schema:about ?item ;
          schema:isPartOf <https://en.wikipedia.org/> .
} order by ?itemLabel
Try it! --Tagishsimon (talk) 17:22, 5 April 2019 (UTC)

Filter out current yearEdit

Hello I've got data (say Sydney Airport (Q17581) / patronage (P3872)). Query works but we are on April 2019. So not a good idea to show current 2019 year as data is not fully update. How to filter year out (something like FILTER (?year <current_year) ? Thanks!  – The preceding unsigned comment was added by Bouzinac (talk • contribs) at 06:31, 5 April 2019‎ (UTC).

I've found this (very far in the documentation) : FILTER (?year < year(now())) Bouzinac (talk) 07:13, 5 April 2019 (UTC)

Only retrieve catalog numbers for the indicated catalogEdit

Hello! In this Listeria list, I would like to show ONLY the catalog numbers (first column) that correspond with catalog De Wolfers dynastie, Van art nouveau tot art deco (Q60515433). As you can see in the table, quite a few works are mentioned in more than one catalog (modelled via catalog code (P528)) and hence two numbers show up for them. An example work where that happens is Pumpkin Flowers (Q60520450), where I would only like to retrieve catalog code 26 and NOT 8 which corresponds with another catalog. I checked SPARQL documentation around qualifiers, but could not get a working query together unfortunately! Many thanks in advance :-) Spinster 💬 20:41, 5 April 2019 (UTC)

@Spinster: That should be fixed now. Let me know if not. thx. --Tagishsimon (talk) 21:05, 5 April 2019 (UTC)
@Spinster: And here, fwiw, is my mini-tutorial on qualifiers and references, should you want to figure them out - User talk:Tagishsimon#Wittylama --Tagishsimon (talk) 21:07, 5 April 2019 (UTC)
@Tagishsimon:Thank you so much! I was nearly there with my own attempt at the query, but didn't get the succession of elements entirely right. Thank you for linking to your tutorial as well. Cheers! Spinster 💬 08:13, 6 April 2019 (UTC)

Merging two known values togetherEdit

I'm working on a query to show parties after an election. At the moment, it gets all the results and shows them with the right colours. However, the UK has two parties that are in effectively a permanent very close coalition - Labour Party (Q9630) and Labour Co-operative (Q6467393). Everyone treats them as the same when doing things like counting total numbers of seats, even though they're officially distinct. I'd like to count any Labour Co-operative (Q6467393) as part of Labour Party (Q9630), so they show up in the Labour count (giving them a total of 301) and don't have a line of their own. Is it possible to do this by hard-coding something in as a BIND line? Andrew Gray (talk) 20:35, 7 April 2019 (UTC)

# members of the 1974-74 Parliament -635 seats.
SELECT DISTINCT ?party ?partyLabel ?rgb (count(?party1) as ?count) 
{
 ?item p:P39 ?positionStatement . ?positionStatement ps:P39 ?term . ?term wdt:P279* wd:Q16707842 .
 ?positionStatement ps:P39 wd:Q41582615 . 
 ?positionStatement pq:P768 ?constituency . 
 ?positionStatement pq:P2715 wd:Q119524 .     # feb 74 general election
 ?positionStatement pq:P4100 ?party . 
 optional { ?party wdt:P465 ?rgb } . # colour if known
 SERVICE wikibase:label { bd:serviceParam wikibase:language 'en' }
} group by ?party ?partyLabel ?rgb order by desc(?count)
#defaultView:BubbleChart

Try it!

@Andrew Gray: Something like the following? ?party1 is now the final variable counted and plotted, which is the same as ?party unless party = Labour Co-operative (Q6467393) :
# members of the 1974-74 Parliament -635 seats.
SELECT DISTINCT ?party1 ?party1Label ?rgb (count(DISTINCT(?item)) as ?count) 
{
 ?item p:P39 ?positionStatement . ?positionStatement ps:P39 ?term . ?term wdt:P279* wd:Q16707842 .
 ?positionStatement ps:P39 wd:Q41582615 . 
 ?positionStatement pq:P768 ?constituency . 
 ?positionStatement pq:P2715 wd:Q119524 .     # feb 74 general election
 ?positionStatement pq:P4100 ?party . 
 
 BIND(IF(?party = wd:Q6467393, wd:Q9630 , ?party) AS ?party1) .
 optional { ?party1 wdt:P465 ?rgb } . # colour if known
 SERVICE wikibase:label { bd:serviceParam wikibase:language 'en' }
} group by ?party1 ?party1Label ?rgb order by desc(?count)
#defaultView:BubbleChart
Try it! -- Jheald (talk) 20:49, 7 April 2019 (UTC)
Also, if larger numbers of parties need to be run together, you could have a series of lines like
OPTIONAL { BIND(wd:Q9630 AS ?party1) FILTER (?party = wd:Q6467393) }
followed by
OPTIONAL { BIND(?party AS ?party1) } to mop up the rest. Jheald (talk) 20:57, 7 April 2019 (UTC)
Hmmm. This ^^ latter case isn't quite working out of the box, but let me keep teasing away at it. Jheald (talk) 21:08, 7 April 2019 (UTC)
The first one looks great! Thanks for this. Andrew Gray (talk) 21:59, 7 April 2019 (UTC)
@Andrew Gray: Shouldn't Labour Co-operative (Q6467393) & Labour Party (Q9630) both be subclasses of a shared parent item? Then you could search on that. Andy Mabbett (Pigsonthewing); Talk to Andy; Andy's edits 18:02, 18 April 2019 (UTC)

get wikidata ID for research articles when the author is known by ORCIDEdit

Hey, I try to request the wikidata-q-numbers of articles an author wrote applying her*his ORCID-ID. I cannot find the correct query. There might be a prefix for ORCID somehow? Thanks a lot for helping me! Eva


get wikidatai dentifier for article from orcid

SELECT ?item ?article ?articleLabel ?wikidataIdentifier WHERE {

 ?item wdt:P496 ?orcid                                # item has an ORCID = it's a publishing researcher 
 Values ?orcid { '0000-0003-2300-3928' }              # ... and the ORCID is the of "Tasuku Honjo"
 ?item wdt:P50 wd:Q13442814 .                         # the guy is author (wdt:P50) of research articles (wd:Q13442814) 
 ?article wdt:P1687 wd:Q43649390                      # the articles are identified with Wikidata Identifer
 

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

Three issues here. The individual is not linked in any academic paper article via P50, but rather by author name string (P2093). If there were a relation, then the useful code would be more along the lines of ?paper wdt:P50 ?item . And then ?article wdt:P1687 wd:Q43649390 . is kinda not bound to the rest of the query - has no relation to the ?item, so I'm not sure what you were hoping for there. --Tagishsimon (talk) 15:52, 8 April 2019 (UTC)
select ?item ?itemLabel where 
{
  ?item wdt:P496 ?orcid .                               # item has an ORCID = it's a publishing researcher 
  Values ?orcid { "0000-0003-2300-3928" }              # ... and the ORCID is the of "Tasuku Honjo"
#  ?item wdt:P50 wd:Q13442814 .                         # the guy is author (wdt:P50) of research articles (wd:Q13442814) 
#  ?article wdt:P1687 wd:Q43649390 .                     # the articles are identified with Wikidata Identifer
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } 
}
Try it! --Tagishsimon (talk) 15:52, 8 April 2019 (UTC)
To get the articles of that person, you can use:
SELECT distinct ?item ?article ?articleLabel 
WHERE {
 ?item wdt:P496 ?orcid .                  # item has an ORCID = it's a publishing researcher 
 Values ?orcid { "0000-0003-2300-3928" }. # ... and the ORCID is that of "Tasuku Honjo"
 ?article wdt:P50 ?item .                 # an article has this person as author
 ?article wdt:P31 ?type .                 # what is the article?
 ?type wdt:P279* wd:Q13442814             # it is a scholarly article or subclass (not all are classed directly w/ Q13442814)
 SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } 
}
Try it!
This adds a line to find all articles with the person shown as the author; then finds what types of thing they are; and selects the ones that are scholarly articles (or subclasses of scholarly article). The subclasses issue isn't a problem for Honjo, as all his items are labelled as Q13442814, but for some researchers it will be useful - items are sometimes labelled with more specialised values like "scientific article" or "review". Andrew Gray (talk) 16:25, 8 April 2019 (UTC)
You can omit the ?type wdt:P279* wd:Q13442814 line, and see all the author's works, including, for example, books and chapters. Andy Mabbett (Pigsonthewing); Talk to Andy; Andy's edits 18:11, 18 April 2019 (UTC)

Doctoral advisorEdit

Hello, I would like to create a graph that links all the doctoral advisor (P184) and doctoral student (P185). It looks like a family tree but for doctoral advisor/student relations. I thought I could adapt from a family tree query but I am not able to find any. You can test on Leonhard Euler (Q7604). Thanks in advance. Pamputt (talk) 11:47, 9 April 2019 (UTC)

#defaultView:Graph

SELECT ?doctor ?doctorMaster ?doctorLabel ?doctorMasterLabel WHERE {
  ?root (wdt:P184*) ?doctor.
  ?doctor wdt:P184 ?doctorMaster.
  VALUES ?root {
    wd:Q7604
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
Try it!
Some examples : Wikidata:SPARQL query service/Wikidata Query Help/Result Views
@Pamputt: (I’m currently trying to format the tree from left to right from the root by default on the annotation, did not find the answer yet. You can play with the different layout buttons to change the display of the graph to something you like) author  TomT0m / talk page 12:52, 9 April 2019 (UTC)
A version including the doctor trained by Euler :
#defaultView:Graph#defaultView:Graph

SELECT ?doctor ?doctorMaster ?doctorLabel ?doctorMasterLabel ?docimage WHERE {
  { ?root (wdt:P184*) ?doctor. } union {?root wdt:P185/wdt:P185?/wdt:P185?/wdt:P185? ?doctor .}
  ?doctor wdt:P184 ?doctorMaster.
  optional {?doctor wdt:P18 ?docimage }
  VALUES ?root {
    wd:Q7604
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
Try it! (depth caped at 4 trainees because the tree seems to explode overwise and the causes performance issues in the graph rendering, and for readability) author  TomT0m / talk page 13:35, 9 April 2019 (UTC)

Merci TomT0m et effectivement pour les grands noms scientifiques, ça peut partir en timeout. Pamputt (talk) 15:58, 9 April 2019 (UTC)

Handling of Wikidata-Identifier (Q-Number) causes ProblemsEdit

Hey, one more question on dealing with the Wikidata-identifier or q-number. I try to retrieve the authors-Wikidata-q-number from known article-Wikidata-q-numbers.

Thanks a lot! Eva


SELECT ?item ?itemLabel                  # searching for an author and her*hisWikidata identifier (=q-number)
WHERE {?article wdt:P50 ?item .             # an article has this person as author
  ?article wdt:P4070 ?wd:Q43649390 .        # the article has a Wikidata identifier (=q-number)
  Values ?wd:Q43649390 { ' Q24535835 ' } .  # the wikidata-identifier of the article has this value 
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } 
}
Try it!
If I understand you correctly, Eva, this is what you want. Note the value in the VALUES statement starts with wd: and has no enclosing quotes.
SELECT ?item ?itemLabel   # searching for an author and her*hisWikidata identifier (=q-number)
WHERE 
{
  VALUES ?article { wd:Q24535835 } .      # the wikidata-identifier of the article has this value 
  ?article wdt:P50 ?item .                # an article has this person / these people as author(s)
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } 
}
Try it! --Tagishsimon (talk) 09:37, 10 April 2019 (UTC)

either A or BEdit

This:

SELECT ?item ?BRid ?IHc ?specieslink WHERE {
  {?item p:P4090 [ ps:P4090 ?BRid ] .}
        union
  {?item p:P5858 [ ps:P5858 ?IHc ] .}
  ?specieslink schema:about ?item; schema:isPartOf <https://species.wikimedia.org/> .
}

Try it!

finds everything I want (for a Listeria-populated wiki page), but with a separate line for each. How do I combine related entries? Andy Mabbett (Pigsonthewing); Talk to Andy; Andy's edits 07:53, 11 April 2019 (UTC)

SELECT ?item ?BRid ?IHc ?specieslink WHERE {
  ?specieslink schema:about ?item; schema:isPartOf <https://species.wikimedia.org/> .
  OPTIONAL { ?item p:P4090 [ ps:P4090 ?BRid ] }
  OPTIONAL { ?item p:P5858 [ ps:P5858 ?IHc ] }
  FILTER(BOUND(?BRid)|| BOUND(?IHc)) .
}
Try it!  It is by far not as efficient as your attempt, but still far enough away from timeouts. --MisterSynergy (talk) 08:06, 11 April 2019 (UTC)
SELECT ?item (group_concat(?BRid;separator=" / ") as ?BRid) (group_concat(?IHc;separator=" / ") as ?IHcid) ?specieslink WHERE {
  {?item p:P4090 [ ps:P4090 ?BRid ] .}
        union
  {?item p:P5858 [ ps:P5858 ?IHc ] .}
  ?specieslink schema:about ?item; schema:isPartOf <https://species.wikimedia.org/> .
} group by ?item ?specieslink
Try it! This one is efficient and regroup ids on the same line if there are several (which should not happen for an ID, so it’s weird) author  TomT0m / talk page 10:05, 11 April 2019 (UTC)

Always timeoutEdit

Hi,
I try for many days now to optimize this query (every # parts), but I always timeout. Someone have an idea ?

SELECT distinct ?item
?locLabel 
?etatLabel
?paysLabel WHERE {
  ?item wdt:P31/wdt:P279* wd:Q486972 ;
        wdt:P17 wd:Q159 ;
        wdt:P17 ?pays ;
        wdt:P131 ?loc ;
        schema:description ?desc ; #"human settlement in Russia"@en  ;
        wdt:P131* ?etat .
 ?etat  wdt:P131 
#wd:Q159 .
#pays2
#filter (?pays = ?pays2)
#FILTER(LANG(?desc) IN ("en")).
#FILTER regex (?desc, "human settlement in Russia").
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
LIMIT 5000

Try it!

Simon Villeneuve (talk) 10:17, 13 April 2019 (UTC)

@Simon Villeneuve: What are you trying to do, for a start ? It’s not entirely clear to me from reading the query. author  TomT0m / talk page 11:13, 13 April 2019 (UTC)
@TomT0m: Hi,
I want to get 3 levels of administrative divisions to upload better descriptions in French and English for these items (example). It work in French when I put a low limit (~5,000), but it didn't work in English for big countries like Russia and USA, even if I put a 1,000 limit. Simon Villeneuve (talk) 11:39, 13 April 2019 (UTC)
@Simon Villeneuve: This query finds 3 administrative levels for all administrative territorial divisions of Russia (more exactly with a P17:russia statement) without timeout
SELECT SELECT distinct ?item ?level1 ?level2 ?level3
WHERE {
  ?item wdt:P31/wdt:P279* wd:Q486972 ;
        wdt:P17 wd:Q159 ;
        wdt:P131 ?level1
  ?level1 wdt:P131 ?level2 .
  ?level2 wdt:P131 ?level3 .
}
Try it! (EDITED author  TomT0m / talk page 13:15, 13 April 2019 (UTC)) but do not attempt to retrieve label or description at all. Works in a few seconds. Hope it helps … Anything to try to add ? author  TomT0m / talk page 12:01, 13 April 2019 (UTC)
There's many problems with this : without descriptions, I can't create a batch. Without detection of actual descriptions, I can't know if a 3 levels automated description is a better description for the listed items. Simon Villeneuve (talk) 12:34, 13 April 2019 (UTC)
Ok. I can't explain why, but this work :
SELECT distinct ?item ?level1Label ?level2Label ?level3Label
WHERE {
  ?item wdt:P31/wdt:P279* wd:Q486972 ;
        wdt:P17 wd:Q159 ;
        schema:description "human settlement in Russia"@en ;
        wdt:P131 ?level1 .
  ?level1 wdt:P131 ?level2 .
  ?level2 wdt:P131 ?level3 .
  minus {?level2 wdt:P576 ?fin .}
  minus {?level3 wdt:P576 ?fin2 .}
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
LIMIT 25000
Try it! Simon Villeneuve (talk) 14:55, 13 April 2019 (UTC)

One problem in the Russia example seem to be that the administrative location statements are not properly ranked : The USSR old administrative division are ranked « normal » as well as the current one … The Russia WikiProject does not exist. Please correct the name. This makes several obsolete lines in my query above. author  TomT0m / talk page 12:12, 13 April 2019 (UTC)

Le problème se règle relativement bien (voir ma requête ci-haut). Simon Villeneuve (talk) 18:50, 13 April 2019 (UTC)
Disons que ça n’aide pas à écrire les requêtes et tout, les différentes combinaisons peuvent facilement faire passer les requêtes du mauvais côté des timeouts. Ce serait bien si des outils comme quickstatements géraient les rangs en tout cas, ou openrefine, mais j’ai pas l’impression que ce soit le cas. author  TomT0m / talk page 19:11, 13 April 2019 (UTC)

All items in TenerifeEdit

I'm trying to get a list of all items located in Tenerife, with a commons category sitelink if available. The query is:

SELECT ?place ?placeLabel ?sitelink WHERE { wd:Q40846 wdt:P625 ?mainLoc . SERVICE wikibase:around { ?place wdt:P625 ?location . bd:serviceParam wikibase:center ?mainLoc . bd:serviceParam wikibase:radius "20" . } SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . } OPTIONAL {?sitelink schema:about ?item ; schema:isPartOf <https://commons.wikimedia.org/>.} }

But it times out. It works OK without the "OPTIONAL {?sitelink ... }" part, though. Is there a better way do to this query? Thanks. Mike Peel (talk) 19:43, 13 April 2019 (UTC)

@Mike Peel: Problem was you started by looking for ?place and then switched to ?item for the sitelinks. Cured.
SELECT ?place ?placeLabel ?sitelink WHERE 
{ 
  wd:Q40846 wdt:P625 ?mainLoc . 
  SERVICE wikibase:around { ?place wdt:P625 ?location . 
                            bd:serviceParam wikibase:center ?mainLoc . 
                            bd:serviceParam wikibase:radius "20" . } 
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . } 
  OPTIONAL {?sitelink schema:about ?place ; schema:isPartOf <https://commons.wikimedia.org/>.} 
}
Try it! --Tagishsimon (talk) 20:05, 13 April 2019 (UTC)
Perfect, thanks! Mike Peel (talk) 20:14, 13 April 2019 (UTC)
@Mike Peel, Tagishsimon: The above query only covers the central parts of Tenerife and misses most of the coast areas. In order to cover the entire Tenerife island, you will have to increase the radius from "20" (giving some 300 hits) to "58" (giving some 1,350 hits), but then also some 150 points on the neighbour island will be included in this larger circle. An alternative to "wikibase:around" is "wikibase:box" where you state the coordinates for the southwest and northeast corners. This gives some 1,200 objects. See query below where I have also used the "map view" with the instance of (P31) as layers. With the layer feature you can, with the layer icon in the top right corner of the map, check mark the type of places, e.g. "mountain", "church building", "black sand beach" or whatever you may have a special interest in. I also included the optional image (P18), available for approximately half of the Tenerife objects. Click on the map dots to see the images and/or links to Commons.
#defaultView:Map
SELECT ?place ?placeLabel ?sitelink ?coord ?image ?layer WHERE 
{ 
  SERVICE wikibase:box {
      ?place wdt:P625 ?location .
      bd:serviceParam wikibase:cornerSouthWest "Point(-17.0 27.8)"^^geo:wktLiteral .
      bd:serviceParam wikibase:cornerNorthEast "Point(-16.0 28.7)"^^geo:wktLiteral .
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . } 
  ?place wdt:P625 ?coord .
  ?place wdt:P31 ?p31 . 
  OPTIONAL {?p31 rdfs:label ?layer . FILTER(lang(?layer)='en') }
  OPTIONAL {?sitelink schema:about ?place ; schema:isPartOf <https://commons.wikimedia.org/>.}
  OPTIONAL {?place wdt:P18 ?image } 
}
Try it!
--Larske (talk) 07:13, 14 April 2019 (UTC)
@Larske, Tagishsimon: Very nice, thanks! Is there a way to say 'if the item has topic's main category (P910), get the Commons sitelink from that item' please? An example being Fasnia (Q524431), where the sitelink is in Category:Fasnia (Q6241086). (I'm specifically interested in sitelinks not Commons category (P373).) Thanks. Mike Peel (talk) 08:20, 14 April 2019 (UTC)
@Mike Peel: Yes, by the addition of the line optional {?place wdt:P910 ?commonscat . ?sitelink schema:about ?commonscat ; schema:isPartOf <https://commons.wikimedia.org/>. } --Tagishsimon (talk) 08:45, 14 April 2019 (UTC)
That works nicely, thanks again! Mike Peel (talk) 09:47, 14 April 2019 (UTC)

Female German-language science-fiction writersEdit

I just came across a discussion about a list article in the German Wikipedia which tries to collect female science-fiction authors writing in German. The article got deleted, then reinstated, it got a certain amount of publicity and the discussion became heated and political. I tried to create such a list with a Wikidata query but I'm having a hard time getting the largest possible number of matches. After all, not all articles are using the precisely identical statements.

  • The language part can be accomplished using "native language" and "language spoken".
  • There is an occupation "science fiction writer", but the query could also use author plus genre science fiction (or an arbitrary sub-genre of sci-fi).

Maybe there are additional ways to express German plus science fiction writer that I don't know. I'm also having a hard time using the union feature of SPARQL. Here's what I currenly have, I've tried various combinations of what I have put into comments:

SELECT ?person ?personLabel ?dob ?dod WHERE
{
  ?person wdt:P31 wd:Q5.
  ?person wdt:P21 wd:Q6581072.
  # ?person wdt:P136 wd:Q24925.
  # ?person wdt:P136/wdt:P279 wd:Q24925.
  # {?person wdt:P103 wd:Q188} union {?person wdt:P1412 wd:108}.
  # ?person wdt:P106 wd:Q18844224
  optional {?person wdt:P569 ?dob}
  optional {?person wdt:P570 ?dod}
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

Try it!

Thanks for any suggestions on how to make this work.--178.201.237.185 22:19, 14 April 2019 (UTC)

Something along these lines. Two blocks of unioned requirements; the first looking for something SFish; the second looking for something Germanish. You could throw more countries into the VALUES statement, if there are any.
SELECT distinct ?person ?personLabel ?dob ?dod WHERE
{
  ?person wdt:P31 wd:Q5.           #human
  ?person wdt:P21 wd:Q6581072.     #female
#sf-ish
  {?person wdt:P106 wd:Q18844224}         #sf writer
  union                                   #and/or
  {?person wdt:P136/wdt:P279* wd:Q24925.} #genre or subclass thereof=sf
#German-ish  
  {?person wdt:P103 wd:Q188 .}            #native lang = German
  union                                   #and/or 
  {?person wdt:P1412 wd:Q108 .}           #spoken/written lang = German
  union                                   #and/or
  {?person wdt:P27 ?Germanish .}          #citizen of (some sort of) Germany
  union                                   #and/or
  {?person wdt:P19/wdt:P131* ?Germanish .} #born somewhere within (some sort of) Germany
  VALUES ?Germanish {wd:Q183 wd:Q16957 wd:Q713750 wd:Q7318}           
  optional {?person wdt:P569 ?dob}
  optional {?person wdt:P570 ?dod}
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
} order by ?personLabel
Try it! --Tagishsimon (talk) 23:28, 14 April 2019 (UTC)
Thanks for your help! I pointed out this query at the discussion page of the list article and asked for help improving the WD entries. Maybe WD and WP can help each other out. I wonder if relevant WD queries can be integrated in WP articles? It must be a bonus, especially for WP versions with few writers or topics which are somewhat remote for the speakers of a particular language.--178.201.237.185 18:15, 15 April 2019 (UTC)

Federated Query including variable from own Knowledge BaseEdit

Dear everybody,

I am workin on this query in which I would like to use positions stored on my own server. I would like to find out what is located around these positions using the power of wikidata.

The query running on my server gives me the following result:


                [...] <binding name="wktLoc">
               <literal datatype="http://www.opengis.net/ont/geosparql#wktLiteral">POINT(8.3779196 49.0135909)</literal>
           </binding> [...]

I now would like to use the location wktLoc to find out what buildings etc wikidata knows about. The federated neste, query then looks like this:

PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX myNamespace:<http://myNamespace.com#>


SELECT ?place
WHERE {
{SERVICE <https://query.wikidata.org/sparql>
 {  SERVICE wikibase:around {
      ?place wdt:P625 ?location .
      bd:serviceParam wikibase:center ?wktLoc.
      bd:serviceParam wikibase:radius "1" . }
	  {
	  SELECT (STRDT(CONCAT("POINT(",str(?lon)," ", str(?lat),")"),geo:wktLiteral) AS ?wktLoc)
		WHERE {
		?Report a myNamespace:Report .
		?Report myNamespace:hasReportLocation ?location.
		?location myNamespace:latitude ?lat.
		?location myNamespace:longitude ?lon.
		}
	  }
 }
}
}

Try it!

Unfortunately, I receive an empty result. Does anyone have experience on this or could point me to my mistake?

Thanks and best!  – The preceding unsigned comment was added by JohnnyMoonshine (talk • contribs) at 12:47, 15 April 2019‎ (UTC).

@JohnnyMoonshine: See https://w.wiki/334 -- Luitzen (talk) 16:47, 15 April 2019 (UTC)
@Luitzen: Hey, thanks a lot! What does the dot do at the end of the first query? Namely the one in line 11 of your query?  – The preceding unsigned comment was added by JohnnyMoonshine (talk • contribs) at 06:03, 16 April 2019‎ (UTC).
It just improves readability; consider it as a kind of JOIN. In short, you shouldn't put your local triple patterns inside the SERVICE clause. -- Luitzen (talk) 07:31, 16 April 2019 (UTC)

Wikidata merging proposalEdit

Q131877 and Q18113858 are connecting same content for most of the languages. I'm really confused. Could we make one data page for all pages which has natural rubber (+ synthtetic rubber), and one for synthetic rubber only (who has it)?

That's exactly what we have - rubber (Q18113858), which has subclasses synthetic rubber (Q6714735) and natural rubber (Q131877) --Tagishsimon (talk) 20:20, 15 April 2019 (UTC)
Thank you!  – The preceding unsigned comment was added by Xunonotyk (talk • contribs) at 06:57, 16 April 2019‎ (UTC).

Why some optional "?use" values show up but not others?Edit

I'm scratching my head wondering why some of the OPTIONAL "?use" values show up but not others (e.g. Afghanistan, which clearly has values for "use").

Here's my query:

SELECT DISTINCT ?country ?countryLabel ?numberLabel ?useLabel WHERE {

 ?country wdt:P2852 ?number .
 OPTIONAL {?number wdt:P366 ?use .}
 SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }

} ORDER BY asc(?countryLabel)

 – The preceding unsigned comment was added by 72.74.138.246 (talk • contribs) at 16:00, 6 April 2019 (UTC).

use (P366) is used as a qualifier to emergency phone number (P2852), here is a way of retrieving it:
SELECT ?country ?countryLabel ?numberLabel ?useLabel WHERE {
 ?country p:P2852 ?p2852stm .
 ?p2852stm ps:P2852 ?number . 
 OPTIONAL { ?p2852stm pq:P366 ?use }
 SERVICE wikibase:label { bd:serviceParam wikibase:language "en,fr,nl,es". }
} 
ORDER BY ?countryLabel ?numberLabel
Try it!
--Larske (talk) 18:00, 16 April 2019 (UTC)

So I imagine WikiData is using some sort of "sugar" in order to be able to fetch the indirected "emergency phone number" statement per country by right of being able to use ordinary "?country wdt:P2852 ?number" notation to fetch the number (even though it is one level of indirection) -- correct? Or are the first level embedded statements an entailment?  – The preceding unsigned comment was added by MJSfoto1956 (talk • contribs) at 21:01, 16 April 2019‎ (UTC).

@MJSfoto1956: I refer you to my essay on qualifiers & references at User talk:Tagishsimon#Wittylama for an explainer on, err, qualifiers such as pq:P366, & references. --Tagishsimon (talk) 21:49, 16 April 2019 (UTC)

Thanks for the link, I'm just beginning to understand it. But that is not what I was inquiring about. I was interested in "how" WikiData retrieves an embedded statement value (one level of indirection) when using ordinary "?country wdt:P2852 ?number" -- which works perfectly btw. Are they using an entailment to effectively "duplicate" the embedded values as triples local to the parent node? Or do they have some magic in their implementation that does it on-the-fly? Recall that wdt:P2852 is the IRI of the parent node, not the statement.  – The preceding unsigned comment was added by 72.74.138.246 (talk • contribs) at 22:15, 16 April 2019‎ (UTC).

List of Qid linked to french wikiEdit

Hello I'd like to get a list of Qid (say airports), their french wikidata label + their fr wikipedia article title (I have doubts on correct linking between wikidata and wiki articles).

Thanks! Bouzinac (talk) 12:43, 17 April 2019 (UTC)

@Bouzinac:
SELECT ?item ?itemLabel ?sitelink ?article WHERE {
  ?item wdt:P31/wdt:P279* wd:Q62447.
  SERVICE wikibase:label {bd:serviceParam wikibase:language "fr" .  }
  ?sitelink ^schema:name ?article .
  ?article schema:about ?item ;
          schema:isPartOf <https://fr.wikipedia.org/> .
  }
Try it! --Tagishsimon (talk) 13:48, 17 April 2019 (UTC)

QUERY FOR EXACT SEARCH OF ENTITY LABELEdit

Hi,

Can you please provide the query for the following:

1.Query to check If a WORD is an ENTITY- like 'MUTUAL FUND' IS AN ENTITY OR NOT? EXACT MATCH 2.ALL the ENTITES DATA EXPORT FOR finance

It will be a great help.

Thanks in Advance.

Anubhav Singh  – The preceding unsigned comment was added by 150.129.237.154 (talk • contribs) at 18:27, 17 April 2019‎ (UTC).

Locating aticles without photosEdit

Can Wikidata be used to locate articles that currently don't have any photos/images for which parralel articles in another specific Wikipiedia edition do have photos/images?

I would like to be able to produce a list of all the articles in the Hebrew Wikipedia which do not yet have any photos/images but for which parralel articles in the English Wikipiedia do have photos/images. Is that even possible? WikiJunkie (talk) 11:06, 18 April 2019 (UTC)

No. Other tools to do that may be available. Andy Mabbett (Pigsonthewing); Talk to Andy; Andy's edits 17:37, 18 April 2019 (UTC)

Get items with a higher administrative unitEdit

I am looking for every Naturschutzgebiet (Q759421) where the item given at located in the administrative territorial entity (P131) has the statement: instance of (P31) rural district of Germany (Q106658) Thanks.--GPSLeo (talk) 19:25, 18 April 2019 (UTC)

SELECT ?item WHERE { ?item wdt:P31 wd:Q759421; wdt:P131/wdt:P31 wd:Q106658 }
Try it!  —MisterSynergy (talk) 19:37, 18 April 2019 (UTC)
Thanks a lot. --GPSLeo (talk) 21:39, 18 April 2019 (UTC)

Federation with DBpediaEdit

PREFIX dbpedia2: <http://dbpedia.org/property/>
PREFIX dbpedia: <http://dbpedia.org/>
PREFIX dbont: <http://dbpedia.org/ontology/>
PREFIX : <http://dbpedia.org/resource/>
SELECT DISTINCT *
WHERE {
 ?person dbpedia2:birthPlace :Turkey;
 rdf:type dbont:MusicalArtist;
 dbpedia2:name ?name.
}
ORDER BY ASC(?name)

Try it!  – The preceding unsigned comment was added by 212.156.230.146 (talk • contribs) at 20:33, 18 April 2019‎ (UTC).

More like this, I guess:
PREFIX dbp: <http://dbpedia.org/property/>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX : <http://dbpedia.org/resource/>

SELECT DISTINCT * WHERE {
  SERVICE <http://dbpedia.org/sparql> {
    ?person rdf:type dbo:MusicalArtist; dbp:name ?name.
  }
} ORDER BY ASC(?name)
Try it!
mw:Wikidata Query Service/User Manual/SPARQL Federation endpoints might be of interest. —MisterSynergy (talk) 20:49, 18 April 2019 (UTC)
A sample on how to join Wikidata and dbpedia datas from dbpedia mappings to Wikidata (using owl:sameAs)
PREFIX dbp: <http://dbpedia.org/property/>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX : <http://dbpedia.org/resource/>

SELECT DISTINCT ?person ?name ?wdperson ?familynameLabel WHERE {
  SERVICE <http://dbpedia.org/sparql> {
      ?person rdf:type dbo:MusicalArtist; dbp:name ?name.
      ?person owl:sameAs ?wdperson .
      values ?person {<http://dbpedia.org/resource/Bonnie_Tyler>}
  }
  
  ?wdperson wdt:P735 wd:Q4689423 ; wdt:P734 ?familyname .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  
} ORDER BY ASC(?name)
Try it!
Maybe it would be more efficient to use the mapping to dbpedia stored in Wikidata because « sameAs » in dbpedia also maps to other resources, which multiplies the number of lines returned from the dbpedia service however. author  TomT0m / talk page 13:08, 19 April 2019 (UTC)

adding item label (or title) to a queryEdit

@MisterSynergy: Some time ago, you were clever enough (and kind enough) to generate the following query for me. Can you add the article title (item label?) to the query?

SELECT ?item ?doi WHERE {
  VALUES ?doi { '10.1126/SCIENCE.156.3775.636' '10.1145/358027.358042' }
  ?item wdt:P356 ?doi .
}

Try it!

Thanks in advance. Trilotat (talk) 05:07, 19 April 2019 (UTC)

I think we should look for titles in title (P1476), thus this is the query:
SELECT ?item ?doi ?title WHERE {
  VALUES ?doi { '10.1126/SCIENCE.156.3775.636' '10.1145/358027.358042' }
  ?item wdt:P356 ?doi .
  OPTIONAL {
    ?item wdt:P1476 ?title .
  }
}
Try it!  If was is no title for some of the articles, you would see them listed nevertheless, but with an empty field in the title column. —MisterSynergy (talk) 05:28, 19 April 2019 (UTC)
I sure feel foolish for not figuring that out. I tried ?doiLabel and ?itemLabel, but not ?title. Thanks! Trilotat (talk) 05:44, 19 April 2019 (UTC)

Identifier with certain stringEdit

Hi all! would it be possible to have a query for all the items having only one value of Enciclopedia Italiana ID (P4223) and this single value cointains the string "_res-"? Thank you very much, --Epìdosis 17:16, 19 April 2019 (UTC)

SELECT ?item (SAMPLE(?identifier) AS ?id) WHERE {
  ?item p:P4223/ps:P4223 ?identifier .
  FILTER(CONTAINS(?identifier, '_res-')) .
} GROUP BY ?item HAVING(COUNT(?identifier) = 1)
Try it!  —MisterSynergy (talk) 17:33, 19 April 2019 (UTC)
@MisterSynergy: Thank you, just one thing: if an item (e.g. Sigmund Freud (Q9215)) has only one value of Enciclopedia Italiana ID (P4223) cointaining "_res-" but has also one or more other values of Enciclopedia Italiana ID (P4223) without "_res-", this item should not be a result of the query. Would it be possible? --Epìdosis 17:37, 19 April 2019 (UTC)
Ooops, I messed it up and filtered too early. This one should be better:
SELECT ?item ?identifier WITH {
  SELECT ?item WHERE {
    ?item p:P4223/ps:P4223 ?identifier .
  } GROUP BY ?item HAVING(COUNT(*) = 1)
} AS %subquery WHERE {
  INCLUDE %subquery .
  ?item p:P4223/ps:P4223 ?identifier .
  FILTER(CONTAINS(?identifier, '_res-')) .
}
Try it!  —MisterSynergy (talk) 17:46, 19 April 2019 (UTC)
@MisterSynergy: Perfect! I've posted it in Property_talk:P4223#Appendices. Bye, --Epìdosis 18:20, 19 April 2019 (UTC)