2

Query below gives me all programming languages entities, with their statements.

Problem is that I don't need identifiers now, but these IDs might become necessary. I was just gonna model database return with toJSON, but this became hard since I can't easily filter them at my queries

I think all of them are instances of Q18614948 - Wikidata property for authority control

I don't want to remove them, I need a way to identify them, like add a flag or a different label if wd has this class

SPARQL query:

SELECT ?tipoLinguagem ?tipoLinguagemLabel
       ?subtipoLinguagem ?subtipoLinguagemLabel
       ?linguagem ?linguagemLabel
       ?wd ?wdLabel ?ps ?ps_Label ?wdpq ?wdpqLabel ?pq_ ?pq_Label
WHERE {

  ?tipoLinguagem wdt:P279 wd:Q629206 .
  ?subtipoLinguagem wdt:P279 ?tipoLinguagem .
  ?linguagem wdt:P31 ?subtipoLinguagem .

  ?linguagem ?p ?statement .
  ?statement ?ps ?ps_ .

  ?wd wikibase:claim ?p.
  ?wd wikibase:statementProperty ?ps.

  # NOT WORKINNG
  BIND(
    IF(?wd wdt:P31 wd:Q18614948)
    AS ?isIdentifier
  )

  OPTIONAL {
  ?statement ?pq ?pq_ .
  ?wdpq wikibase:qualifier ?pq .
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . } 

} ORDER BY ?linguagemLabel

i

Example of identifiers from js entity page:

enter image description here

  • 2
    Basically, you need something like BIND ( EXISTS { ?wd wdt:P31 wd:Q18614948 } AS ?isIdentifier ) } + some query optimization. However, properties might be identifiers not directly, i. e. you need BIND ( EXISTS { ?wd wdt:P31/wdt:P279* wd:Q18614948 } AS ?isIdentifier ) . Unfortunately, the latter is not working in Blazegraph. Use something like { BGP + FILTER EXISTS { ?wd wdt:P31/wdt:P279* wd:Q18614948 } BIND (true AS isIdentifier) } UNION { BGP + FILTER NOT EXISTS { ?wd wdt:P31/wdt:P279* wd:Q18614948 } BIND (false AS isIdentifier) } – Stanislav Kralin Jun 13 at 20:23
  • Thanks, Stanislav. I'm not using Blazegraph, your code works – tramada Jun 14 at 0:39
  • 1
    But Wikidata Query Service uses Blazegraph :-). – Stanislav Kralin Jun 14 at 10:51
  • Oh, I had no idea... Thanks again! – tramada Jun 14 at 17:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.