query-42d98b80ba8f349e341fa79259327aeb

rq turtle/ttl

title tots els continguts d'uns items, unes propietats i filtrable per un valor específic

SELECT distinct ?item ?property ?value ?unit ?pq ?qualifier_value ?qualifier_unit ?ref ?pr ?rval WHERE { VALUES ?item { wd:Q515526 } # obligatori, es pot posar una llista VALUES ?property { wd:P39 } # obligatori, pot ser més d'una propietat VALUES ?value { wd:Q110546839 } # opcional. Si no s'informa extraurà tots els valors que tingui la property

?property wikibase:claim ?claim .

# Get amount and unit for the statement ?item ?claim ?statement . { ?property wikibase:propertyType ?property_type . FILTER (?property_type != wikibase:Quantity) ?property wikibase:statementProperty ?propertyStatement . ?statement ?propertyStatement ?value . } UNION { ?property wikibase:statementValue ?statementValue . ?statement ?statementValue [wikibase:quantityAmount ?value; wikibase:quantityUnit ?unit] . }

# Get qualifiers OPTIONAL { { # Get simple values for qualifiers which are not of type quantity ?statement ?propQualifier ?qualifier_value . ?pq wikibase:qualifier ?propQualifier . ?pq wikibase:propertyType ?qualifer_property_type . FILTER (?qualifer_property_type != wikibase:Quantity) } UNION { # Get amount and unit for qualifiers of type quantity ?statement ?pqv [wikibase:quantityAmount ?qualifier_value; wikibase:quantityUnit ?qualifier_unit] . ?pq wikibase:qualifierValue ?pqv . } }

# get references OPTIONAL { ?statement prov:wasDerivedFrom ?ref . ?ref ?pr ?rval . [] wikibase:reference ?pr } }

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX prov: <http://www.w3.org/ns/prov#>
#title tots els continguts d'uns items, unes propietats i filtrable per un valor específic


SELECT distinct ?item ?property ?value ?unit ?pq ?qualifier_value ?qualifier_unit ?ref ?pr ?rval
WHERE
{
  VALUES ?item { wd:Q515526 }       # obligatori, es pot posar una llista
  VALUES ?property { wd:P39 }       # obligatori, pot ser més d'una propietat
  VALUES ?value { wd:Q110546839 }   # opcional. Si no s'informa extraurà tots els valors que tingui la property 

  ?property wikibase:claim ?claim .

  # Get amount and unit for the statement
  ?item ?claim ?statement .
  {
    ?property wikibase:propertyType ?property_type .
    FILTER (?property_type != wikibase:Quantity)
    ?property wikibase:statementProperty ?propertyStatement .
    ?statement ?propertyStatement ?value .
  }
  UNION
  {
    ?property wikibase:statementValue ?statementValue .
    ?statement ?statementValue [wikibase:quantityAmount ?value; wikibase:quantityUnit ?unit] .
  }

  # Get qualifiers
  OPTIONAL
  {
    {
      # Get simple values for qualifiers which are not of type quantity
      ?statement ?propQualifier ?qualifier_value .
      ?pq wikibase:qualifier ?propQualifier .
      ?pq wikibase:propertyType ?qualifer_property_type .
      FILTER (?qualifer_property_type != wikibase:Quantity)
    }
    UNION
    {
      # Get amount and unit for qualifiers of type quantity
      ?statement ?pqv [wikibase:quantityAmount ?qualifier_value; wikibase:quantityUnit ?qualifier_unit] .
      ?pq wikibase:qualifierValue ?pqv .
    }
  }

  # get references
  OPTIONAL {
    ?statement prov:wasDerivedFrom ?ref .
    ?ref ?pr ?rval .
    [] wikibase:reference ?pr
  }
}

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v4("?claim") v1("?item"):::projected v13("?pq"):::projected v15("?pqv") v17("?pr"):::projected v11("?propQualifier") v2("?property"):::projected v7("?propertyStatement") v6("?property_type") v10("?qualifer_property_type") v14("?qualifier_unit"):::projected v12("?qualifier_value"):::projected v16("?ref"):::projected v18("?rval"):::projected v5("?statement") v8("?statementValue") v9("?unit"):::projected v3("?value"):::projected a3((" ")) a1((" ")) a2((" ")) bind0[/VALUES ?item/] bind0-->v1 bind00(["wd:Q515526"]) bind00 --> bind0 bind1[/VALUES ?property/] bind1-->v2 bind10(["wd:P39"]) bind10 --> bind1 bind2[/VALUES ?value/] bind2-->v3 bind20(["wd:Q110546839"]) bind20 --> bind2 v2 --"wikibase:claim"--> v4 v1 -->v4--> v5 subgraph union0[" Union "] subgraph union0l[" "] style union0l fill:#abf,stroke-dasharray: 3 3; v2 --"wikibase:statementValue"--> v8 a1 --"wikibase:quantityAmount"--> v3 a1 --"wikibase:quantityUnit"--> v9 v5 -->v8--> a1 end subgraph union0r[" "] style union0r fill:#abf,stroke-dasharray: 3 3; f3[["?property_type != 'wikibase:Quantity'"]] f3 --> v6 v2 --"wikibase:propertyType"--> v6 v2 --"wikibase:statementProperty"--> v7 v5 -->v7--> v3 end union0r <== or ==> union0l end subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; subgraph union1[" Union "] subgraph union1l[" "] style union1l fill:#abf,stroke-dasharray: 3 3; a2 -."wikibase:quantityAmount".-> v12 a2 --"wikibase:quantityUnit"--> v14 v5 -->v15--> a2 v13 --"wikibase:qualifierValue"--> v15 end subgraph union1r[" "] style union1r fill:#abf,stroke-dasharray: 3 3; f4[["?qualifer_property_type != 'wikibase:Quantity'"]] f4 --> v10 v5 -->v11--> v12 v13 --"wikibase:qualifier"--> v11 v13 --"wikibase:propertyType"--> v10 end union1r <== or ==> union1l end end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v5 -."prov:wasDerivedFrom".-> v16 v16 -->v17--> v18 a3 --"wikibase:reference"--> v17 end