query-54025c377929eed140ba8003ab1c6bac

rq turtle/ttl

results where items are Q itemsI'm working with the following query to find items related. How can I change it to only return rows with a Q item? Also, I'd like to filter out "described by source" type relations as well as negative ones like "opposite of." Thanks, Marc Mason

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT ?wdLabel ?ps_Label ?ps_ ?ps {
  VALUES (?item) {(wd:Q197)}
  ?item ?p ?statement .
  ?statement ?ps ?ps_ .
  ?wd wikibase:claim ?p.
  ?wd wikibase:statementProperty ?ps.
  OPTIONAL {   ?statement ?pq ?pq_ .   ?wdpq wikibase:qualifier ?pq .   }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" } } 
ORDER BY ?wd ?statement ?ps_

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v4("?item") v5("?p") v7("?pq") v8("?pq_") v6("?ps"):::projected v3("?ps_"):::projected v2("?statement") v1("?wd") v9("?wdpq") c5(["bd:serviceParam"]):::iri c7(["en"]):::literal bind0[/VALUES ?item/] bind0-->v4 bind00(["wd:Q197"]) bind00 --> bind0 v4 -->v5--> v2 v2 -->v6--> v3 v1 --"wikibase:claim"--> v5 v1 --"wikibase:statementProperty"--> v6 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v2 -->v7--> v8 v9 -."wikibase:qualifier".-> v7 end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c5 --"wikibase:language"--> c7 end