SPARQL string RANGE

I am trying to extract part of a string using index numbers. When

"OEIUFHWOIEFWNFOPQWJFHQWOIHFEB..." 

and I need a line from 5:10 (FHWOIE) . I found out that this is not possible with REGEX, since it returns only logical, not groups. However, I could not find the selection of the region line by line through the positions. Now I wonder if there are any?

I found out that this is partially possible through ...

 BIND(REPLACE(?sequence, '^.{100}', "") AS ?sequencestrip1) 

but not

 BIND(REPLACE(?sequence, '^.{?start}', "") AS ?sequencestrip1) 

I think this does it for everyone who is interested:

 BIND(REPLACE(?sequence, "^.{"+str(?start)+"}", "") AS ?sequencestrip1) 

and of course delete the area that interests you

 BIND(REPLACE(?region, ".{"+str(strlen(?region)-10)+"}$", "") AS ?upstream) 
+4
source share
1 answer

In the first SPARQL query language for RDF, this would be rather complicated, because there are few manipulation functions with many strings. However, in your question, you used replace , which appeared in SPARQL 1.1 Query Language . This is good for you because, in addition to replace , SPARQL 1.1 includes more string manipulation functions. One of them, substr , does exactly what you need. For example, here is a query in which ?string bound to the ?string you specify, and substr used to retrieve the substring you are looking for, and bind it as ?substring .

 select * where { values ?string { "OEIUFHWOIEFWNFOPQWJFHQWOIHFEB..." } bind( substr( ?string, 5, 6 ) as ?substring ) } 

Results:

 -------------------------------------------------- | string | substring | ================================================== | "OEIUFHWOIEFWNFOPQWJFHQWOIHFEB..." | "FHWOIE" | -------------------------------------------------- 

Note that the second argument to substr is the start position (where the first index is 1), and the third is the length of the substring, not the end position. You wanted a substring, FHWOIE , which has six characters, and the third argument is 6.

+5
source

Source: https://habr.com/ru/post/1494648/


All Articles