query-f18c1988532b743f05c74018435a964a

rq turtle/ttl

title:Using substr to emulate an array PREFIX xsd: http://www.w3.org/2001/XMLSchema# PREFIX fn: http://www.w3.org/2005/xpath-functions#

SELECT ?idx ?num ?num2 (strlen(?arr)/10 AS ?size) WHERE { BIND (CONCAT( "1.11 2.22 3.33 4.44 5.55 ", "6.66 7.77 8.88 9.99 " ) AS ?arr) BIND (2 as ?idx) BIND ((?idx * 10) + 1 AS ?pos) # Blazegraph is fine with whitespace BIND (xsd:decimal(SUBSTR(?arr, ?pos, 10)) AS ?num) # Jena doesn't like whitespace #BIND (xsd:decimal(fn:normalize-space(SUBSTR(?arr, ?pos, 10))) AS ?num2) }

Use at

#title:Using substr to emulate an array
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX fn: <http://www.w3.org/2005/xpath-functions#>

SELECT ?idx ?num ?num2 (strlen(?arr)/10 AS ?size)
WHERE {
  BIND (CONCAT(
    "1.11      2.22      3.33      4.44      5.55      ",
    "6.66      7.77      8.88      9.99      "
  ) AS ?arr)
  BIND (2 as ?idx)
  BIND ((?idx * 10) + 1 AS ?pos)
  # Blazegraph is fine with whitespace
  BIND (xsd:decimal(SUBSTR(?arr, ?pos, 10)) AS ?num)
  # Jena doesn't like whitespace
  #BIND (xsd:decimal(fn:normalize-space(SUBSTR(?arr, ?pos, 10))) AS ?num2)
}

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v1("?arr"):::projected v2("?idx"):::projected v4("?num"):::projected v3("?pos") v5("?size") bind0[/"concat('1.11 2.22 3.33 4.44 5.55 ','6.66 7.77 8.88 9.99 ')"/] bind0 --as--o v1 bind1[/"'2^^xsd:integer'"/] bind1 --as--o v2 bind2[/"?idx * '10^^xsd:integer' + '1^^xsd:integer'"/] v2 --o bind2 bind2 --as--o v3 bind3[/"http://www.w3.org/2001/XMLSchema#decimal(substring(?arr,?pos,'10^^xsd:integer'))"/] v1 --o bind3 v3 --o bind3 bind3 --as--o v4 bind4[/"string-length(?arr) / '10^^xsd:integer'"/] v1 --o bind4 bind4 --as--o v5