query-11fe669f092b032f923b08e1b73782f9

rq turtle/ttl

Query to extract a subsetQuery to extract 2n+1 value-hex pairsThis can be included as a named sub-query in a WDQS query, if a particular number of colours are wanted from blue to red

Use at

PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
SELECT ?colour ?rgb WHERE {
    VALUES ?sequence {wd:Q105849312} .     # desired colour progression
    VALUES ?n {4} .                        # desired no of points either side of centre

    ?sequence p:P527 ?stmt .
    ?stmt pq:P1545 ?seq .
    ?stmt pq:P465 ?rgb .

    ?sequence p:P2670/pq:P1114 ?len .
    BIND(((?len + 1.0)/2.0) AS ?centre) .
    BIND (floor((?centre - 1.0) / xsd:float(?n)) AS ?step) .
    BIND (?n + 1.0 + ((xsd:float(?seq) - ?centre)  / xsd:float(?step)) AS ?colour) .

    FILTER(?colour = floor(?colour))
    FILTER(?colour >= 1)
    FILTER(?colour <= 1 + 2* ?n)
  } ORDER BY ?colour

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v8("?centre") v10("?colour"):::projected v7("?len") v4("?n") v6("?rgb"):::projected v5("?seq") v3("?sequence") v9("?step") v4("?stmt") a1((" ")) f0[["?colour <= '1^^xsd:integer' + '2^^xsd:integer' * ?n"]] f0 --> v10 f0 --> v4 f1[["?colour >= '1^^xsd:integer'"]] f1 --> v10 f2[["?colour = numeric-floor(?colour)"]] f2 --> v10 bind3[/VALUES ?sequence/] bind3-->v3 bind30(["wd:Q105849312"]) bind30 --> bind3 bind4[/VALUES ?n/] bind4-->v4 bind40(["4^^xsd:integer"]) bind40 --> bind4 v3 --"p:P527"--> v4 v4 --"p:qualifier/P1545"--> v5 v4 --"p:qualifier/P465"--> v6 v3 --"p:P2670"--> a1 a1 --"p:qualifier/P1114"--> v7 bind5[/"?len + '1.0^^xsd:decimal' / '2.0^^xsd:decimal'"/] v7 --o bind5 bind5 --as--o v8 bind6[/"numeric-floor(?centre - '1.0^^xsd:decimal' / http://www.w3.org/2001/XMLSchema#float(?n))"/] v8 --o bind6 v4 --o bind6 bind6 --as--o v9 bind7[/"?n + '1.0^^xsd:decimal' + http://www.w3.org/2001/XMLSchema#float(?seq) - ?centre / http://www.w3.org/2001/XMLSchema#float(?step)"/] v4 --o bind7 v5 --o bind7 v8 --o bind7 v9 --o bind7 bind7 --as--o v10