query-e1a939a52e563694586da0a6060733a5

rq turtle/ttl

This query finds all usages of property P887 as a qualifier.

Important note: most SPARQL users don't need such level of complication!

If you want to get only concrete values with best rank, replace body with something like:

?item ?relation [rdf:type wikibase:BestRank; pq:P887 ?value]

Implementation note: it is not possible to distinguish between items where statement looks like:

P887: novalue with qualifier P887: novalue, AS both facts are stored in a form of:

(p:xxxx rdf:type wdno:P887)

SELECT

(CONCAT("-STATEMENT|", STRBEFORE(STR(?statement_qid), "-"), "$", STRAFTER(STR(?statement_qid), (SUBSTR(STR(?statement_qid), STRLEN(STRBEFORE(STR(?statement_qid), "-")) +1, 1)))) AS ?concatminus)

(CONCAT( REPLACE(STR(?item), ".Q", "Q"), "|P921|", REPLACE(STR(?value), ".Q", "Q") , "|S887|Q69652283" ) AS ?concatplus) WITH { SELECT ?item ?relitem ?statement ?qual_snacktype ?qual_value {

VALUES ?item {wd:Q13406268}

VALUES ?qual_dbvalue { wd:Q69652283 }

hint:Query hint:optimizer "None" .
{
  ?statement pq:P887 ?qual_dbvalue .
  ?item ?relation ?statement .
  ?relation rdf:type owl:ObjectProperty .
  ?relitem wikibase:claim ?relation .
} UNION {
  ?statement rdf:type wdno:P887 .
  ?item ?relation ?statement .
  ?relation rdf:type owl:ObjectProperty .
  ?relitem wikibase:claim ?relation .
  FILTER(?relation != p:P887)
} UNION {
  ?statement rdf:type wdno:P887 .
  ?item p:P887 ?statement .
  ?statement ps:P887 [] .
  BIND(wd:P887 AS ?relitem)
}

BIND(COALESCE(IF(wikibase:isSomeValue(?qual_dbvalue), "", ?qual_dbvalue), "") AS ?qual_value)
BIND(COALESCE(IF(wikibase:isSomeValue(?qual_dbvalue), "unknown", "concrete"), "novalue") AS ?qual_snacktype)

} } AS %statements { INCLUDE %statements

?statement wikibase:rank ?rank . ?relitem wikibase:statementProperty ?ps .

OPTIONAL { ?statement ?ps ?dbvalue }

BIND(COALESCE(IF(wikibase:isSomeValue(?dbvalue), "unknown", "concrete"), "novalue") AS ?snacktype) BIND(IF(wikibase:isSomeValue(?dbvalue), "", ?dbvalue) AS ?value)

SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" } BIND(REPLACE(STR(?statement), ".*Q", "Q") AS ?statement_qid) }

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdno: <http://www.wikidata.org/prop/novalue/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX bd: <http://www.bigdata.com/rdf#>
# This query finds all usages of property P887 as a qualifier.
#
# Important note: most SPARQL users don't need such level of complication!
# If you want to get only concrete values with best rank, replace body with something like:
# ?item ?relation [rdf:type wikibase:BestRank; pq:P887 ?value]
#
# Implementation note: it is not possible to distinguish between items where statement looks like:
# P887: novalue with qualifier P887: novalue, AS both facts are stored in a form of:
# (p:xxxx rdf:type wdno:P887)

SELECT 

# (CONCAT("-STATEMENT|", STRBEFORE(STR(?statement_qid), "-"), "$", STRAFTER(STR(?statement_qid), (SUBSTR(STR(?statement_qid), STRLEN(STRBEFORE(STR(?statement_qid), "-")) +1, 1)))) AS ?concatminus)

(CONCAT(
  REPLACE(STR(?item), ".*Q", "Q"), "|P921|", REPLACE(STR(?value), ".*Q", "Q") , "|S887|Q69652283"
) AS ?concatplus)
{
   {
  SELECT ?item ?relitem ?statement ?qual_snacktype ?qual_value {
#     VALUES ?item {wd:Q13406268}
#     VALUES ?qual_dbvalue { wd:Q69652283 }

    {
      ?statement pq:P887 ?qual_dbvalue .
      ?item ?relation ?statement .
      ?relation rdf:type owl:ObjectProperty .
      ?relitem wikibase:claim ?relation .
    } UNION {
      ?statement rdf:type wdno:P887 .
      ?item ?relation ?statement .
      ?relation rdf:type owl:ObjectProperty .
      ?relitem wikibase:claim ?relation .
      FILTER(?relation != p:P887)
    } UNION {
      ?statement rdf:type wdno:P887 .
      ?item p:P887 ?statement .
      ?statement ps:P887 [] .
      BIND(wd:P887 AS ?relitem)
    }

    BIND(COALESCE(IF(wikibase:isSomeValue(?qual_dbvalue), "", ?qual_dbvalue), "") AS ?qual_value)
    BIND(COALESCE(IF(wikibase:isSomeValue(?qual_dbvalue), "unknown", "concrete"), "novalue") AS ?qual_snacktype)
  } 
}
  ?statement wikibase:rank ?rank .
  ?relitem wikibase:statementProperty ?ps .

  OPTIONAL { ?statement ?ps ?dbvalue }

  BIND(COALESCE(IF(wikibase:isSomeValue(?dbvalue), "unknown", "concrete"), "novalue") AS ?snacktype)
  BIND(IF(wikibase:isSomeValue(?dbvalue), "", ?dbvalue) AS ?value)

  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
  BIND(REPLACE(STR(?statement), ".*Q", "Q") AS ?statement_qid) 
}

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v14("?concatplus") v10("?dbvalue") v3("?item"):::projected v9("?ps") v2("?qual_dbvalue") v7("?qual_snacktype") v6("?qual_value") v8("?rank") v4("?relation") v6("?relitem") v11("?snacktype") v1("?statement") v13("?statement_qid") v12("?value"):::projected a1((" ")) c6(["p:novalue/P887"]):::iri c11(["bd:serviceParam"]):::iri c13(["#91;AUTO_LANGUAGE#93;,en"]):::literal c3(["owl:ObjectProperty"]):::iri subgraph union0[" Union "] subgraph union0l[" "] style union0l fill:#abf,stroke-dasharray: 3 3; subgraph union1[" Union "] subgraph union1l[" "] style union1l fill:#abf,stroke-dasharray: 3 3; v1 --"a"--> c6 v3 --"p:P887"--> v1 v1 --"p:statement/P887"--> a1 bind0[/"'wd:P887'"/] bind0 --as--o v6 end subgraph union1r[" "] style union1r fill:#abf,stroke-dasharray: 3 3; f1[["?relation != 'p:P887'"]] f1 --> v4 v1 --"a"--> c6 v3 -->v4--> v1 v4 --"a"--> c3 v6 --"wikibase:claim"--> v4 end union1r <== or ==> union1l end end subgraph union0r[" "] style union0r fill:#abf,stroke-dasharray: 3 3; v1 --"p:qualifier/P887"--> v2 v3 -->v4--> v1 v4 --"a"--> c3 v6 --"wikibase:claim"--> v4 end union0r <== or ==> union0l end bind2[/"if(http://wikiba.se/ontology#isSomeValue(?qual_dbvalue),'',?qual_dbvalue)''"/] v2 --o bind2 bind2 --as--o v6 bind3[/"if(http://wikiba.se/ontology#isSomeValue(?qual_dbvalue),'unknown','concrete')'novalue'"/] v2 --o bind3 bind3 --as--o v7 v1 --"wikibase:rank"--> v8 v6 --"wikibase:statementProperty"--> v9 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v1 -->v9--> v10 end bind4[/"if(http://wikiba.se/ontology#isSomeValue(?dbvalue),'unknown','concrete')'novalue'"/] v10 --o bind4 bind4 --as--o v11 bind5[/"if(http://wikiba.se/ontology#isSomeValue(?dbvalue),'',?dbvalue)"/] v10 --o bind5 bind5 --as--o v12 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c11 -."wikibase:language".-> c13 end bind6[/"replace(str(?statement),'.*Q','Q')"/] v1 --o bind6 bind6 --as--o v13 bind7[/"concat(replace(str(?item),'.*Q','Q'),'|P921|',replace(str(?value),'.*Q','Q'),'|S887|Q69652283')"/] v3 --o bind7 v12 --o bind7 bind7 --as--o v14