RMLio / yarrrml-parser

A YARRRML parser library and CLI in Javascript
MIT License
41 stars 17 forks source link

XPath Syntax in Templates #133

Open robert-mieth opened 3 years ago

robert-mieth commented 3 years ago

Issue type: :question: Question

I've been trying to use XPath axes such as parent::* or ancestor::* within templates in nested mappings. I assumed that I could use them like a rr:parentTriplesMap in the RMLMapper.

XML:

<?xml version='1.0' encoding='UTF-8'?>
<ex:root xmlns:ex="http://example.com/">
    <ex:organization>
        <ex:id>1</ex:id>
            <ex:department>
                <ex:team>
                    <ex:member>
                        <ex:name>John Doe</ex:name>
                    </ex:member>
                </ex:team>
            </ex:department>
    </ex:organization>
</ex:root>

YARRRML:

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

mappings:
 organization:
    sources:
      - [xpath_example.xml~xpath, "root//organization"]
    subjects: ex:organization/$(id)
    po:
      - [a, ex:organization]
      - p: ex:hasMember
        o:
          - mapping: member
            condition:
              function: equal
              parameters:
                - [str1, $(id), s]
              # use of xpath axis
              # - [str2, $(ancestor::organization/id), o]
                - [str2, $(//organization/id), o]
 member:
  sources:
   - [xpath_example.xml~xpath, "root//member"]
  subjects: ex:member/$(name)
  po:
      - [a, ex:member]

I personally quite like the option to deal with (more heavily) nested XML by using XPath axes.

Is there a way to use XPath axes with the YARRRML Parser?

pheyvaer commented 2 years ago

Hi @robert-mieth

YARRRML rules are converted to RML rules. The YARRRML parser itself doesn't interpret any of the rules. So no changes are made to the XPath paths. Are you using the RMLMapper to execute the converted RML rules? Because then it depends on the XML library that is used in the RMLMapper.

robert-mieth commented 2 years ago

Hi @pheyvaer I'm sorry for the late reply. I just double checked and the generated RML rules seem to be fine. Using the RMLMapper they generate the expected triples. I think that I got thrown off by the error messages printed by the yarrrml-parser:

prefix "ancestor" was not found.
prefix "ancestor" was not found.

I thus incorrectly assumed that the RML generation failed. It would be great if you could tweak the logger to not print an error message when XPath prefixes are used.

pheyvaer commented 2 years ago

Hi @robert-mieth

That makes sense. Is there a way to know which prefixes are XPath?