SHACL property value rules: using BIND and REPLACE with special characters

22 views
Skip to first unread message

Dan Segal

unread,
Sep 14, 2023, 2:23:33 PM9/14/23
to TopBraid Suite Users
Hello,

I am trying to use a property value rule to infer a value from another property.

The use case involves using REGEX to strip out certain strings and special characters.

The logic works OK with alphanumeric characters, but it returns an error on special characters.

For example, the following statement works OK:

sh:values [
      sh:select """

        SELECT ?value2

        WHERE {

            $this <http://www.example.org#property1> ?value1 .

        BIND (REPLACE (?value1, "foo" ,"") AS ?value2)

        }

""" ;
    ];

However, the following statement, which is intended to remove the [ character, returns an error:

sh:values [
      sh:select """

        SELECT ?value2

        WHERE {

            $this <http://www.example.org#property1> ?value1 .

        BIND (REPLACE (?value1, "\\[" ,"") AS ?value2)

        }

""" ;
    ];


The escape characters \\ work OK in a SPARQL query.  However, in the property value rule, they return the following error:

    (SHACL node expression of unknown type: org.apache.jena.query.QueryParseException:... Encountered: '91' (91), after prefix "\"\\")


Is there a different way to indicate escape characters, so that REGEX can be used in the BIND/REPLACE statement?

Thank you,

Dan Segal




Holger Knublauch

unread,
Sep 15, 2023, 3:09:27 AM9/15/23
to topbrai...@googlegroups.com
Hi Dan,

I guess the problem is that the Turtle serialization uses its own escaping mechanism. So if you want to pass \\ to SPARQL you will likely need to escape it twice, using \\\\

Holger


--
The topics of this mailing list include TopBraid EDG and related technologies such as SHACL.
To post to this group, send email to topbrai...@googlegroups.com
---
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/efee929b-57a2-47a2-a1a1-0a577420278en%40googlegroups.com.

Dan Segal

unread,
Sep 15, 2023, 11:48:32 AM9/15/23
to TopBraid Suite Users
Hi Holger,

Inserting the additional escape characters - \\\\ - was successful.

Thank you for the suggestion...Much appreciated!

Regards,

Dan
Reply all
Reply to author
Forward
0 new messages