Feature Request: sh:rule and REGEX

32 views
Skip to first unread message

Clare Paul

unread,
Oct 25, 2020, 6:25:40 PM10/25/20
to TopBraid Suite Users
When I test a query using SPARQL CONSTRUCT and then copy/paste the query to make it part of a sh:SPARQLRule it usually works just fine.

However, if I use an escaped left or right square bracket as part of the REGEX pattern, the CONSTRUCT portion of the SHACL SPARQL rule needs to be edited.

Example: Use pattern to find something like "[4"
SPARQL:
VALUES ?find_pattern {'\\[[0-9]'}

SPARQL Rule:
VALUES ?find_pattern {'\\\\[[0-9]'}

If I use the SPARQL version of the pattern, EDG flags an error when the rule is executed:
Lexical error at line39, column 27. Encountered: "[" (91), after "\'\\"

I believe this has something to do with [ needing to be escaped for REGEX and then the  \  in \[ needing to be escaped for Java.

Would it make sense for EDG to automatically convert \\[ to \\\\[ when encountered in an instance sh:SPARQLRule?

Thanks,
Clare


Holger Knublauch

unread,
Oct 25, 2020, 8:38:01 PM10/25/20
to topbrai...@googlegroups.com

Hi Clare,

if I understand your scenario correctly then the difference that you describe is because of the Turtle serialization. For any string literal that contains \ Turtle will write \\

As a result, while you edit queries in a form-based editor you just enter \ but when you save to a file or edit Source Code you would see \\

There is nothing wrong about that, and EDG doesn't have to do any automatic conversion.

If I have misunderstood your scenario please send a minimal but complete example, in TTL format.

Regards,
Holger

--
You received this message because you are subscribed to the Google Groups "TopBraid Suite Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to topbraid-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/topbraid-users/cc5ff1fd-e230-467b-b187-d0a74c455f43n%40googlegroups.com.

Clare Paul

unread,
Oct 26, 2020, 9:52:45 AM10/26/20
to TopBraid Suite Users
Holger,
I've attached a couple of files.  One file contains everything required to execute the SPARQL rule: ex:RuleForFindingBracketedNumbers.  The  rule's REGEX pattern has four backslashes prior to a square bracket.

An example of a bracketed number is [4].  The sample resources are instances of the class ex:CandidateResource. The rule finds resource labels that match a REGEX pattern and types them as ex:BracketedNumber.  

The second file contains the SPARQL CONSTRUCT that was used to test the query.  The REGEX pattern has two backslashes prior to a square bracket.

The SPARQL CONSTRUCT was copied and then pasted as the value for sh:construct.

After adding the backslashes to the REGEX pattern in the rule, everything worked as expected on EDG 6.4.2.

Thanks,
Clare

Note: for some reason, Google Groups flags an error when I try to include the files.

Clare Paul

unread,
Oct 26, 2020, 9:56:13 AM10/26/20
to TopBraid Suite Users
20201026_square_brackets_and_shacl_rules.txt

Clare Paul

unread,
Oct 26, 2020, 9:57:23 AM10/26/20
to TopBraid Suite Users
The file extensions were changed from ttl to txt.
20201026_BracketedNumberSPARQL_CONSTRUCT.txt

Holger Knublauch

unread,
Oct 26, 2020, 6:09:19 PM10/26/20
to topbrai...@googlegroups.com

It all looks correct to me. One cannot compare .sparql files with .turtle files as Turtle requires escaping the \ character, while SPARQL text files do not.

Holger

--
You received this message because you are subscribed to the Google Groups "TopBraid Suite Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to topbraid-user...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages