query-c5698c10cc437ba5371c7822ace6d588

rq turtle/ttl

Check CAS numbers with a SPARQL requestHello, ) in wikidata, without a Python script. (P231)CAS Registry Number I would like a SPARQL request for validate the all CAS Number ( i have fix CAS numbers who failed. https://github.com/simonengelke/CAS_ValidationWith this Python validation script from Github 14:51, 2 January 2018 (UTC)) talk (Manu1400. Property talk:P231 in complexe constraintThe goal, now, is to have this validation in a request for add this request as a 14:59, 2 January 2018 (UTC)) talk (Manu1400. xsd:float(?value) we can use the maths operator >http://www.w3.org/2001/XMLSchema#PREFIX xsd: <With and the status for "correct pattern" and "correct checksum". If you only want to see the erroneus ones, activate the filter on line 20.(P231)CAS Registry Number This query lists all the items with

Use at

PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
SELECT ?item ?cas ?correct_pattern ?correct_checksum WHERE
{
  ?item wdt:P231 ?cas .
  BIND(REGEX (str(?cas), '^[1-9][0-9]{1,6}-[0-9]{2}-[0-9]$') AS ?correct_pattern )
  BIND(replace(str(?cas), "-","") AS ?c)
  BIND(STRLEN(?c) AS ?strlen) 
  BIND(xsd:integer(substr(?c,?strlen,1)) AS ?val )
  BIND(xsd:integer(substr(?c,?strlen-1,1)) AS ?x1 )
  BIND(xsd:integer(substr(?c,?strlen-2,1)) AS ?x2 )
  BIND(xsd:integer(substr(?c,?strlen-3,1)) AS ?x3 )
  BIND(IF(?strlen>4,xsd:integer(substr(?c,?strlen-4,1)),0) AS ?x4 )
  BIND(IF(?strlen>5,xsd:integer(substr(?c,?strlen-5,1)),0) AS ?x5 )
  BIND(IF(?strlen>6,xsd:integer(substr(?c,?strlen-6,1)),0) AS ?x6 )
  BIND(IF(?strlen>7,xsd:integer(substr(?c,?strlen-7,1)),0) AS ?x7 )
  BIND(IF(?strlen>8,xsd:integer(substr(?c,?strlen-8,1)),0) AS ?x8 )
  BIND(IF(?strlen>9,xsd:integer(substr(?c,?strlen-9,1)),0) AS ?x9 )
  BIND(?x1+?x2*2+?x3*3+?x4*4+?x5*5+?x6*6+?x7*7+?x8*8+?x9*9 AS ?sum0)
  BIND(?sum0-(xsd:integer(?sum0/10)*10) AS ?sum )
  BIND(?sum=?val AS ?correct_checksum)
#  FILTER(!?correct_pattern|| !?correct_checksum)
}
ORDER BY ?cas

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v4("?c") v1("?cas"):::projected v18("?correct_checksum"):::projected v3("?correct_pattern"):::projected v2("?item"):::projected v5("?strlen") v17("?sum") v16("?sum0") v6("?val") v7("?x1") v8("?x2") v9("?x3") v10("?x4") v11("?x5") v12("?x6") v13("?x7") v14("?x8") v15("?x9") v2 --"wdt:P231"--> v1 bind0[/"regex(str(?cas),'^#91;1-9#93;#91;0-9#93;{1,6}-#91;0-9#93;{2}-#91;0-9#93;$')"/] v1 --o bind0 bind0 --as--o v3 bind1[/"replace(str(?cas),'-','')"/] v1 --o bind1 bind1 --as--o v4 bind2[/"string-length(?c)"/] v4 --o bind2 bind2 --as--o v5 bind3[/"http://www.w3.org/2001/XMLSchema#integer(substring(?c,?strlen,'1^^xsd:integer'))"/] v4 --o bind3 v5 --o bind3 bind3 --as--o v6 bind4[/"http://www.w3.org/2001/XMLSchema#integer(substring(?c,?strlen + '-1^^xsd:integer','1^^xsd:integer'))"/] v4 --o bind4 v5 --o bind4 bind4 --as--o v7 bind5[/"http://www.w3.org/2001/XMLSchema#integer(substring(?c,?strlen + '-2^^xsd:integer','1^^xsd:integer'))"/] v4 --o bind5 v5 --o bind5 bind5 --as--o v8 bind6[/"http://www.w3.org/2001/XMLSchema#integer(substring(?c,?strlen + '-3^^xsd:integer','1^^xsd:integer'))"/] v4 --o bind6 v5 --o bind6 bind6 --as--o v9 bind7[/"if(?strlen > '4^^xsd:integer',http://www.w3.org/2001/XMLSchema#integer(substring(?c,?strlen + '-4^^xsd:integer','1^^xsd:integer')),'0^^xsd:integer')"/] v5 --o bind7 v4 --o bind7 bind7 --as--o v10 bind8[/"if(?strlen > '5^^xsd:integer',http://www.w3.org/2001/XMLSchema#integer(substring(?c,?strlen + '-5^^xsd:integer','1^^xsd:integer')),'0^^xsd:integer')"/] v5 --o bind8 v4 --o bind8 bind8 --as--o v11 bind9[/"if(?strlen > '6^^xsd:integer',http://www.w3.org/2001/XMLSchema#integer(substring(?c,?strlen + '-6^^xsd:integer','1^^xsd:integer')),'0^^xsd:integer')"/] v5 --o bind9 v4 --o bind9 bind9 --as--o v12 bind10[/"if(?strlen > '7^^xsd:integer',http://www.w3.org/2001/XMLSchema#integer(substring(?c,?strlen + '-7^^xsd:integer','1^^xsd:integer')),'0^^xsd:integer')"/] v5 --o bind10 v4 --o bind10 bind10 --as--o v13 bind11[/"if(?strlen > '8^^xsd:integer',http://www.w3.org/2001/XMLSchema#integer(substring(?c,?strlen + '-8^^xsd:integer','1^^xsd:integer')),'0^^xsd:integer')"/] v5 --o bind11 v4 --o bind11 bind11 --as--o v14 bind12[/"if(?strlen > '9^^xsd:integer',http://www.w3.org/2001/XMLSchema#integer(substring(?c,?strlen + '-9^^xsd:integer','1^^xsd:integer')),'0^^xsd:integer')"/] v5 --o bind12 v4 --o bind12 bind12 --as--o v15 bind13[/"?x1 + ?x2 * '2^^xsd:integer' + ?x3 * '3^^xsd:integer' + ?x4 * '4^^xsd:integer' + ?x5 * '5^^xsd:integer' + ?x6 * '6^^xsd:integer' + ?x7 * '7^^xsd:integer' + ?x8 * '8^^xsd:integer' + ?x9 * '9^^xsd:integer'"/] v7 --o bind13 v8 --o bind13 v9 --o bind13 v10 --o bind13 v11 --o bind13 v12 --o bind13 v13 --o bind13 v14 --o bind13 v15 --o bind13 bind13 --as--o v16 bind14[/"?sum0 - http://www.w3.org/2001/XMLSchema#integer(?sum0 / '10^^xsd:integer') * '10^^xsd:integer'"/] v16 --o bind14 bind14 --as--o v17 bind15[/"?sum = ?val"/] v17 --o bind15 v6 --o bind15 bind15 --as--o v18