Jump to content

Talk:Wikidata Query Service/Archive 1

From mediawiki.org
Latest comment: 2 years ago by Aidhog in topic Bug on sample?

More in Wikidata

See also suggestions at https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/suggestions

Duplicates and missing rows.

I am getting duplicates and missing rows. The duplicates seem to arise when the a value has been edited in the references. I do not know why the row is missing.

An example of a duplicate with the below SPARQL is "wd:Q21076992 * En røv bag øret" and the missing one is "wd:Q21083886 * Beton - historier fra skurvognen" from [1]. I am also getting duplicate elements, e.g., "Ove Dahl, Ove Dahl (politi)". This seems also to be related to editing the value.

PREFIX p: <http://www.wikidata.org/prop/>
PREFIX v: <http://www.wikidata.org/prop/statement/>
PREFIX q: <http://www.wikidata.org/prop/qualifier/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX prov: <http://www.w3.org/ns/prov#>

SELECT ?work ?workLabel ?author ?authorLabel ?genre ?location ?locationLabel ?geo ?location_statement ?citat WHERE {
  ?work wdt:P31/wdt:P279* wd:Q386724 . 
  ?work wdt:P50 ?author .
  ?work p:P840 ?location_statement .
  ?location_statement v:P840 ?location .
  ?location wdt:P17 wd:Q35 .
  ?location wdt:P625 ?geo . 
  OPTIONAL {
    ?work wdt:P136 ?genre . 
    ?location_statement prov:wasDerivedFrom ?ref .
    ?ref pr:P1683 ?citat .
  }
  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "da,en" . }
}

Try it!

Fnielsen (talk) 22:16, 15 October 2015 (UTC)

This issue has now been phabricated: https://phabricator.wikimedia.org/T116622Fnielsen (talk) 17:53, 26 October 2015 (UTC)

Scratch pad

A scratch pad beside the query box would be really convenient for quickly storing queries. The pgAdmin tool for managing Postgresql databases has had this feature for years (http://www.pgadmin.org/docs/1.6/images/query.png). The main use case is when people are experimenting with queries, they often need a temporary place (ends up being a text file) to store and compare variations of a query. This feature is an effective and "low-tech" alternative to providing multiple tabs for running queries.

Rename page and subpages

Should this page and subpages be titled 'Wikidata Query Service' ? John Vandenberg (talk) 02:37, 6 January 2016 (UTC)

Exceptions and timeouts using wikidata query service

Hi there,
there might be a problem with the current wikidata query service.
I try to write a tool, which can answer questions with given answer candidates. To accomplish this I match the children of a parsed entity from the question and match the found candidates with the given.

One way which is realy fast and effective is using queries like these:

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX entity: <http://www.wikidata.org/entity/>
PREFIX y: <http://www.wikidata.org/prop/statement/>

SELECT distinct ?a ?y ?aLabel WHERE {
 entity:Q42 ?y ?a . SERVICE wikibase:label { bd:serviceParam wikibase:language "de" .
}
}

Try it!

But currently I am receiving timeouts or exceptions

This seems to be fine now. --Smalyshev (WMF) (talk) 18:43, 16 March 2016 (UTC)

"Execute" shortcut

Can we have a keyboard shortcut for the "Execute" button, please? --Magnus Manske (talk) 12:34, 9 March 2016 (UTC)

Yes Done

"Error:"

This one gives a blank error. Query via WDQ2SPARQL, converted from CLAIM[131:(TREE[1198][150][131])] AND CLAIM[31:(TREE[473972][][279])]. --Magnus Manske (talk) 18:39, 10 March 2016 (UTC)

I think that is the same as phab:T127014 added as another example there. - Jan Zerebecki 14:32, 11 March 2016 (UTC)
Yes, there's something fishy there, I'm looking into it. Smalyshev (WMF) (talk) 18:43, 16 March 2016 (UTC)

Something seems to have happened recently that broke old short URLs, such as tinyurl.com/htb92er . You can see the query in the final URL, but it doesn't appear in the box, and can't be executed. Cheers, Bovlb (talk) 20:55, 22 March 2016 (UTC)

Which browser are you using? --Lydia Pintscher (WMDE) (talk) 15:58, 23 March 2016 (UTC)
That's an excellent question, so I did some testing. I observe this problem using Google Chrome Version 49.0.2623.87 (64-bit) on MacOS, and also using an unknown version of Google Chrome on Windows. I do not observe it in Safari 8.0.7 or Firefox 35.0.1. This used to work fine in Google Chrome, and I'm not aware that I've updated since it was working. The expanded URL is [2] which also fails on Google Chrome. I also observe the same behaviour using the new short link mechanism. Looking in the JavaScript console, I see this error;
 App.js:126 Uncaught TypeError: this._editor.registerCallback is not a function
UPDATE: As I did more testing, the problem disappeared, and old links started working in Chrome. Did you update the site? Now the only console message I see is the relatively benign:
 modernizr-2.8.3-respond-1.4.2.min.js:4 Mixed Content: The page at 'https://query.wikidata.org/#SELECT%20%3Fx%20%3FxLabel%20(MIN(%3Fdate)%20AS%…20%7D%0A%7D%20GROUP%20BY%20%3Fx%20%3FxLabel%20ORDER%20BY%20DESC(%3Fmindate)' was loaded over HTTPS, but requested an insecure font 'http://themes.googleusercontent.com/static/fonts/inconsolata/v5/BjAYBlHtW3CJxDcjzrnZCIbN6UDyHWBl620a-IRfuBk.woff'. This request has been blocked; the content must be served over HTTPS.
Cheers, Bovlb (talk) 16:16, 23 March 2016 (UTC)
It seems your browser cache had an old version of Editor.js which broke App.js

Yes Done (caching problem)

Query Logs

Hello,

would it be possible to get query logs of Wikidata (https://query.wikidata.org/)? I'd love to have them for my research project. Thanks a lot!

Fadirra (talk) 13:54, 31 March 2016 (UTC)

Missing ps/pq

It appears that the ps and pq prefixes are automatically added in the web interface, but not in https://query.wikidata.org/sparql?format=json&query= The automatic prefixes should be consistent. --Magnus Manske (talk) 20:28, 12 April 2016 (UTC)

WDQ2SPARQL query timeout

So I have a deceptively simple WDQ query:

CLAIM[1435:(TREE[916475][][279])] AND CLAIM[131:(TREE[12526][][131])]

which WDQ2SPARQL converts to

SELECT ?item WHERE { ?item wdt:P1435 ?sub0 . ?sub0 (wdt:P279)* wd:Q916475 . ?item wdt:P131 ?sub1 . ?sub1 (wdt:P131)* wd:Q12526 }

Now, WDQ returns the ~1000 items in about 1 second. However, the SPARQL query (can't link to it, because tinyurl prevents me from saving the page) times out (still returns JSON though?). Is there anything you can do on the SPARQL engine or WDQ2SPARQL to improve this? I would like to retire WDQ sooner rather than later, but as long as auto-conversion essentially breaks functionality in downstream tools, I can't do it. --Magnus Manske (talk) 14:22, 13 April 2016 (UTC)

Unlimited path queries are usually the hardest for the engine in my experience. I'll look into what can be done to make it better, maybe use vertex-based search service instead... --Smalyshev (WMF) (talk) 22:19, 16 August 2016 (UTC)

Sardinia (Q1462) is not returned when I query for regions of Italy (Q16110)

This query should return 20 regions but instead only returns 19. Sardinia for some reason is missing. I checked and the relation Q16110 seems to be correctly declared for Sardinia.

This is my query

SELECT * WHERE {?resource wdt:P31 wd:Q16110.}

and this is the result

resource

wd:Q1210
wd:Q1216
wd:Q1222
wd:Q1237
wd:Q1243
wd:Q1250
wd:Q1256
wd:Q1263
wd:Q1273
wd:Q1279
wd:Q1280
wd:Q1282
wd:Q1284
wd:Q1438
wd:Q1443
wd:Q1447
wd:Q1452
wd:Q1458
wd:Q1460

FrBailo (talk) 14:40, 13 April 2016 (UTC)

It's in wdq: http://wdq.wmflabs.org/api?q=claim[31:16110] --Magnus Manske (talk) 15:01, 13 April 2016 (UTC)
Returns 20 now so I assume it's ok. --Smalyshev (WMF) (talk) 22:21, 16 August 2016 (UTC)

Deleted items showing up in queries??

I've been trying to clean up self-instances (which are never logically justified) - the query is at tinyurl.com/jq5hduf - I cleaned up the ones I could, but the remaining 5 are all deleted items like Q21704990. Why is the query service returning deleted items in responses??? ArthurPSmith (talk) 16:03, 13 April 2016 (UTC)

deleted items show up repeatedly: SPARQL server with old cache/data

i have a problem on a couple of user subpages visible best here (notice all the ListeriaBot edits of size +321/-321). the 3 items d:Q1499520, d:Q1792416 and d:Q2560705 were deleted in April 2016, but -since May- are added and removed again and again.

Magnus explained to me that this is because one of the SPARQL servers has current data, but the other has outdated/old cache data (if i understood it correct, see [3] in German).

Can somebody please fix this issue. Holger1959 (talk) 20:17, 4 August 2016 (UTC)

Smalyshev, maybe you can have a look? don't know if you noticed this. Holger1959 (talk) 15:48, 13 August 2016 (UTC)

Should be fine now, please ping me if it is still a problem. --Smalyshev (WMF) (talk) 22:08, 16 August 2016 (UTC)

thanks, seems ok now. Holger1959 (talk) 17:43, 1 November 2016 (UTC)

@Smalyshev (WMF): the problem returned, see diff from yesterday and notice that d:Q1590717 was deleted on 2016-04-30. Holger1959 (talk) 00:34, 3 January 2017 (UTC)

Looks like still old deletes not updated... Should be ok now. --Smalyshev (WMF) (talk) 01:50, 5 January 2017 (UTC)

Not properly synced?

SELECT ?item WHERE { ?item wdt:P131 wd:Q2107 . ?item wdt:P1435 wd:Q15632117 }

(can't link because tinyurl not allowed) should include Q16832586, but doesn't. I tried to purge the item, but no joy. WDQ finds it correctly. Any idea? --Magnus Manske (talk) 14:46, 28 April 2016 (UTC)

Updated data ?

Maybe I'm wrong but it seems that data are for now not updated. Results are different from those of WDQ. Is it an old version? Example: instances of sculpture (or subclass) with image WDQ resultsSPARQL results . Is there somewhere a place to have live information about the service? Thanks --Shonagon (talk) 16:52, 28 April 2016 (UTC)

It is currently catching up and should be all good again soon. --Lydia Pintscher (WMDE) (talk) 09:37, 2 May 2016 (UTC)

Result on map : reverses lat/lon

Latitude and longitude are set in place of the other one.

Yeah there was a switch. Will be fixed tonight. --Lydia Pintscher (WMDE) (talk) 09:34, 2 May 2016 (UTC)

Translation

I cannot find the tool on Translatewiki. Is the UI not internationalized yet? Danmichaelo (talk) 06:53, 2 May 2016 (UTC)

It is not there yet. We've got the patch to make it happen but it still needs some manual work. --Lydia Pintscher (WMDE) (talk) 09:35, 2 May 2016 (UTC)

SPARQL endpoint is down?

I am rarely able to run any query for the past 18 hours or so. When I load the website, the status bar at the bottom eventually displays: "Data last updated: [unable to connect]". Is this possibly related to this task:? https://phabricator.wikimedia.org/T133566seav (talk) 04:12, 3 May 2016 (UTC)

@Smalyshev (WMF): Any idea what happened here? --Lydia Pintscher (WMDE) (talk) 08:41, 3 May 2016 (UTC)
Separate bug has been filed in Phabricator: https://phabricator.wikimedia.org/T134238seav (talk) 13:37, 3 May 2016 (UTC)

Way to get the precision of time values?

Is there a way to get the precision of time values using this service? —seav (talk) 01:58, 5 May 2016 (UTC)

@Seav: See Wikibase/Indexing/RDF Dump Format#Time. Matěj Suchánek (talk) 16:25, 3 October 2016 (UTC)

502 Bad Gateway

I constantly receive 502 bad gateway from spraql query service. I tried with 3 different browsers and it is still the same. Is the problem related with me or the server?

Seems like the server. I haven't been able to query it for some hours now. Danmichaelo (talk) 19:42, 7 May 2016 (UTC)
Found phab:T134238. Danmichaelo (talk) 19:50, 7 May 2016 (UTC)

Completion, Plotting OSM relations in the results, instead of a single coordinate

It would be nice with completion on #defaultView:. Also, when doing the example query that returns rivers, it would be nice if there was an option in the Display drop-down that would show their associated OSM relations. Like with Hessischer Fernradweg R1 (Q1473473). On Wikipedia, clicking the inline map on that page will show the whole route. --Ysangkok (talk) 01:49, 13 May 2016 (UTC)

Blank error and search does not complete

I tried running the following query: PREFIX wdt: <http://www.wikidata.org/prop/direct/><br /> SELECT ?compound ?name ?smiles WHERE {<br /> ?compound wdt:P31 wd:Q11173 ;<br /> rdfs:label ?name .<br /> OPTIONAL {?item wdt:P233 ?smiles}<br /> }

and the query runs, but after a few seconds the text ERROR: appears, but no message is displayed. The query doesn't display a time out and appears to continue running for minutes until I close the browser window. Without the OPTIONAL statement the query will return 156546 results in 8138 ms. I get the same error if I use the OPTIONAL statement looking for other properties eg P234 (inchi). Any ideas on what the error is? Is it my query or a bug? Ideally I would like to get InChIs and SMILES data where they exist for a compound. Thanks --The chemistds (talk) 10:18, 2 June 2016 (UTC)

Handling properties with variable unit types

[Disclaimer: My knowledge of SPARQL and other query languages is almost zero.]

I'm trying to see how well I can generate lists of geographical entities (mountains, lakes, rivers, etc.) sorted by a particular measured physical property: elevation, area, volume, depth, length, width, etc. Here's an example Wikidata Query that actually works (after a fashion):

#Any instance of any subclass of "lake" listed by volume
SELECT ?lake ?lake_label ?volume ?vol_units ?lake_subclass_label 

WHERE 
{
    ?lake wdt:P31 ?lake_subclass.                  # find items that have "instance of (P279): lake_subclass"
    ?lake_subclass wdt:P279* wd:Q23397.            # ... where lake_subclass is "subclass (P279): lake (Q23397)"
    ?lake wdt:P2234 ?volume filter(?volume >= 10)  # filter to include only volumes at least 10 (unit unknown) 
    
    OPTIONAL {?lake_subclass rdfs:label ?lake_subclass_label filter (lang(?lake_subclass_label) = "en") .} 
    OPTIONAL {?lake rdfs:label ?lake_label filter (lang(?lake_label) = "en") .} 
}
ORDER BY DESC(?volume)
LIMIT 200

Try it!

Once I got to this point I discovered that a lot of the lakes showing up at the top of my list of largest lakes were actually mid-sized lakes in Sweden. After some digging I discovered that some lake volume figures are given in cubic meters and others in cubic kilometers. Clearly these can be converted, so long as I can identify which unit of measurement is being used for each and adjust it as needed. How would I do that? (I tried a lot of times and failed.) This seems to be a pretty broadly applicable requirement as there are lots of properties here that accept values with various types of units.

Also, some items show up more than once. For example, the Caspian Sea (Q5484) shows up twice because it is an instance of both an endorheic lake (Q9019918) and a salt lake (Q188025), both of which are subclasses of lake. Is there a way I can rewrite the query so that I don't get duplicate items? Rupert Clayton (talk) 22:59, 7 June 2016 (UTC)

Queries are down at this time: (6th of July 2016 : 7:16 UTC).

Is the number of arguments in a query limited?

Hi, I just wonder whether there is some limitation as to the length of a query. Here is the query: tinyurl.com/zdn4lfl

When I add more fields, the server returns "ERROR: Could not contact server" Is this a feature or a bug? Is it documented somewhere? -- Beat Estermann (talk) 22:13, 16 July 2016 (UTC)

Why don't URIs work in queries?

This works:

SELECT ?item ?itemLabel
    WHERE {
      ?item wdt:P828 wd:Q12206 .
      SERVICE wikibase:label {
      bd:serviceParam wikibase:language "en" .
      }
    }

This doesn't:

SELECT ?item ?itemLabel
    WHERE {
      ?item <http://www.wikidata.org/entity/P828> <http://www.wikidata.org/entity/Q12206> .
      SERVICE wikibase:label {
      bd:serviceParam wikibase:language "en" .
      }
    }
You need to use different URL for property, wdt: prefix is http://www.wikidata.org/prop/direct/ so full URL is http://www.wikidata.org/prop/direct/P828. See: https://www.mediawiki.org/wiki/Wikibase/Indexing/RDF_Dump_Format#Full_list_of_prefixes --Smalyshev (WMF) (talk) 22:11, 16 August 2016 (UTC)

Add WDQ to SPARQL conversion?

Many of Magnus's tools (eg PetScan) now have a wonderful WDQ2SPARQL feature which can take a standard WDQ query (eg claim[31:5]) and convert it into the correct SPARQL form. Given how relatively easy WDQ is to remember for simple queries, and that this conversion tool works so neatly on PetScan, could it be added as a feature on the Wikidata query service as well? Andrew Gray (talk) 19:44, 2 August 2016 (UTC)

You can use http://tools.wmflabs.org/wdq2sparql/ Smalyshev (WMF) (talk) 05:34, 6 August 2018 (UTC)

Add support for bds: to SPARQL endpoint?

Blazegraph supports full text search which can be executed in SPARQL with bsd: predicates. Would it be possible to add support for bsd:?

For example:

prefix bds: <http://www.bigdata.com/rdf/search#>
select distinct (?event as ?Source)
where {
  ?event ?p ?eventLabel .
  ?eventLabel bds:search "olympics" .
}

Try it!

This currently results to the following error message:

"No free text index?"

Well, this is because free text index has not been enabled :) We are working on integrating WDQS with our own full-text index solution that is indexing wikidata, see phab:T141813. --Smalyshev (WMF) (talk) 22:13, 16 August 2016 (UTC)

Suggestion: Query formatting function

Hi, Just have to say I love the SPARQL interface. Slick and with very useful functionality!

The only little thing I wish sometimes, is ability to automatically format the query , with nesting, spacing etc.

This is useful sometimes when pasting queries copied from oneliners (such as when they have been embedded in URLs) etc.

The Wikidata query service delivers http links (without TLS encryption) in the query results. Could you please switch to https, or at least use protocol-relative links? Example: go to the query service, select the very first example (“Cats”), and look at the links in the “item” column. Thanks! —MisterSynergy (talk) 10:48, 2 September 2016 (UTC)

These are entity identifiers, not links. They need to be fixed and unique for an item, and traditionally most linked data ontologies use http in their URI schemes, almost nobody uses https. This does not mean if you want to use this URI to access the data you have to use http. BTW, what is the problem with identifiers using http URIs? --Smalyshev (WMF) (talk) 19:31, 7 September 2016 (UTC)
Thanks for response. The entity identifiers are used as links here, but not fully displayed as such in the GUI (they are listed as "wd:Qxxxx"). I am often using public unencrypted wireless networks and try to hide as much traffic as possible with https, and I am also not sure whether anything sensible such as cookies are sent unencrypted if I click on unencrypted links. It would suffice if I could activate https links as an option in the WDQS GUI, in those situations where I am not primarily interested in entity identifiers. --MisterSynergy (talk) 19:42, 7 September 2016 (UTC)

RGB

Do RGB color values only work when they are upper case? Example:

{{sparql|query=
# Languages and the grammatical cases they have in common
SELECT ?item ?itemLabel ?case ?caseLabel (concat("F3A2FF") as ?rgb)
WHERE
{
	?item wdt:P2989 ?case .
	SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
}}

--Tobias1984 (talk) 13:09, 3 September 2016 (UTC)

Getting started

I'm unable to find documentation on Wikidata query service that is complete enough to actually write queries. Everything I've found is hit or miss.

As an example, I started out with a query, which is found at Wikidata Property talk:P569 (search for "Wrong calendar and click on "Violations query")


My intent was to add a new requirement, in addition to the date-related requirement, that the item have the property "Country of citizenship" and the value of that property be "Kingdom of Great Britain". So I modified the query by adding this line:

?item p:P27 wd:Q161885 .

on a separate line just above the right curly brace.

This query didn't return any results. I couldn't find any documentation that one could read from the point of view of "this is what I want to do, how do I do it?" Any suggestions? Jc3s5h (talk) 23:35, 30 September 2016 (UTC)

Jens on my team is currently working on better documentation. Hope to have something to show in a week. --Lydia Pintscher (WMDE) (talk) 11:07, 2 October 2016 (UTC)
@Lydia Pintscher (WMDE): i'm very interested in such a beginners' guide too. is there a "better documentation" somewhere now? Holger1959 (talk) 00:42, 1 December 2016 (UTC)
Check out d:Wikidata:SPARQL query service/Wikidata Query Help. --Lydia Pintscher (WMDE) (talk) 10:20, 1 December 2016 (UTC)

Missing data in query

I'm trying to query cities. Algiers (Q3561) is an instance of capital (Q5119) and city (Q515). But when I make the following query, information about city is lost and result consists only of one entity.

SELECT * {wd:Q3561 wdt:P31 ?class}

https://query.wikidata.org/#SELECT%20%2a%20%7Bwd%3AQ3561%20wdt%3AP31%20%3Fclass%7D

I get the following result: wd:Q5119, but I expect it to be wd:Q515 and wd:Q5119

Is it a bug, or am I doing something wrong? --176.14.69.93 19:38, 1 October 2016 (UTC)

See for instance phab:T125558#1990988. Matěj Suchánek (talk) 16:21, 3 October 2016 (UTC)

Label service button

Could we have a button that adds the "label service" magic incantation? Maybe before the last "}", or just append otherwise? We can move it around as needed, just copying that thing all the time gets annoying... --Magnus Manske (talk) 13:19, 13 October 2016 (UTC)

New visitors do not see the "Run" button because my query is very long.

When I send lay people to my shiny query, all they see is a wall of text, and nothing to click on. That's because my query has many lines, even though I have compacted the code a lot.

SOLUTION: Make the query area scrollable if the query is more than 20 lines.

What do you think about it? Thanks! Syced (talk) 13:23, 14 October 2016 (UTC)

Knowledge Graph

Hello, please add information on blogger Alexei Pechkurove https://www.wikidata.org/wiki/Q27303908 in the Knowledge Graph

This item was deleted as spam. Syced (talk) 08:09, 18 October 2016 (UTC)

number align

it would be useful right align numeric columns or count columns--Edoardo88 (talk) 11:45, 1 November 2016 (UTC)

SPARQL servers use different item order system?

Smalyshev, maybe you can have a look into the following issue:

we have a problem on dewiki with a couple of pages visible best in this example (notice all the ListeriaBot edits of size +/- 0) or here for 2016-10-31/11-01. Some specific items are reordered/rearranged again and again, otherwise nothing is changed. it looks as if the reason is only a slightly different order (alphabetical, per ID, or similar, don't know).

As far i know, ListeriaBot uses SPARQL servers, which may have a bit different cache data (see above). Can you identify a pattern and fix this behaviour please? Holger1959 (talk) 17:43, 1 November 2016 (UTC)

@Holger1959: In general, items order is not guaranteed unless you explicitly sort them. So it could be the bot gets different order in different queries. I guess it should either ask for some kind of sorting or check that the set of entries did not change despite different order and not change, not sure. --Smalyshev (WMF) (talk) 20:26, 1 November 2016 (UTC)
Smalyshev, thank you for the reply. the sorting in our lists is usually done by property, and within a property section by alphabet. is there something special Magnus could add to his bot or to the Wikidata list template? (i don't understand the technics myself) Holger1959 (talk) 21:53, 1 November 2016 (UTC)
I am using the PHP Collator class to get proper sorting in the respective language. Not sure why that would "flip" the sort order. Investigating, but if you have any ideas, let me know. Relevant code, and here as well. --Magnus Manske (talk) 11:13, 2 November 2016 (UTC)
Update: Have fiddled with the code, I hope it's sorting more stable now, without breaking anything. Let me know please. --Magnus Manske (talk) 10:32, 3 November 2016 (UTC)

Image grid and timeline view not working anymore since display types update?

Before the addition of the (very awesome!) new types of displays, I could select an image grid and a timeline view for a query like this one. Now not anymore - those view options are greyed out ('bubble chart' as well). Is this intentional? Spinster (talk) 18:39, 1 November 2016 (UTC)

Yes, sorry, known bug, will be fixed soon. --Smalyshev (WMF) (talk) 20:26, 1 November 2016 (UTC)

Textual representation fails when using VALUES

In my (well initially prepared with help of I don't remember who on #wikidata) query tinyurl.com/jhhq89r (btw, why don't we have a url shortening service specifically for SPAQRL which would allow not to have it blacklisted?) after I used VALUES the textual representation is sure that I am looking for anything. That is rather unfortunate since it is handy in picking needed item without need to look it's entity id up directly on Wikidata, while I used VALUES to define a variable exactly for merging value used in 2 places into one being. --Base (talk) 00:07, 7 November 2016 (UTC)

Well it looks I still can use its window to actually look up entities but well still the original thing is a bug. --Base (talk) 00:18, 7 November 2016 (UTC)

Simple query does not work (dewiki project)

this question is related to a comprehensive Wikidata project on dewiki.

  • background: i use Magnus' ListeriaBot for many pages on dewiki, all related to geographical objects in Germany. The goal and usage is broad: better sorting items by federal state>district>municipality, finding wrong classifications, adding missing descriptions/images/Commonscat/etc (example page for one district). this is extremely helpful and my (together with Aeroid's) subpages cover already 11 of 16 federal states of Germany by district/independent city using queries like "all items [P131] located in the administrative territorial entity, including [P150] subdivisions, and sorted by [P31] instance of". Additionally, queries for certain topics are used on associated subpages, eg. "all rivers/mountains/cultural heritage monuments/windmills/etc located in [administrative unit]". This worked fine for months.
  • problem: about 2 weeks ago, queries stopped working for some topics, eg. "all protected areas in a certain administrative unit". ListeriaBot with WDQ displays an error, with SPARQL it displays "no items" and when using query.wikidata.org i see only "Query timeout limit reached".
  • example:
    • see subpage DE-RP (German state of Rhineland-Palatinate)
    • old WDQ definition for ListeriaBot CLAIM[131:(TREE[1200][150][131])] AND CLAIM[31:(TREE[473972][][279])] worked fine for months, stopped working (errors)
    • new SPARQL definition works on DE-SL (German state of Saarland), cf. [4] and following bot edits
    • new SPARQL definition does not work for DE-RP (only difference is the federal state item Q1200 instead of Q1201) and for other related/similar queries:
SELECT ?item WHERE {
  ?item wdt:P131 ?sub0 .
  ?tree0 (wdt:P150)* ?sub0 .
  ?tree0 (wdt:P131)* wd:Q1200 .
  ?item wdt:P31 ?sub1 .
  ?sub1 (wdt:P279)* wd:Q473972 .
}
Try it!

Smalyshev (WMF), could you have a look into this, or tell an other staff member with SPARQL experience to help, please? the users who work on these topics are really lost without Listeria worklist updates and/or without functioning query.wikidata.org. Maybe you know an alternative query to achieve the same result, as it was possible with the WDQ definition given above? (please note that my own understanding of SPARQL, unfortunately, is limited, and none of the other users i asked was able to find a solution.) Holger1959 (talk) 02:03, 8 December 2016 (UTC)

@Holger1959: The query doesn't seem right but I'm not sure wherer it's me not understanding what it's supposed to do or conversion bug. I think "protected items in specific territory" should be give by this:
SELECT ?item WHERE {
  ?item wdt:P31/wdt:P279* wd:Q473972 .
  ?item wdt:P131 ?territory .
  wd:Q1200 wdt:P150* ?territory .
}

Try it!

but please verify if it's indeed the case and if not, please point me to what's missing. --Smalyshev (WMF) (talk) 21:41, 9 December 2016 (UTC)

@Smalyshev (WMF): many thanks for your help! the new query at least works (no timeouts), but the results are incomplete (only ca. 1/5 of items formerly found). i am currently trying to get help by an other german-speaking user who seems to understand SPARQL. will report back here if we find a functioning query scheme.
Either way, i still think the results i want to achieve (all objects of type A located in a defined area B, like eg. "all towers somewhere in England"), should only require a simple query. This type of request (or its structure) is rather trivial and very common, isn't it? so i really don't understand why it is so complicated. (in despair) Holger1959 (talk) 06:52, 16 December 2016 (UTC)
@Smalyshev (WMF): now MisterSynergy found the solution! it works also for larger federal states with many items, complete results (as before) and without timeouts.
SELECT DISTINCT ?item WHERE { 
  {
    SELECT ?item WHERE {
      ?item wdt:P31/wdt:P279* wd:Q473972 .
    }
  }
  ?item wdt:P131* wd:Q1200 .
}
Try it!
i hope this example helps also other users with similar query problems. Holger1959 (talk) 18:34, 16 December 2016 (UTC)
The last query does not have P150 check though. Is it not required? --Smalyshev (WMF) (talk) 01:59, 20 December 2016 (UTC)
it gives all relevant results without P150 obviously :) and if needed, we can now use a separate query for P150, which works the same. this solved also a couple of similar problematic queries ("Cities in Saxony"). maybe someone can add this hint to phabricator:T116298? Holger1959 (talk) 00:45, 3 January 2017 (UTC)

WDQ

What is the reason of abolishing such short and convenient syntax? Earlier I used auto-generated WDQ queries like: http://wdq.wmflabs.org/api?q=claim[2936]&noitems=1. And how should I get the number of items with some claim? Compare: "noclaim[31]" and "SELECT ?item WHERE { OPTIONAL { ?item wdt:P31 ?dummy0 } FILTER(!bound(?dummy0))}". What is easier to remember? May be to make at least reverse compatibility? --Infovarius (talk) 12:36, 7 December 2016 (UTC)

The reason is WDQ and Query Service are two completely different tools, which use completely different codebases and completely different platforms. It's not really feasible to implement WDQ syntax on top of SPARQL graph engine, it's be quite a lot of work for which we just don't have resource. You can however use the translator here: http://tools.wmflabs.org/wdq2sparql/w2s.php to translate from WDQ syntax to SPARQL. --Smalyshev (WMF) (talk) 04:46, 13 December 2016 (UTC)
@Infovarius: in SPARQL that is better said:
select * {?item a wikibase:Item. filter not exists {?item wdt:P31 []}}

--Vladimir Alexiev (talk) 19:28, 13 March 2017 (UTC)

@Vladimir Alexiev: Thanks. But I will not remember this, and the translator above (and in PetScan, e.g.) gives me my version... --Infovarius (talk) 16:05, 17 March 2017 (UTC)
https://github.com/smalyshev/wdq2sparql/issues/12 --Vladimir Alexiev (talk)
Another problem with absence of WDQ. I used to get a list of all films (>250 thousands) by WDQ-quering "claim[31:(TREE[11424][][279])]". Now it seems that I have no any alternative... --Infovarius (talk) 16:06, 17 March 2017 (UTC)
This is translated to
SELECT ?item WHERE {
  ?item wdt:P31 ?sub0 .
  ?sub0 (wdt:P279)* wd:Q11424 .
}

Try it!

Which has equivalent but simpler form

SELECT ?item WHERE {
  ?item wdt:P31/wdt:P279* wd:Q11424 .
}

Try it!

Just tested, both of them run fast and return 244k results --Vladimir Alexiev (talk) 15:02, 23 March 2017 (UTC)

Display URLs with an icon

Excellent tool but if you have hyperlinks in a list/map... then they take to much space. I would like to see a possibility t just show a

  • Wiki icon that is clickable
  • Google map icon that is clickable
  • SBL icon that is clickable
  • Spotify icon

Example query displaying gravestones with external links..... - Salgo60 (talk) 13:46, 30 December 2016 (UTC)

Answers questions

  • Do you consider yourself part of the Wikimedia movement?

Yes I am have been working with P2949 and now working with P3217

  • What are you using the service for? (e.g. building an interactive timeline of British prime ministers)

Adding value with references using P3217 that is a source from the Swedish National Archives

  • Were you able to get what you needed from the service?

Its more than excellent but some reports would benefit from not displaying the URL instead an icon

Query parameter for simple json

What is the API parameter for simple JSON. "format=json" gives a standard long format with "results", "bindings", etc. — Fnielsen (talk) 15:12, 8 February 2017 (UTC)

Optimize regex filter

A regex filter now times out when searching on Document Object Model (Q2093)

select * where { ?work wdt:P2093 ?authorname . filter(regex(?authorname, '^G.+Knudsen$')) }

I tried a modification, but that also timed out:

select * where { ?work wdt:P2093 ?authorname . filter(strends(?authorname, 'Knudsen') && strstarts(?authorname, 'G')) }

This is a not entirely satisfactory workaround:

select * where { ?work wdt:P2093 ?authorname . filter(strends(?authorname, 'Knudsen') && strstarts(?authorname, 'G')) } limit 1

Is there any other way to change the query? — Fnielsen (talk) 15:22, 8 February 2017 (UTC)

@Fnielsen: adding
hint:Query hint:optimizer "None"
. gets you a few additional ones. --Esc3300 (talk) 09:54, 26 March 2017 (UTC)
@Esc3300: Do you think that the hint works? I was under the impression that it does not do much when there is only one triple pattern. If I now execute the first statement I listed, I do not get a time out. I suspect that the time out has been set up or that the engine has been improved. — Fnielsen (talk) 19:55, 27 March 2017 (UTC)

Why schema:name and skos:prefLabel are missing?

Trying to get names of concentration camps. This returns a bunch of names for Auschwitz:

curl -L -Haccept:text/turtle https://www.wikidata.org/entity/Q7341

(more schema:name=skos:prefLabel, fewer skos:altLabel

But this returns only altLabels. No matter whether I use schema:name or skos:prefLabel, it returns none of those:

select * {
  ?x wdt:P31 wd:Q328468; wdt:P625 ?coords.
  {?x schema:name ?pref} union  {?x skos:altLabel ?alt}
}

--Vladimir Alexiev (talk) 19:25, 13 March 2017 (UTC)


From Wikidata_query_service/User_Manual#Label_service I grokked that I should use rdfs:label instead of schema:name/skos:prefLabel. What threw me off is that skos:prefLabel and skos:altLabel are both subprops of rdfs:label, so nominally speaking rdfs:label should return both. Oh well, I'll use what is present. --Vladimir Alexiev (talk) 19:49, 13 March 2017 (UTC)

Wikidata Query Short URLs are blocked

When you run a query on Wikidata at https://query.wikidata.org there is a links button with a "Short URL to Result" generator option. But as it produces a tinyurl.com link, you then block it from being saved. Can tinyurl.com be whitelisted for use on User pages? I don't want to have to expand the URL to the full code, or save the tinyurl as plaintext, not a link, to be able to save it. Or can Wikipedia/Wikidata/Wikimedia ensure that all of its INTERNAL tools are able to be used effectively across all sites and not use external services that you block. The-Pope (talk) 15:23, 8 May 2017 (UTC)

Sometimes, broken JSON (latin1 encoding) is emitted when using "Download JSON file"

Steps to reproduce:

SELECT ?label WHERE {
  wd:Q648745 rdfs:label ?label .
}
  • Click run
  • Click the "Download" → "Download JSON file" button
  • Inspect the downloaded file. It is encoded using latin1 and fails to load in any spec-conforming json implementation

I managed to reproduce this using current Chrome and Firefox on Linux.

Ctrl space not working

I tried to control space (in Chrome), and it wasn't working. Is there a breaking bug? Sadads (talk) 23:16, 31 May 2017 (UTC)

Adding simple sameas reasoning

Dear Dev Team, Proposal for language extension for SPARQL.

Here is an example ontology with owl:sameAs statements to rename predicates: https://raw.githubusercontent.com/h4ck3rm1k3/wikidata_varnish/master/enmap.ttl

I would like to add a sparql preprocessor that would take a query like this :

PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX bd: <http://www.bigdata.com/rdf#>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wd: <http://www.wikidata.org/entity/>
prefix owl: <http://www.w3.org/2002/07/owl#>
prefix enmap: <https://raw.githubusercontent.com/h4ck3rm1k3/wikidata_varnish/master/enmap.ttl#>
prefix varnish: <https://raw.githubusercontent.com/h4ck3rm1k3/wikidata_varnish/master/varnish.ttl#>
prefix objects: <https://raw.githubusercontent.com/h4ck3rm1k3/wikidata_varnish/master/objects.ttl#>
prefix void: <http://rdfs.org/ns/void#>

SELECT ?countryLabel WHERE {
  OPTIONAL {varnish:done varnish:import enmap:ontology}
  OPTIONAL {objects:country owl:sameas wd:Q146}
  ?country enmap:sameas objects:country.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY ?countryLabel

the query would be rewritten to :

PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX bd: <http://www.bigdata.com/rdf#>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wd: <http://www.wikidata.org/entity/>
SELECT ?countryLabel WHERE {
  ?country wdt:P31 wd:Q6256.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY ?countryLabel

Here is a proof of concept javascript to implement this : https://github.com/h4ck3rm1k3/wikidata-sparql-varnish-brush

The example ontologies are here: https://github.com/h4ck3rm1k3/wikidata_varnish

wdt: should have normalized values

2016 Quantities

  1. ^ - because we use them in sorting; labels "sq km" "acre" should be inside
  2. we should have an option to use Labeling service to describe values using "hidden labels" back D1gggg (talk) 06:37, 4 July 2017 (UTC)

Probably same remark about values in wds: D1gggg (talk) 06:42, 4 July 2017 (UTC)

Reindent

When working on a complex query with copy-and-paste moving parts around and adding thinks I often get terrible wrong indented source code. I also copy it to vim/some other editor to use the automaticall re-indentation feature every modern editor has. Are there any plans adding this to the online-editor? -- MichaelSchoenitzer (talk) 15:20, 14 July 2017 (UTC)

Query web interface and REST endpoint yielding different results

Hello, I'm running a simple query, trying to get all nodes with ancestor 'software':

SELECT DISTINCT ?entity {?entity wdt:P31+/wdt:P279+ wd:Q7397.}

Using the web interface, I get "63673 Results in 5111 ms." The json object that results from this query: https://query.wikidata.org/bigdata/namespace/wdq/sparql?format=json&query=SELECT%20DISTINCT%20?entity%20{?entity%20wdt:P31+/wdt:P279+%20wd:Q7397.} gives only 1941. Why is that? Am I missing a point? Cheers, −PetaRZ (talk) 15:42, 19 July 2017 (UTC)

Sorry for bothering, I have struggled a lot of time, and just when I posted the question, I've realized that I have "+" signs in my url, which I should have quoted! Really sorry. −PetaRZ (talk) 15:48, 19 July 2017 (UTC)

GeoJson download option

I'm often creating lists of items with Geographical coordinates (P625). What I would like is the option to Download results in GeoJSON. This would make it much easier to load the downloaded files into programs like JOSM. — Preceding unsigned comment added by Hjart (talkcontribs) 26. 7. 2017, 12:51‎ (UTC)

Caching of rand() queries

Suggestion: Do not cache queries that contain

s/\brand\s*\(\)/i

The results are expected to be different each time, that's the whole point of using rand(). Getting the same "random" result set during the caching period is not nice. --Magnus Manske (talk) 10:52, 21 August 2017 (UTC)

Extremely simple query times out

The following query, which simply attempts to count all humans, regularly times out. Unexpectedly though, if I add some filters the query magically works. It looks like the system has problems when the dataset reaches a certain size, but shouldn't "count" just count instances, not save them? Any way to optimize this query to make it work without repeating it several times with binary filtering?— Preceding unsigned comment added by Redgolpe (talkcontribs) 26. 8. 2017, 12:12

SELECT (COUNT(?person) AS ?count) WHERE {
  ?person wdt:P31 wd:Q5
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

Try it!

You have SERVICE in your query but make no actual use of it. Delete it and you should get ~3.5M results. Matěj Suchánek (talk) 14:22, 27 August 2017 (UTC)
Thank you! Redgolpe (talk) 16:55, 27 August 2017 (UTC)
Note also while the query is simple, the set of results is huge. You are going through 3.5M items (with SERVICE clause). This may be slow. Smalyshev (WMF) (talk) 17:44, 18 September 2017 (UTC)

Firefox, query.wikidata.org and long url under HTTP/2

Mozilla has an open issue about query.wikidata.org and long url See https://bugzilla.mozilla.org/show_bug.cgi?id=1402269

This seems to be a server-side issue. As soon as Firefox send the request (and the SETTINGS frames are exchanged and ack'd):

2017-09-26 21:02:54.814765 UTC - [Socket Thread]: I/nsHttp Http2Session::RecvGoAway 0x10a798000 GOAWAY Last-Good-ID 0xF status 0xB live streams=1

It could be due to nginx or varnish being used in front of query. — Preceding unsigned comment added by 203.215.134.58 (talkcontribs) 27. 9. 2017, 02:14‎ (UTC)

Query "Cities in Japan" does not include major cities like Tokyo, Kyoto, Hiroshima..

Hello,

I want to showcase some data visualizations on my website and use a dataset from wikidata, showing the number of cities with more than a million inhabitants from countries worldwide. I used the follogwing query:

SELECT DISTINCT ?cityLabel ?population ?countryLabel WHERE {
?city wdt:P31 wd:Q515. 
?city wdt:P1082 ?population filter(?population >= 1000000).
?city wdt:P17 ?country.
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } }

Try it!

The number of results was suspiciously small and I noticed that some important cities like Tokyo are missing (although Tokyo, for example, has both the P17 and P1082 properties).

When I just look for cities in Japan, with this query:

SELECT DISTINCT ?cityLabel ?population WHERE { 
?city wdt:P31 wd:Q515. 
?city wdt:P1082 ?population. 
?city wdt:P17 wd:Q17. 
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } }

Try it!


again, cities like Tokyo, Osaka, Kyoto or Hiroshima are missing.

Even with this most basic query:

SELECT DISTINCT ?city ?cityLabel WHERE {
?city wdt:P31 wd:Q515. 
?city wdt:P17 wd:Q17. 
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }

Try it!


If such important cities are left out, my first query is quite pointless.

I couldn´t find out why these cities are missing and what I have to change in my query in order to let them appear and would very much appreciate some clarification or further information.

Thanks a lot in advance! — Preceding unsigned comment added by Dkasai (talkcontribs) 4. 10. 2017, 19:55‎ (UTC)

Tokyo is not declared a city and this will probably be the case with the other cities. You can try modifying the predicate to wdt:P31/wdt:P279*. Matěj Suchánek (talk) 16:14, 7 October 2017 (UTC)
Thank you, Matěj Suchánek! That works well. --Dkasai (talk) 18:25, 9 October 2017 (UTC)

How to add another endpoint for the WQS federation

Hi all, Nonoranonqui (talk · contribs) and I would like to know how to add another potential endpoint, the in the Wikidata query service endpoint federation. Is there anyone who can answer us? Thank you very much. --Sannita (talk) 14:59, 7 October 2017 (UTC)

See d:Wikidata:SPARQL federation input. Matěj Suchánek (talk) 16:15, 7 October 2017 (UTC)

Can it have its own URL shortener?

The "Link > short URL" option generates a tinyurl short-link, which is blacklisted by most WMF sites, even on talk pages. Can the Wikidata query service have its own URL shortener so that the short URL can be shared in discussions? Deryck C.Meta 23:26, 8 October 2017 (UTC)

See phab:T112715. Matěj Suchánek (talk) 18:30, 11 October 2017 (UTC)

Brings my browser down but doesn't give any results

I tried to follow some youtube videos on how to use sparql. With the following (i thought very easy) example, the query runs for hours until firefox or chrome crashes:

SELECT ?person ?personLabel ?birthPlace
WHERE {
  ?person wdt:P69 wd:Q447354 .
  ?preson wdt:P21 wd:Q6581072 .
  ?person wdt:P19 ?birthPlace .
          
  Service wikibase:label {
    bd:serviceParam wikibase:language "de" .
  }
}

Also on every change the window bounces forth and back.

kinda crap. Ogmios (talk) 14:41, 3 December 2017 (UTC)

@Ogmios: You've got a typo there: ?preson?person. Matěj Suchánek (talk) 09:49, 30 December 2017 (UTC)

minor typo in Dutch query helper

Hi all,

There is a very minor typo in the Dutch version of the Query helper for the query service. It reads 'fliteren', which is a -however cute- non-existent word in Dutch language, instead of 'filteren', which is the Dutch word for to filter. Not a big priority off course, but just to let you know. Keep up the good work! Mtmlan84 (talk) 08:16, 12 December 2017 (UTC)

@Sjoerddebruin: ^ Would you verify and fix at Wikimedia:Wdqs-ve-filter/nl? Matěj Suchánek (talk) 09:51, 30 December 2017 (UTC)

Export results to clipboard

I normally do some post-processing of query results in spreadsheet. Is it possible to "export" to clipboard (via document.execCommand('copy') all results in tab-delimited format? --Ghuron (talk) 12:25, 28 December 2017 (UTC)

@Ghuron: If you select the table contents with the mouse and copy them, both Firefox and Chromium seem to separate them with tabs by default when pasting in a plain-text context. In Firefox, you can also hold Ctrl to select full table cells, rows or columns. (Note: you might run into phabricator:T185838 for a few more days, but the fix should be deployed soon – in the meantime, you can work around it by selecting Copy from the context menu instead of using Ctrl+C.) --Lucas Werkmeister (WMDE) (talk) 09:59, 5 February 2018 (UTC)
@Lucas Werkmeister (WMDE): it works, but limited to 1000 rows (max number of items displayed per page) --Ghuron (talk) 20:04, 5 February 2018 (UTC)
@Ghuron: Wouldn’t it be better to just download the query results in that case? We have TSV download formats already, so you should be able to use those in your spreadsheet software. --Lucas Werkmeister (WMDE) (talk) 14:56, 6 February 2018 (UTC)
@Lucas Werkmeister (WMDE): yes, that's how I do it today. But that's impose a few additional steps (especially when working with google sheet) --Ghuron (talk) 06:17, 7 February 2018 (UTC)

Timeout with instances of Q1344963

Am I doing something wrong with phabricator:P6583? Is it unreasonable to search "participants of" ~6800 instances of Q1344963? --Nemo 19:21, 14 January 2018 (UTC)

Tag cloud?

How about a tag cloud view? --Shisma (talk) 09:25, 27 January 2018 (UTC)

Tiny URLs not secure

The query service's short URLs, using TinyURL, are http by default. Can we make the default https? Andy Mabbett (Pigsonthewing); Talk to Andy; Andy's edits 18:43, 29 January 2018 (UTC)

Thanks for mentioning it. We are aware that tinyURL is not the best option, for other reasons than security. A project to create a URL shortener for the Wikimedia projects is onwards. Lea Lacroix (WMDE) (talk) 09:01, 5 February 2018 (UTC)
We still(!) don't have a dedicated URL shortener; and our TinyURLs are still insecure. Andy Mabbett (Pigsonthewing); Talk to Andy; Andy's edits 15:59, 28 November 2018 (UTC)

Download result in RDF-native format (when using CONSTRUCT or DESCRIBE)

Hi, I have created some query to extract a little subgraph of Wikidata using CONSTRUCT, but I can't see any option to get the result in RDF-native format like RDF/XML, Turtle, JSON-LD or so. I have also tried to use WDQS remotely as an API, in JavaScript's AJAX I have set headers to Accept: 'text/turtle', it has not fired any error, but returned only the prefix definitions in Turtle syntax. So is there some way to get the RDF graph, not its tabular representation (as can be seen in the WDQS GUI)? Thanks --YjM (talk) 23:51, 1 February 2018 (UTC)

@YjM: For a simple test query, curl -d 'query=CONSTRUCT { wd:Q42 wdt:P31 wd:Q5. } WHERE {}' https://query.wikidata.org/sparql (default format: RDF XML) and curl -H 'Accept: text/turtle' -d 'query=CONSTRUCT { wd:Q42 wdt:P31 wd:Q5. } WHERE {}' https://query.wikidata.org/sparql (Turtle) both seem to work for me. Or am I missing something? --Lucas Werkmeister (WMDE) (talk) 09:47, 5 February 2018 (UTC)
@Lucas Werkmeister (WMDE): It gave me some hard time to make curl running on Windows, but in the end.. at least something works, thanks! Strange, that when I tried to use the API https://query.wikidata.org/sparql in AJAX, it didn't worked the same (as stated above). But what I mentioned in the first place: in the GUI at https://query.wikidata.org/, under the Download menu (after the execution of the query), there is no suitable option (only JSON/CSV/TSV or image). I think, that some people would appreciate some option like Turtle or RDF/XML there. --YjM (talk) 21:36, 5 February 2018 (UTC)
@YjM: Well, this additional download option would only be available for two of four possible query forms, and I think SELECT is by far the most common query form on the query service, so I’m not sure if it’s worth the extra development effort to be honest… do you know if there are many people who integrate the query service with other RDF technologies? I feel like most people use the query service to get results for their queries in some format and then use them in their own fashion, without caring too much about RDF. --Lucas Werkmeister (WMDE) (talk) 15:02, 6 February 2018 (UTC)
@Lucas Werkmeister (WMDE): Sorry for the very late answer, I have forgotten to reply.. Anyway, I have no idea if there are some other people who might be interested in such new feature. Not many I guess, as I am the first one who has complaint about it :-) --YjM (talk) 21:22, 26 April 2018 (UTC)

Adding a Shortcut to the "Examples" menu

For writing documentation, and sharing the query service with other people, it's occasionally useful to want to link to the "Examples" menu, instead of having to write instructions to find it. Would it be possible to add a unique url for that menu? Sadads (talk) 17:56, 5 February 2018 (UTC)

In the following table, top and bottom lines are already implemented features. What I’d like you to consider is the middle line feature. When linking to SPARQL query from outside of Wikdiata, "Auto Execute" feature would be very helpful from outreach perspective. --Was a bee (talk) 07:52, 24 February 2018 (UTC)

Query links to various sandwiches
Link type Status pros cons
Try it! link Already exists Visitor can see SPARQL query code and modify that. If visitor doesn't know that one must press the execute button () to see result, visitor can't understand what this link is for.
https://query.wikidata.org/....&autorun=true Now proposing Visitor can see SPARQL query code and modify that. At the same time, as if the execute button () is automatically pressed, visitor can see the result without do anything. For experienced Wikidata user, auto-run function is no need.
Result link Already exists Visitor can see SPARQL query result automatically. If visitor doesn't know there is a small link (Edit this query) at the bottom-left of the page, visitor can't know there is modifiable source code.

Labels of properties not available in the query service

The labels of properties are not available in the query service.

e.g. The following query fail in retrieving the property labels : "Give me the most common properties and their labels used on instances of Museums or a subclass of Museum" :

SELECT ?p ?count ?pLabel WHERE { { SELECT ?p (COUNT(?o) AS ?count) WHERE { # instances de sous-classes de Musées ?item (wdt:P31/wdt:P279*) wd:Q33506. ?item ?p ?o . } GROUP BY ?p } SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" . } } ORDER BY DESC(?count)


this also shows that no triples are available on a property :

SELECT ?p ?o WHERE { <http://www.wikidata.org/prop/P17> ?p ?o . }

(returns only one triple that says rdf:type owl:ObjectProperty).

Having property labels is a must to start "discovering" the data model. Can they be loaded in the query service ? is there another way to fetch them ? Thanks — Preceding unsigned comment added by Tfrancart (talkcontribs) 17:05, 27 February 2018‎

Properties (as entities in Wikibase) and property predicates are different things. As such, you can not retrieve label from a predicate. You can use this query:
SELECT * WHERE {
  ?prop wikibase:claim <http://www.wikidata.org/prop/P17> .
  ?prop rdfs:label ?label .
  FILTER(lang(?label) = 'en')
}
Try it!
in order to find the labels. Label service could probably do some data transformation for property URIs, it should be possible, but currently this capability does not exist. If you think it'd be useful please add Phabricator task for it. Smalyshev (WMF) (talk) 00:38, 1 March 2018 (UTC)

How to pick only certain entities in WDQS

Hi there,

I have a SPARQL query:

SELECT DISTINCT
    ?key ?keyLabel ?any
    WHERE
    {
        ?key  wdt:P1282 ?any .
        FILTER(regex(?any, "^Key:")).
        ?key rdfs:label ?keyLabel
    }

Try it!

...which works just fine, but there are both Items and Properties in the results. I am not interested in Ps and would like to only pick the Items in the result. Something like:

?key a wikibase:Item .

Try it!

But it does not work (tried several variants of it, non of it worked. Also googled the web and crawled the WD help and found no answer...). Is there some way to do it? Thanks! --YjM (talk) 21:28, 26 April 2018 (UTC)

Oddly enough, I have convinced the WDQS to pick only Properties from the result:

?key a wikibase:Property .

Try it!

...so, even though it is not generally applicable (imagine having also Lexemes in the result), I thought I will work around it with NOT EXISTS {}, but it returns

Query is malformed: Encountered " "not exists" "NOT EXISTS "" at line 8, column 9.

and so on. Update: This was caused by a forgotten "FILTER" keyword, so a mistake on my side. This way is also possible.

So after a while, the only functional workaround which (I hope!) gives the desired resultset is following:

SELECT DISTINCT
    ?key ?keyLabel ?any
    WHERE
    {
        ?key wdt:P1282 ?any .
        FILTER(regex(?any, "^Key:")).
        ?key rdfs:label ?keyLabel.
        MINUS {
          ?key a wikibase:Property 
         }
    }

Try it!

Is some of this behaviour actually intentional? --YjM (talk) 22:09, 26 April 2018 (UTC)

Per Wikibase/Indexing/RDF Dump Format#WDQS data differences:
Types (a or rdf:type) for wikibase:Item, wikibase:Statement, wikibase:Reference are currently omitted for performance reasons.
My workarounds: ?item wikibase:sitelinks [] (or MINUS { ... }) for (non)-items, ?property wikibase:PropertyType [] (or MINUS { ... }) for (non)-properties. Matěj Suchánek (talk) 07:23, 27 April 2018 (UTC)
Thanks Matěj for clarification! --YjM (talk) 12:00, 27 April 2018 (UTC)

Can't click next page button in result

I can't click next page buttons at the bottom-right in result page. For example, open this page[5] and scroll down to the bottom of the result. Then "2044 results in 2854 ms" overlay prohibits clicking next page button. (Does this explanation make sense?) I've encountered this phenomenon in Chrome and IE.--Was a bee (talk) 12:11, 4 August 2018 (UTC)

Looks like it's fixed now. Smalyshev (WMF) (talk) 00:20, 7 August 2018 (UTC)
Oh, that's so nice. Thanks! --Was a bee (talk) 12:36, 8 August 2018 (UTC)

Add code snippet (besides prefixes)

Approximately 50% of time I'm opening monstrous d:Wikidata:SPARQL_query_service/queries/examples because I want to add

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

to my query. It would be nice to have a button "Add code snippet" that acts like "Add prefix" but not only for prefixes --Ghuron (talk) 09:23, 29 November 2018 (UTC)

@Ghuron: You can type "SERVICE" and then press CTRL-Space and code completion will offer you choices to fill the rest. Smalyshev (WMF) (talk) 23:55, 5 December 2018 (UTC)
@Smalyshev (WMF): Doesn't seem to work for me, see screenshot when I'm pressing CTRL-Space. It's chromeos 70.0.3538.110, ru/en keyboard switcher is turned on --Ghuron (talk) 04:15, 6 December 2018 (UTC)
@Ghuron: Don't type the space after SERVICE, just the word and then press CTRL-Space. Also, if may be that on your system CTRL-Space is overridden by some other application. Unfortunately, it's not yet configurable, see phab:T210679. Smalyshev (WMF) (talk) 04:21, 6 December 2018 (UTC)
@Smalyshev (WMF): same thing w/o space. Chromium seems to allow app to consume this shortcut first, see here --Ghuron (talk) 04:28, 6 December 2018 (UTC)
@Ghuron: I've added Alt-Enter and Ctrl-Alt-Space to the list of autocomplete shortcuts, please see if it works better for you Smalyshev (WMF) (talk) 01:05, 11 December 2018 (UTC)
@Smalyshev (WMF): Both works for chromeos --Ghuron (talk) 04:40, 11 December 2018 (UTC)

Error: "414 Request-URI Too Large"

I'm trying to run a query using the graphical interface that was working fine the other day. When I try to run it, I get back an "Unknown error" with the following HTML source displayed:

<html>
<head><title>414 Request-URI Too Large</title></head>
<body bgcolor="white">
<center><h1>414 Request-URI Too Large</h1></center>
<hr><center>nginx/1.13.6</center>
</body>
</html>

I am fully aware that large queries should use a POST request with the query in the body rather than the URL, but the GUI used to handle this transparently, and needs to if it is to be used for large queries. Like I said the query I'm attempting to run was working earlier. --NoInkling (talk) 02:17, 9 January 2019 (UTC)

I cut as much as I could out of the query, now I'm getting <h1>Bad Message 431</h1><pre>reason: Request Header Fields Too Large</pre> in both the GUI and a manual request. There's something weird going on. --NoInkling (talk) 03:19, 9 January 2019 (UTC)
Yes, it probably needs to be POST if it's long. If the GUI doesn't handle it please submit Phabricator issue with the query (or at least post the query somewhere so somebody else could submit it). Smalyshev (WMF) (talk) 05:53, 12 January 2019 (UTC)
I opened an issue on Phabricator. --NoInkling (talk) 05:54, 20 February 2019 (UTC)

Simple API SPARQL query fails - cache problem?

Hello. I want to find items based on the value of P225, for which I use a SPARQL API query, but I am plagued by what seem to be caching problems. If I execute the following URL (with Windows and Firefox): "https://query.wikidata.org/bigdata/namespace/wdq/sparql?query=select+%3Fx+%3FxLabel+where+%7B%3Fx+wdt%3AP225+%22Psalliota%22.+SERVICE+wikibase%3Alabel+%7B+bd%3AserviceParam+wikibase%3Alanguage+%22en%22.+%7D%7D", that is, a search for P225 = "Psalliota", I get back the following file, indicating that nothing has been found:

<?xml version='1.0' encoding='UTF-8'?>
<sparql xmlns='http://www.w3.org/2005/sparql-results#'>
	<head>
		<variable name='x'/>
		<variable name='xLabel'/>
	</head>
	<results>
	</results>
</sparql>

But the item is there, it is Q61885451. If I execute the equivalent query with a similar old item "Agaricus": "https://query.wikidata.org/bigdata/namespace/wdq/sparql?query=select+%3Fx+%3FxLabel+where+%7B%3Fx+wdt%3AP225+%22Agaricus%22.+SERVICE+wikibase%3Alabel+%7B+bd%3AserviceParam+wikibase%3Alanguage+%22en%22.+%7D%7D", it works fine giving the following:

<?xml version='1.0' encoding='UTF-8'?>
<sparql xmlns='http://www.w3.org/2005/sparql-results#'>
	<head>
		<variable name='x'/>
		<variable name='xLabel'/>
	</head>
	<results>
		<result>
			<binding name='x'>
				<uri>http://www.wikidata.org/entity/Q390456</uri>
			</binding>
			<binding name='xLabel'>
	 			<literal xml:lang='en'>Agaricus</literal>
			</binding>
		</result>
	</results>
</sparql>

In other similar cases the query typically starts working after a few minutes, but I made "Psalliota" hours ago and I still cannot query for it.

Please could someone tell me how I can investigate this problem? Strobilomyces (talk) 17:44, 26 February 2019 (UTC)

Look at the little icon in the lower right of the WDQS screen just below the edit box - it looks like two curved arrows making a circle? Right now when I go there it's indicating red - suggested a long lag time. And hovering over it shows that WDQS is about 5 hours out of date. I have no idea why, but it's been way behind all day today. I just checked Phabricator and don't see anything on this. Anybody paying attention here??? ArthurPSmith (talk) 19:16, 26 February 2019 (UTC)
@User:ArthurPSmith: Thanks a lot for this answer, which makes my problem much clearer. There seem to be various servers which were updated at different times - at present either one hour ago or 3 hours ago. Strobilomyces (talk) 09:48, 27 February 2019 (UTC)
I would like to ask some more questions. Is the server update process of WDQS documented somewhere? Is there some other way of finding an item based on the value of a property, apart from WDQS? Could I pre-create my own items in advance and then instead of creating a new item, update the properties of a pre-allocated item to get around the problem?Strobilomyces (talk) 17:21, 27 February 2019 (UTC)
@ArthurPSmith: yes, we know about the lag (already fixed) but we can't usually fix it instantly. In most cases it is caused by traffic spike. Usually it is back to normal within an hour, sometimes (like today) it's not. It's ok to ping me or anybody from Search Platform team on IRC but usually we'd already know (unless we are offline for some reason) about the long lags. Smalyshev (WMF) (talk) 07:45, 28 February 2019 (UTC)
@Strobilomyces: WDQS is documented extensively on mediawiki and wikitech but I am not sure which exactly information you're looking for. You certainly also can use Wikibase API to look up the data about specific items. Smalyshev (WMF) (talk) 07:45, 28 February 2019 (UTC)
Thanks for your answer. Well, I was looking for information about how to influence the update system of the query system, but I suppose that just means contacting someone through this page. When you say "specific items", I think you mean "items where you already know the Q number". But one reason that I need to use the query service is that I want to search for an item which I have already created (using "QuickStatements"), preferably using a property. But I think none of the functions of the Wikibase API allow to do this. Strobilomyces (talk) 19:11, 28 February 2019 (UTC)
@Strobilomyces: on that last point of yours, AIUI the lag is "all changes" not "new items being added", so edits which update an existing item will be caught in the lag as well - whether or not they're newly created shouldn't significantly affect things. Andrew Gray (talk) 17:07, 28 February 2019 (UTC)
Well, my first problem shows up when I create items (which I do using QuickStatements), because in that case I don't know their Q numbers. But I think that it is true that I cannot get very much further without querying those items again, so you are right, it does not make much difference. Strobilomyces (talk) 19:11, 28 February 2019 (UTC)

Feature Request?

It's only me or does anybody else miss an option to save one's own painfully developed queries? Without copying the URL or the raw query code at some local or wiki place all work usually is lost. Or do I overlook something? --Elya (talk) 20:35, 3 May 2019 (UTC)

You could just bookmark it (or use short URL button and copy it). WDQS servers do not have any permanent non-SPARQL storage so they can't really save queries, but since it's part of the URL, they can be saved anywhere like in bookmarks. Smalyshev (WMF) (talk) 07:21, 8 May 2019 (UTC)

Query timeout limit for important query reached

See here. --jobu0101 (talk) 22:00, 10 August 2019 (UTC)


The population for Orange Free State is incorrect

I am not sure if this is the correct place to report an error in Wikidata, thus if not, please be so kind as to refer me to the correct forum. I would have tried to correct this if I knew how to do it, and if I was expert in Russian, which I'm not. I thus request that the editors of Wikidata refer this issue to someone that is better qualified and more capable of fixing the problem.

Thank you for your attention.

Here is my error report

I have executed one of the sample queries in the SPARQL tutorial (The example I am referring to)

I noticed that the resulting population record for "Orange Free State" is incorrect:

wd:Q218023 	Orange Free State 	207503189

I am not sure what the correct value is, but the Wikipedia page lists a value of 100,000 in 1875, the value above (207503189) is linked to a reference in the Russian Wikipedia, for the year 1890. It is incorrect. The Orange Free State was incorporated as a province, simply named the Free State, into what eventually became South Africa. The population of the Free State in modern South Africa is estimated as 2,866,678 ([of South African provinces by population]. It is simply impossible that more than 200 million people could have migrated to and then out of that area in the course of 143 years.

Use of tinyurl

Kind of silly that tinyurl is the URL shortener when that domain is blocked from the English Wikipedia, so we effectively can't even share the links on-wiki. Would it be possible to use a different domain instead? czar 12:02, 18 June 2018 (UTC)

Save queries in account

I'd like the ability to save queries in my account both publicly and private. Also it should be possible to name, describe and tag them. So people will be able to find more queries in the Examples section. --Loominade (talk) 07:47, 22 August 2018 (UTC)

searching highest mountains is mixing up units (meters vs. feet)

searching highest mountains is mixing up meters and feet values (many US mountains are above 8000 ft, and therefore seem to be the highest on planet) searching the highest mountains does not mean searching the highest number (if I measure my house in millimeters, it is larger than any mountain on earth). (even more useless by the fact, that outside of USA nobody is using feet, but only meters)

tinyurl.com ydczydek

?subj wdt:P2044 ?elev filter(?elev > 8500) .

I derived this from help examples. If there is a better query, then examples should be improved. If not, then please extend the search engine to handle this. This applies to anything, that has different units (area, height, elevation, time/age, date, price/money(at least roughly possible, as via e.g. google convert), etc).

--Aleks-ger (talk) 13:17, 2 November 2018 (UTC)

input box for "But not Include" in Query Helper

I think if we add an option in Query Helper GUI to exclude the results, that can be helpful. something to add this code:

FILTER NOT EXISTS { ?item wdt:P31 wd:Q19832712 . }

--Hariva (talk) 19:32, 9 November 2018 (UTC)

Example query cannot run

All museums (including subclass of museum) in Washington, D.C. with coordinates It cannot return the result because of the timeout problem.

Not all entries are showing up

When I search for all countries in WikiData using WikiData query service, certain countries like Sweden and Denmark do now show up. They used to do that, and they seem to be annotated correctly.

SELECT ?item ?itemLabel WHERE {
  ?item wdt:P31 wd:Q6256.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
This is because preferred type for Sweden (Q34) is sovereign state (Q3624078). If you want to see all types, use p:P31/ps:P31 instead of wdt:P32. Smalyshev (WMF) (talk) 07:50, 21 December 2018 (UTC)

Query Service: Jumping Frames

Hi, query service is a very great tool. But could you please fix the bug with the jumping windows. Its extremely disturbing when they are resizing to zero and back to normal after every little change. Ogmios (talk) 15:54, 16 February 2019 (UTC)

Abfragehelfer ist leer

Das Fenster Abfragehelfer bleibt komplett leer.91.221.58.20 14:56, 18 February 2019 (UTC)

Is there a way to add UTF-8 BOM to exported tsv file?

It would help to work with those files in various processing tools --Ghuron (talk) 07:50, 25 February 2019 (UTC)

Run selected query

MS SQL Server Query Analyser had very useful feature - when you click "Run query" button, it tries to run only query from selected text, not everything. This way you can have several queries in 1 window, which is very useful if you do data exploration. If nothing is selected, "Run query" works exactly like today --Ghuron (talk) 12:17, 11 March 2019 (UTC)

Weird Pxxx units have been showing up lately

For a query such as

CONSTRUCT {?s ?p ?o.} WHERE { VALUES ?s {wdv:1b133cdd8e6d4ab769bf119d89ebe63e} ?s ?p ?o.}

there are both entity-based units (Q7727) and weird property-based units (P7727) being returned. If one attempts to edit the original value (see P2047 for Q1004531), there's no indication where the property-based unit is coming from. Graph error? Something else? This is not an isolated case.

Both Examples Tried Failed

Interested in this I tried two examples from the examples folder. First gave a Javascript error. Second gave some results but also a timeout reached error. Not great examples if they don't work (or the service has a lot of issues); not sure which but its rather offputting!

R code fix

R code fails it needs argument for agent wrong code is


SPARQL(endpoint,query)

correct code is

SPARQL(endpoint,query,curl_args=list(useragent=R.version.string))


see https://stackoverflow.com/questions/58560369/r-sparql-wikidata-opening-and-ending-tag-mismatch

who is in charge of the code tab and the suggestion?

The graph graph

The "Graph" results display should probably be called "network", which is the more commons parlance for an edges-and-nodes visualisation. This is especially the case as one of the other display options is "Graph builder".

Additionally, there are two features for the network display that may be easy to implement, but very valuable:

  • When two nodes point to each other, make single two-headed arrow rather than two single-headed arrows (example)
  • Allow edges to be coloured by the type of property relationship that they represent, just like nodes can be (example)

T.Shafee(Evo﹠Evo)talk 06:42, 18 November 2019 (UTC)

Default Maps representation vs http://graves.wiki/

The default maps representation on the query service struggles when multiple results are spatially close or fully overlap (example query). Implementing an interface more like http://graves.wiki/ (GitHub source by User:Yarl) would massively improve usability! T.Shafee(Evo﹠Evo)talk 05:54, 20 November 2019 (UTC)

@Evolution and evolvability: You can achieve a similar effect (query) with a custom result view option. --Lucas Werkmeister (WMDE) (talk) 12:08, 22 November 2019 (UTC)
@Lucas Werkmeister (WMDE): Thank you so much for that! A few questions about it:
  1. Is there a way to make that the default view for maps normally?
  2. Is there a way to make it compatible with the layers? The numbers currently don't change when the layers are turned on and off (clearer example).
  3. Also, it'd be amazing to have the remaining single points a little larger if possible.
T.Shafee(Evo﹠Evo)talk 02:46, 23 November 2019 (UTC)
@Evolution and evolvability: 2) I haven’t yet found a way to make the interaction of markercluster and layers work (it’s broken in several ways); 1) not before 2 is fixed; 3) hm, where would that be necessary? It’s supposed to mirror the size of the marker dots without markercluster enabled. --Lucas Werkmeister (WMDE) (talk) 16:26, 25 November 2019 (UTC)
Template:Lucas Werkmeister (WMDE) Thanks for the info. Hopefully the layers compatibility proves possible eventually. I found the point size made the singletons easy to miss (especially in some colours). It could be useful to have the singletons double size whenever there is at least one cluster shown, but going back to normal size once zoomed enough that no clusters are show. I really love the polygon outline drawn for each cluster upon mouseover though! T.Shafee(Evo﹠Evo)talk 01:03, 26 November 2019 (UTC)

Property path with repetition count

I don't seem to be able to use the "elt{n,m}" form of property paths. This query

ASK WHERE { wd:Q48940439 wdt:P31/wdt:P279* wd:Q17537576 . }

Try it!

works fine but the following:

ASK WHERE { wd:Q48940439 wdt:P31/wdt:P279{,3} wd:Q17537576 . }

Try it!

produces the error Query is malformed: Encountered " "{" "{ "" at line 1, column 42.. Is this supposed to be supported? Cheers, Bovlb (talk) 16:39, 23 November 2019 (UTC)

I cannot find anything about this in SPARQL. --Matěj Suchánek (talk) 12:33, 24 November 2019 (UTC)
Hmm. Interesting. It was in the working draft, but somehow didn't make it into the following recommendation. Curiously, that syntax is supported by Apache Jena. Looking closely at their documentation, it is described as an "ARQ extension". I guess that answers my question. Thanks! Bovlb (talk) 16:20, 24 November 2019 (UTC)

sdcquery.wmflabs.org

https://sdcquery.wmflabs.org/ has help page with "Give Feedback" linking to here. Is this the right place to be asking about that service? --Jarekt (talk) 02:54, 16 December 2019 (UTC)

In the query https://w.wiki/EX3 , the osmlink for wikidata item is not being reported, though it is linked for the mandal qid wd:Q7918199 (see the sophox query (http://sophox.org) below)

#List all OSM objects with a place tag
SELECT * WHERE {
  # Limit to subjects that have an OSM type ('n', 'r', 'w').
  # Replace ?osmType with a string 'r' to show only relations.
  ?osmId osmm:type ?osmType .

  # Limit to subjects that have an OSM tag `place`
  # Replace ?place with a string 'city' to filter the tag value to `place=city`
  ?osmId osmt:name 'Veerapunayunipalle'  .
  ?osmId osmt:wikidata ?qid

} LIMIT 50

Try it!

--Arjunaraoc (talk) 09:51, 27 December 2019 (UTC)

Link for the issue on openstreetmap wiki https://wiki.openstreetmap.org/wiki/Talk:Sophox_Editor#osmID_with_wikidata_link_not_being_reported_in_query --Arjunaraoc (talk) 10:08, 27 December 2019 (UTC)
@Arjunaraoc: Veerapunayunipalle mandal (Q7918199) is linked from relation/10219506, but has no name:te tag, if you want both the name and the openstreetmap relation to be individually optional, you should do it with surrounding both individually with an optional clause:
prefix osmt: <https://wiki.openstreetmap.org/wiki/Key:>

select ?mandal ?mandalLabel ?districtLabel ?page_titleTE ?tewikilink ?osmlink where {
  hint:Query hint:optimizer "None".
  ?mandal wdt:P131* wd:Q1159;
          wdt:P131 ?district;
          wdt:P31/wdt:P279* wd:Q13005188.
  ?tewikilink schema:about ?mandal;
              schema:isPartOf <https://te.wikipedia.org/>;
              schema:name ?page_titleTE.
  service wikibase:label {
    bd:serviceParam wikibase:language "te".
  }
  service <https://sophox.org/sparql> {
    optional {
      ?osmlink osmt:wikidata ?mandal.
    }
    optional {
      ?osmlink osmt:name:te ?osmnamete.
    }
  }
}
order by (?mandalLabel)
Try it! --CamelCaseNick (talk) 00:39, 17 January 2020 (UTC)
Thanks CamelCaseNick, Looks like I missed adding name:te here. --Arjunaraoc (talk) 04:00, 17 January 2020 (UTC)

Getting french cities from their geoname ID doesn't work. Other countries, yes.

Getting french cities from their geoname ID doesn't work. Other countries, seem yes.

Try it

Also, some GeoNamesIDs on wikidata's city pages simply don't correspond to the ones given by geonames.org. For examples: Paris (FR), Venice (IT) Seems strange but maybe there has been an update.

Tooltip for property used as object is incorrect

The tooltip for properties referenced using the 'wd' prefix is wrong.

Steps:

  1. Open [6]
  2. Hover over 'wd:P276'.

Expected result: name and description of location (P276) in the description.

Actual result: tooltip displays an item that happens to start with "P276".

Screenshot:

Screenshot Cdo256 (talk) 14:37, 22 September 2020 (UTC)

get rottenId from imdbid is wrong!

SELECT ?rottenId

       WHERE
       {
           ?item wdt:P345 "tt7294150".
           ?item wdt:P1258 ?rottenId
       }

return m/the_eight_hundred_heroes bug the right one is:m/the_eight_hundred

Example for longest river is incorrect

Just to feedback that the example of longest river does not take into account of Unit of length, some length are in Km, some are in meter. see the code comment

  1. Longest rivers

SELECT ?item ?itemLabel ?length ?pic ?location WHERE {

 ?item wdt:P31/wdt:P279* wd:Q4022 .
 ?item wdt:P2043 ?length .
 ?item wdt:P18 ?pic .  #IF this is taken away, it will return the result of Q95676337	with length 20202.373	but in meter
 ?item wdt:P625 ?location
 SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }

} ORDER BY DESC(?length) ?itemLabel LIMIT 50

Choose language for map view in wikidata query

Hello,

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

Thanks!

ps. I preeviously mentioned this in request a query

Please add dark theme

Save our eyes. And batteries. https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme Vitaly Zdanevich (talk) 01:45, 22 February 2021 (UTC)

LIMIT+OFFSET apparently not working as intended

I'm trying to get a list of all en.wiki articles using GND ID (P227), which is ~350,000. I'm unable to obtain the last 50,000 via this query due to timeout, despite using LIMIT 50000 OFFSET 300000. I'm trying to perform this same search for ISNI (P213), Library of Congress authority ID (P244), P7859 (P7859), VIAF ID (P214), but repeatedly get timed out beyond ~300,000.

SELECT DISTINCT ?item ?name WHERE {
  ?item wdt:P227 ?blah .
  ?article schema:about ?item; schema:inLanguage ?lang; schema:isPartOf <https://en.wikipedia.org/>; schema:name ?name .
  FILTER (!CONTAINS(?name, 'Category:')).
}
LIMIT 50000 OFFSET 300000

Try it!

  ~ Tom.Reding (talkdgaf)  14:21, 17 February 2021 (UTC)

Unerklärliche (subjektiv) Abfrageergebnisse

Hallo Ich suche nach

 ?gde wdt:P131 wd:Q11911. 
 ?gde wdt:P31 wd:Q70208.

Und zwar geht es mir um die Stadt Thun (Q68978) - sowohl liegt Thun im Kanton Bern als es auch eine politische Gemeinde ist -, welche Standort eines von mir gesuchten Objektes ist. Das Ergebnis ist aber immer Null. Die einzelnen Abfragen dagegen liefern immer einen Treffer. Warum funktioniert das bei der kombinierlten Abfrage nicht?

Das ist mir (noch) unerklärlich. Wenn mir das jemand erklären könnte, wäre mir wohl sehr geholfen Besten Dank Andreas

  • Try P131* to search for things that are part of an administrative unit that is part of the Canton of Bern. Thun is not encoded as part of the Canton of Bern but part of the district of Thun.
SELECT ?gde ?gdeLabel WHERE {
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  ?gde wdt:P131* wd:Q11911. 
 ?gde wdt:P31 wd:Q70208.
  ?gde wdt:P131* wd:Q678914.

Try it!}

Valeriummaximum (talk) 01:25, 30 August 2021 (UTC)

Request for checking the structure of the province (Q34876)

As we can see from this link: [Province Of Canada], the province of canada is a subclass of Province(Q34876). However, when we asked Wikidata endpoint if Province of canada is a subclass of province the result is false. I need some clarifications.I think we need ti fix that.

ASK WHERE { wd:Q11828004 wdt:P279  wd:Q34876}

Try it!

@Bilalox01: Wrong wiki for this kind of question, but this is a Rank issue. Only the best rank are showable using the simple statements (wdt:). Don’t know why there is several ranks involved. TomT0m (talk) 16:23, 3 April 2021 (UTC)
@TomT0m: thank you so much for your answer.

Matter for the Listeria Code generated for SPARQL queries

Let me consider this query (https://w.wiki/3ACr). In this query, there are two variables. The output will be a table including people and their countries. However, when generating the Listeria Code for this query in order to embed the output table in a Wikipedia page, I discovered that the columns are label:Article,description,p131:Place,P580,P582,p625,P18 regardless the output of the query. However, the columns should be ?person, ?country. I propose to the developers of the Wikidata Query Service Code Generator to substitute the columns in the Listeria Code for the queries by what comes after the first SELECT module. When what comes after SELECT module is an asterisk (*), the main WHERE clause can be analyzed to find the variables for the query. --Csisc (talk) 20:10, 5 April 2021 (UTC)

Export WDQS result as markdown?

Hello,

I often use markdown for documentation (e.g. in GitHub Flavored Markdown syntax) and sometimes I have to write some quick-and-dirty code to get the markdown table.

I thought about writing a web app, but it might be simpler just to add a Markdown rendering at the "Downloads" session of WDQS. Would that be feasible/desired?

Best, TiagoLubiana (talk) 18:53, 17 June 2021 (UTC)

wikidata query: "Unable to display result"

when I run sparqls in wikidata query with Chrome (ver 91.0.4472.164, 64 bit), it dispalys "Unable to display result: Table". This happens on both MacOs bigsur and Win10, but Safari and MS Edge work fine. How to solve it?

error with spain query

when you query for spain, for example to get its name, it shows the name "galicia".

SELECT ?country ?countryLabel WHERE {

 ?country wdt:P31 wd:Q6256;
   wdt:P17 wd:Q29.
 SERVICE wikibase:label { bd:serviceParam wikibase:language "es". }
 OPTIONAL { ?country wdt:P17 ?country. }

}

When I run this query:

#defaultView:Map
SELECT * WHERE {
  {
    ?poi osmt:historic "ruins".
    ?poi osmt:name ?name.
    ?poi osmm:loc ?coordinates.
  } 
}

Try it!

I get lots of results but, e.g., this one doesn't show (which does have a historic:ruins key value pair)

https://www.openstreetmap.org/node/1638478716

Similarly, if I run this query

#defaultView:Map
SELECT * WHERE {
  {
    ?poi osmt:historic "aircraft".
    ?poi osmt:name ?name.
    ?poi osmm:loc ?coordinates.
  } 
}

Try it!

It shows neither of these two "gate guardians" (both have historic:aircraft key value pairs)

https://www.openstreetmap.org/node/4904841880

https://www.openstreetmap.org/node/4143702889

Am I doing something wrong?

Many thanks

Rob

SPARQL - Not getting Gender for all humans, eventhough the P21 statement is made

Hi, can someone please help me to understand, why I am not getting the gender for all humans in this list?

Example: Q108147928 -> Q61268672 (Albert Schweizer) -> P21 = Q6581097 - I receive an empty result in the query.


Thanks

Cheers Pandabear


#in Karben benanntes Objekt nach...
SELECT ?ist_eineLabel ?objekt ?objektLabel 
      ?cityLabel ?personLabel ?artLabel
      ?geschlechtLabel ?personDescription ?religionLabel 
      (group_concat(DISTINCT ?berufL;separator=", ") as ?berufe) 
WHERE
{
    #?street wdt:P31 wd:Q79007 .
    ?objekt wdt:P31 ?ist_eine .
    ?objekt wdt:P131 wd:Q570057 . #Verwaltungseinheit Karben
    ?objekt wdt:P131 ?city .
    ?objekt wdt:P138 ?person .
    ?person wdt:P31 ?art .
    FILTER ( ?art not in ( wd:Q16521, wd:Q55983715, wd:Q754660, wd:Q978 ) )  . #not Taxon, Lebewesen Trivaler Name, Falconinae, Mem
    
    optional {
      ?person wdt:P21 ?geschlecht .
      ?person wdt:P140 ?religion .
      
      ?person wdt:P106 ?beruf .
      ?beruf rdfs:label ?berufL .
      FILTER((LANG(?berufL)) = "de") .
      
    }
    SERVICE wikibase:label { bd:serviceParam wikibase:language "de" }
}
GROUP BY ?ist_eineLabel ?objekt ?objektLabel ?cityLabel ?personLabel ?artLabel ?geschlechtLabel ?personDescription ?religionLabel 
ORDER BY ?city ?objektLabel

Problem with Commons file names with white space

There seems to be a problem with sparql queries of Goslar (Q3896) when the file name contains white space. It seems the query service adds a "+" to the filename and then can't retrieve the GeoJson file from Wiki Commons. But when you go to the wiki page (for example Newfoundland and Labrador (Q2003)), you can then follow it through to the GeoJson file without issue.

SELECT ?thingLabel ?shape WHERE {
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  ?thing wdt:P3896 ?shape.

Try it!}

Any suggestions about how to fix this issue or where to direct it to? I didn't have this issue two weeks ago. Valeriummaximum (talk) 23:33, 25 August 2021 (UTC)

random results on each query. how?

i add small data (viaf, place of birth, date of birth, etc..). i use mobile device. so i prefer not more than 10 results at a time. however, when i run again same query it shows same results. i mean the result of query1, query2, etc.. are all same. -28au21 (talk) 17:39, 28 August 2021 (UTC)

Very stale results

I ran a bot to change some qualifiers on taxon names from 'instance of' to 'has role'. The bot used the following query as a pywikibot generator to identify the items that required the change.

SELECT ?item
WHERE
{
     ?item  p:P225 ?name.
     ?name  pq:P31 wd:Q14594740.
}

Try it!

The query is currently still returning 27 rows, even though the bot changed the qualifiers days ago. I'm wondering how this relates to the Graphana dashboard. William Avery (talk) 10:48, 15 November 2021 (UTC)

Raised issue at https://phabricator.wikimedia.org/T295941 William Avery (talk) 22:57, 17 November 2021 (UTC)

Have "Format Query" keep comments

I love to use "Format Query" to tidy and condense my queries, but for more complex queries I like to comment along to help keep track. The "Format Queries" button removes these comments, which is very frustrating. An option to let "Format Query" keep the comments would be very useful.

Wikidata Query Service erroneously formats/fills partial dates into full dates

When querying some places with population having partial dates of point in time, the results display an erroneous full date instead of the exact partial date. For example, Ruinen (Q1007156) has a population of 1,624 with point in time 1830 (census). But when running the query, it displays 1 January 1830 instead of just 1830. How can this be fixed?:

SELECT ?place ?placeLabel ?populationLabel ?populationDate WHERE {
  ?place wdt:P131 wd:Q835108;
    p:P1082 ?place_statement.
  ?place_statement ps:P1082 ?population;
    pq:P585 ?populationDate.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY (?place) (?populationDate)

Try it!

Sanglahi86 (talk) 16:04, 23 February 2022 (UTC)

I'd appreciate a possibility to be able to share a SPARQL query code with a permalink to the code instead of having to share the whole code itself - similar to how social network applications manage to share content. --Katpatuka (talk) 12:59, 7 May 2022 (UTC)

Derogatory language

"Nigger" comes up in list of dog names when q144 is queried.

SELECT ?item ?itemLabel WHERE {

 ?item wdt:P31 wd:Q144. # Must be of a cat
 SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } # Helps get the label in your language, if not, then en language

}


145.94.152.78 09:19, 16 May 2022 (UTC)

EOF occurred in violation of protocol (_ssl.c:1131)

Hi Madam or Sir,


I am trying to query the Wikidata using SPARQLWrapper. But I obtain the error message saying that "ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:1131)". I am wondering whether my IP is banned? Or some other reasons? Could you please help me?


Best,

Nancy Yunshi1994 (talk) 09:07, 21 May 2022 (UTC)

Bug? Query helper adds round brackets - breaking "inverse property path" optimization

Hi, i've noticed a strange behaviour of the Query Helper. I'm using query with "inverse property path" optimization to avoid timeouts - the following query for church buildings in the autonomous region of Aosta Valley works fine (returning 36 results in 661 ms):

#defaultView:ImageGrid
SELECT DISTINCT ?item ?itemLabel ?lieuLabel ?image WHERE {
  ?item wdt:P131* wd:Q1222.
  wd:Q16970 ^wdt:P279*/^wdt:P31 ?item.
  ?item wdt:P18 ?image.
  ?lieu ^wdt:P131 ?item.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ORDER BY (?lieuLabel)

Try it!

If i use the query helper to select a different region, it doesn't just change the wdt:P131* parameter but adds some round brackets as follows (third and fourth line):

#defaultView:ImageGrid
SELECT DISTINCT ?item ?itemLabel ?lieuLabel ?image WHERE {
  ?item (wdt:P131*) wd:Q1222.
  wd:Q16970 (^(wdt:P279*)/^wdt:P31) ?item.
  ?item wdt:P18 ?image.
  ?lieu ^wdt:P131 ?item.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ORDER BY (?lieuLabel)

Try it!

This query times out :-( Fl.schmitt (talk) 14:26, 19 June 2022 (UTC)

Bug? Unknown error: java.lang.ClassCastException on one entity

I run this query, which is fine:

SELECT ?place ?location
WHERE {
wd:Q8818 wdt:P625 ?villageLoc . 

SERVICE wikibase:around { 
    ?place wdt:P625 ?location . 
    bd:serviceParam wikibase:center ?villageLoc . 
    bd:serviceParam wikibase:radius "1" . 
    bd:serviceParam wikibase:distance ?dist.
} 

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

Try it!

But running the same query on a dfifferent entity returns an exception:

SELECT ?place ?location
WHERE {
wd:Q12711767 wdt:P625 ?villageLoc . 

SERVICE wikibase:around { 
    ?place wdt:P625 ?location . 
    bd:serviceParam wikibase:center ?villageLoc . 
    bd:serviceParam wikibase:radius "1" . 
    bd:serviceParam wikibase:distance ?dist.
} 

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

Try it!

I am not sure how to fix this, maybe it is something in that specfific item or a bug? 2.136.33.201 09:38, 27 July 2022 (UTC)

Items and coordinates

SELECT DISTINCT ?item ?itemLabel ?itemDescription ?geographLink
WHERE {
   ?item wdt:P31/wdt:P279* wd:Q44494;            
         wdt:P131* wd:Q5922; 
         p:P625 ?coordinate.
  ?coordinate psv:P625 ?coordinate_node.
  ?coordinate_node wikibase:geoLatitude ?lat.
  ?coordinate_node wikibase:geoLongitude ?lon.
BIND(URI(CONCAT("http://geo.hlipp.de/browse.php?ll=",STR(?lat),",",STR(?lon))) AS ?geographLink)
SERVICE wikibase:label { bd:serviceParam wikibase:language "de". }
}

Try it!

Please help me to make this more effective: I want to query all items within a given region. Then I would like to use the geolocation to form the external link. ChristianSW (talk) 10:40, 24 September 2022 (UTC)

Bug on sample?

I think the results for this query seem a bit fishy. The sample does not seem to respect the grouping, generating the same titles across different years.


SELECT DISTINCT ?year (COUNT(?game) AS ?total) (SAMPLE(?gameLabel) AS ?randomGame)
WHERE {
  ?game wdt:P31/wdt:P279* wd:Q7889 .
  ?game wdt:P577 ?date .
  ?game rdfs:label ?gameLabel .
  BIND(YEAR(?date) AS ?year)
  FILTER(lang(?gameLabel)="en" && ?year > 2010)
}
GROUP BY ?year
ORDER BY ?year

Try it! Aidhog (talk) 04:04, 12 October 2022 (UTC)