On Monday, October 26, 2020 at 9:52:45 AM UTC-4 Clare Paul wrote:

> 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.
>
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/topbraid-users/f87a79bd-aa57-4a09-a8be-4199f36687ccn%40googlegroups.com.
# baseURI: urn:x-evn-master:square_brackets_and_shacl_rules
# imports: http://datashapes.org/graphql
# imports: http://topbraid.org/teamworkconstraints

@prefix ex: <http://example.org/ontologies/Square_Brackets_and_SHACL_Rules#> .
@prefix metadata: <http://topbraid.org/metadata#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix teamwork: <http://topbraid.org/teamwork#> .

ex:BracketedNumber
  a owl:Class ;
  a sh:NodeShape ;
  rdfs:label "BracketedNumber" ;
  rdfs:subClassOf owl:Thing ;
.
ex:CandidateResource
  a owl:Class ;
  a sh:NodeShape ;
  rdfs:label "CandidateResource" ;
  rdfs:subClassOf owl:Thing ;
  sh:rule ex:RuleForFindingBracketedNumbers ;
.
ex:RuleForFindingBracketedNumbers
  a sh:SPARQLRule ;
  rdfs:comment """
Four backslashes are required before square brackets in REGEX pattern. Error 
message with two  backslashes before a square bracket: Failed to execute rules: 
org.apache.jena.query.QueryParseException: Lexical error at line 24, column 27. 
Encountered: \"[\" (91), after : \"'\\\" 
""" ;
  rdfs:comment "This rule types the found resource as ex:BracketedNumber." ;
  rdfs:label "RuleForFindingBracketedNumbers" ;
  sh:construct """
CONSTRUCT {$this rdf:type ex:BracketedNumber .}
WHERE {
  #?res a ex:CandidateResource .
  $this rdfs:label ?res_label .
  #----------
  VALUES ?find_pattern {'\\\\[[0-9]\\\\]'}           
  FILTER(REGEX(?res_label,?find_pattern))
}
""" ;
  sh:prefixes <urn:x-evn-master:square_brackets_and_shacl_rules> ;
.
ex:txt01
  a ex:CandidateResource ;
  rdfs:label "abc[5]def" ;
.
ex:txt02
  a ex:CandidateResource ;
  rdfs:label "abc[z]def" ;
.
ex:txt03
  a ex:CandidateResource ;
  rdfs:label "abcdef" ;
.
<http://teamwork.topbraidlive.org/ontologyprojects#Ontology>
  rdfs:subClassOf teamwork:Vocabulary ;
.
teamwork:Vocabulary
  rdfs:subClassOf owl:Ontology ;
.
<urn:x-evn-master:square_brackets_and_shacl_rules>
  a <http://teamwork.topbraidlive.org/ontologyprojects#Ontology> ;
  a teamwork:Vocabulary ;
  a owl:Ontology ;
  metadata:status metadata:UnderDevelopmentStatus ;
  <http://topbraid.org/swa#defaultNamespace> 
"http://example.org/ontologies/Square_Brackets_and_SHACL_Rules#"; ;
  teamwork:rootClass rdfs:Resource ;
  rdfs:label "Square Brackets and SHACL Rules" ;
  owl:imports <http://datashapes.org/graphql> ;
  owl:imports <http://topbraid.org/teamworkconstraints> ;
  sh:declare [
      sh:namespace 
"http://example.org/ontologies/Square_Brackets_and_SHACL_Rules#"^^<http://www.w3.org/2001/XMLSchema#anyURI>
 ;
      sh:prefix "ex" ;
    ] ;
.

Reply via email to