0

I am trying to run a simple query, looking up an item by its English label. For some reason, some entries are not showing. Most are fine, but some aren't. I can't pinpoint why.

An example: oyster bed. Here is the entry: https://www.wikidata.org/wiki/Q65953972

This is the query:

SELECT distinct ?item ?itemLabel ?itemDescription WHERE {  
        ?item ?label 'oyster bed'@en.  
        ?article schema:about ?item .
        ?article schema:inLanguage 'en' .
        SERVICE wikibase:label { bd:serviceParam wikibase:language 'en'. }
  }

and I get nothing.

The same query with oyster yields an expected result.

What am I doing wrong?

Vadim Berman
  • 1,932
  • 1
  • 20
  • 39
  • 2
    you're ignoring the case that there is no article about the entity: `select * { ?item rdfs:label "oyster bed"@en . optional {?article schema:about ?item . ?article schema:inLanguage 'en' . } SERVICE wikibase:label { bd:serviceParam wikibase:language 'en'. } }` – UninformedUser Mar 20 '20 at 07:07
  • So simple! Thank you, @UninformedUser. Indeed it worked! If you write it as a reply, I will upvote it. If not, I'll just post my own. – Vadim Berman Mar 21 '20 at 03:06

1 Answers1

0

Hat tip of @UninformedUser helped.

As a SPARQL newbie, I did not realise the ?article was an implicit JOIN.

SELECT distinct ?item ?itemLabel ?itemDescription WHERE {  
        ?item ?label 'oyster bed'@en.  
        OPTIONAL { ?article schema:about ?item .
        ?article schema:inLanguage 'en' . }
        SERVICE wikibase:label { bd:serviceParam wikibase:language 'en'. }
  }

is to be used if the article is required, but if there is no real need, the query can be simplified to:

SELECT distinct ?item ?itemLabel ?itemDescription WHERE {  
        ?item ?label 'oyster bed'@en.  
        SERVICE wikibase:label { bd:serviceParam wikibase:language 'en'. }
  }
Vadim Berman
  • 1,932
  • 1
  • 20
  • 39