Talk:Wikidata Query Service

About this board

Previous discussion was archived at Talk:Wikidata Query Service/Archive 1 on 21 October 2022.

Query with ISBLANK gives unexpected (empty) result on WDQS

2
Hannah Bast (talkcontribs)

The following query gives zero results on WDQS, but QLever and Virtuoso both return hits, and correctly so I think:

PREFIX wdt: <http://www.wikidata.org/prop/direct/>
SELECT ?person ?date_of_birth WHERE {
  ?person wdt:P569 ?date_of_birth .
  FILTER ISBLANK(?date_of_birth)
}
LIMIT 10

Try it on WDQS: https://w.wiki/8Szp

Try it on QLever: https://qlever.cs.uni-freiburg.de/wikidata/2nzFYg

Try it on Virtuoso: https://wikidata.demo.openlinksw.com/sparql

PS: Not sure whether this is the right page for reporting this. If there is a better place, please let me know.

TomT0m (talkcontribs)

Wikidata changed its model a while ago and do not use blank nodes anymore to represent unknown value, for update performance reasons. "wikibase:isSomeValue" should be used instead of isblank, as a consequence. See this ticket for example task T244341

This query

SELECT ?person ?date_of_birth WHERE {
  ?person wdt:P569 ?date_of_birth .
  FILTER ( wikibase:isSomeValue( ?date_of_birth) )
}
LIMIT 10

Try it!

Reply to "Query with ISBLANK gives unexpected (empty) result on WDQS"
Xia (talkcontribs)
TomT0m (talkcontribs)

Hi, the filter is too expensive for the query service. Another approach that works is to specify all the dates, like in https://w.wiki/8hMC (example query). https://www.wikidata.org/wiki/Q12355561 helps to do this, I import this to WD and let konw know when it’s done and how to use it. Something like tomorrow.

TomT0m (talkcontribs)

I put a query on your page that works. It specifies manually all the correct dates so I started from 1900 (it’s unlikely to have accurate birth date before that anyway) to limit the length, but it works (and fast).

Xia (talkcontribs)

Thanks a lot!!

Reply to "Issue with query"

Data from query not returned even though it appears on page

3
Stuchalk (talkcontribs)

The following query returns data for the first three tributaries of Lake Geneva but not others, even though there is data available.

SELECT ?trib ?tribLabel ?length ?elevation ?area ?discharge

WHERE

{

  wd:Q6403 wdt:P200 ?trib .

  OPTIONAL {

  ?trib wdt:P2043 ?length .

  ?trib wdt:P2053 ?area .

  ?trib wdt:P2044 ?elevation .

  ?trib wdt:P2225 ?discharge .

   }

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

} ORDER BY DESC(?length) ?tribLabel

LIMIT 50


For tributary 'Eau Floride' (and others) the data exists on the wikidata entry page but is not showing up via this query. Why not? See the images below...

Length - Eau Froide
Length of the river 'Eau Froide' on Wikidata.
Watershed area - Eau Froide
Watershed area information for the river 'Eau Froide'.
Fnielsen (talkcontribs)

You need individual OPTIONALs

SELECT
  ?trib ?tribLabel ?length ?elevation ?area ?discharge
WHERE {
  wd:Q6403 wdt:P200 ?trib .
  OPTIONAL { ?trib wdt:P2043 ?length }
  OPTIONAL { ?trib wdt:P2053 ?area }
  OPTIONAL { ?trib wdt:P2044 ?elevation }
  OPTIONAL { ?trib wdt:P2225 ?discharge }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
}
ORDER BY DESC(?length) ?tribLabel
LIMIT 50

Try it!

- Fnielsen (talk) 16:49, 14 June 2023 (UTC)

Stuchalk (talkcontribs)

Ah, thanks for the clarification on this. I keep forgetting that optional has to be individual items.

Reply to "Data from query not returned even though it appears on page"

SELECT DISTINCT returns duplicates

4
Tena inmotion (talkcontribs)

The following query returns duplicate rows:

SELECT DISTINCT ?s ?l

WHERE {

        ?s wdt:P31 wd:Q19829914 ;

            rdfs:label ?l .

        FILTER(langMatches(lang(?l), "en"))

}

Fnielsen (talkcontribs)

I am not familiar with "langMatches". Is there an error? This seems to be working:

SELECT DISTINCT ?property ?label
WHERE {
  ?property wdt:P31 wd:Q19829914 ;
            rdfs:label ?label .
  FILTER(LANG(?label) = "en")
}
Tena inmotion (talkcontribs)

Thanks, that seems to solve it.

TomT0m (talkcontribs)

In the original query you select all languages variants.

LangMatches will match american english and UK-english variants, who are both present in Wikidata sometimes, with "en". And are technically different labels values as far as sparql is concerned because of the different language tag.

So you end-up having duplicates. To remove them you might remove the language tag with something like replacing "?l" with "(str(?l) as ?label)"

Reply to "SELECT DISTINCT returns duplicates"
There are no older topics
Return to "Wikidata Query Service" page.