query-7d6cfdae8513e729846bade00879c84a

rq turtle/ttl

Obviamente se pueden añadir más condiciones a la consulta. Y otro ejemplo que me pasan por Telegram que no sé realmente interpretar pq a esta hora estoy empanao :-)

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX schema: <http://schema.org/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX prov: <http://www.w3.org/ns/prov#>
PREFIX pr: <http://www.wikidata.org/prop/reference/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
select distinct ?item ?itemLabel {
  ?a ?p1 wd:Q1631944.

  # ignore sitelinks
  minus { ?a schema:about wd:Q1631944 }

  # if ?a is a statement node (has a rank), ?p1 is a predicate like ps: or pq:
  # so select triples which use the statement node as a value (?p2 is a p: predicate)
  optional {
    ?a wikibase:rank [].
    ?b ?p2 ?a.
  }

  # if ?a is a reference node, a statement node links to it using prov:wasDerivedFrom
  # again, select triples which use the statement node as a value
  optional {
    ?c ?p3 [ prov:wasDerivedFrom ?a ].
  }

  # assign ?item to the first assigned value out of ?b (ps:/pq:), ?c (pr:) and ?a (wdt: and any cases not caught by the previous two)
  bind (coalesce(?b, ?c, ?a) as ?item)

  service wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
} order by ?itemLabel ?item

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v3("?a") v5("?b") v7("?c") v9("?item"):::projected v1("?itemLabel"):::projected v4("?p1") v6("?p2") v8("?p3") a1((" ")) a2((" ")) c6(["bd:serviceParam"]):::iri c1(["wd:Q1631944"]):::iri c8(["#91;AUTO_LANGUAGE#93;,en"]):::literal v3 -->v4--> c1 subgraph minus0["MINUS"] style minus0 stroke-width:6px,fill:pink,stroke:red; v3 --"schema:about"--> c1 end subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v3 -."wikibase:rank".-> a1 v5 -->v6--> v3 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; a2 -."prov:wasDerivedFrom".-> v3 v7 -->v8--> a2 end bind1[/"?b?c?a"/] v5 --o bind1 v7 --o bind1 v3 --o bind1 bind1 --as--o v9 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c6 --"wikibase:language"--> c8 end