RMLio/yarrrml-parser

Parser failed to handle template definitions with xpath functions

tjroamer opened this issue ยท 5 comments

Issue type: ๐Ÿ› Bug

Description

The parser failed to handle template with xpath functions

Steps

Use the following yaml as input

prefixes:
  ex: http://www.example.com/

mappings:
  ExampleMap:
    sources:
      - [example.xml~xpath, /Root]
    s: ex:Root
    po:
      - [a, ex:Model]
      - [ex:compIndex, $(count(preceding-sibling\:\:Comp))]

The parser generates the following output for the last line which contains an xpath function count(..):

@prefix rr: <http://www.w3.org/ns/r2rml#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix fnml: <http://semweb.mmlab.be/ns/fnml#> .
@prefix fno: <https://w3id.org/function/ontology#> .
@prefix d2rq: <http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#> .
@prefix void: <http://rdfs.org/ns/void#> .
@prefix dc: <http://purl.org/dc/terms/> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix rml: <http://semweb.mmlab.be/ns/rml#> .
@prefix ql: <http://semweb.mmlab.be/ns/ql#> .
@prefix : <http://mapping.example.com/> .
@prefix ex: <http://www.example.com/> .

:rules_000 rdf:type void:Dataset ;
        void:exampleResource :map_ExampleMap_000 .

:map_ExampleMap_000 rml:logicalSource :source_000 ;
        rdf:type rr:TriplesMap ;
        rdfs:label "ExampleMap" ;
        rr:subjectMap :s_000 ;
        rr:predicateObjectMap :pom_000, :pom_001 .

:source_000 rdf:type rml:LogicalSource ;
        rml:source "example.xml" ;
        rml:iterator "/Root" ;
        rml:referenceFormulation ql:XPath .

:s_000 rdf:type rr:SubjectMap ;
        rr:constant "http://www.example.com/Root" .

:pom_000 rdf:type rr:PredicateObjectMap ;
        rr:predicateMap :pm_000 ;
        rr:objectMap :om_000 .

:pm_000 rdf:type rr:PredicateMap ;
        rr:constant rdf:type .

:om_000 rdf:type rr:ObjectMap ;
        rr:constant "http://www.example.com/Model" ;
        rr:termType rr:IRI .

:pom_001 rdf:type rr:PredicateObjectMap ;
        rr:predicateMap :pm_001 ;
        rr:objectMap :om_001 .

:pm_001 rdf:type rr:PredicateMap ;
        rr:constant ex:compIndex .

:om_001 rdf:type rr:ObjectMap ;
        rr:template "{count(preceding-sibling::Comp})" ;        ############# BUG
        rr:termType rr:Literal .

Expected output for the marked line is: rr:template "{count(preceding-sibling::Comp)}"

Environment

Java version: openjdk 11.0.14.1 2022-02-08 LTS
OS: Windows 10

Hi @tjroamer

Thanks for the issue. It indeed seems like a bug. We will look into it!

It's possible to do this by escaping the first ), resulting in the following YARRRML rules.

prefixes:
  ex: http://www.example.com/

mappings:
  ExampleMap:
    sources:
      - [example.xml~xpath, /Root]
    s: ex:Root
    po:
      - [a, ex:Model]
      - [ex:compIndex, $(count(preceding-sibling\:\:Comp\))]

Yes, adding the backslash resolved the issue. Thanks.

Great! Can we close this issue then?

Sure, thanks for your support.