RMLio / RML-Mapper

Generate High Quality Linked Data from multiple originally (semi-)structured data (legacy)
http://RML.io
52 stars 20 forks source link

xpath example #32

Open rajaram5 opened 6 years ago

rajaram5 commented 6 years ago

Hello,

I was trying to generate subject url with IDs from two different nodes (Child and parent node). For example, lets say that I want to generate url of this pattern <http://www.example.com/note/{notes id}/{note id}> is it possible to generate this url pattern in RML? I also tried using ancestor:: option in the RML but, it didn't work.

Example XML:

<?xml version="1.0" encoding="UTF-8"?>
<notes id="Notebook2">
<note id="M17" day="10" month="01" year="2008"> 
        <to>Tove</to>
        <from>Jani</from>
        <heading>Reminder</heading>
        <body>Don't forget me this weekend!</body>
</note>
<note id="M18" day="10" month="02" year="2008"> 
        <to>Chris</to>
        <from>Rick</from>
        <heading>Update</heading>
        <body>We now leave at six</body>
</note>
</notes>

Example RML (Not working)

@prefix rr: <http://www.w3.org/ns/r2rml#>.
@prefix  rml: <http://semweb.mmlab.be/ns/rml#> .
@prefix ql: <http://semweb.mmlab.be/ns/ql#> .
@prefix mail: <http://example.com/mail#>.
@base <http://example.com/base> .

<#FromToMaps>
rml:logicalSource [ 
    rml:source "/home/rajaram/work/zin-byod/rr-work/test.xml";
        rml:referenceFormulation ql:XPath;
    rml:iterator "/notes";
];
rr:subjectMap [
        rr:template "http://www.example.com/note/{@id}/{/note/@id}"; 
        rr:class mail:note;
 ].
pheyvaer commented 6 years ago

Hi,

The following mapping works and should achieve what you want. More specific, I changed the iterator and the template. Now you iterate over all notes instead of only the notebooks and I use the ancestor to get the id of the notebook.

<#FromToMaps>
rml:logicalSource [
        rml:source "input.xml";
        rml:referenceFormulation ql:XPath;
        rml:iterator "/notes/note";
];
rr:subjectMap [
        rr:template "http://www.example.com/note/{ancestor::notes/@id}/{@id}"; 
        rr:class mail:note;
 ].
rajaram5 commented 6 years ago

Hi Pieter,

Thank you for your reply, but the proposed solution is not working for me. I am using RMLMapper v0.3.1

pheyvaer commented 6 years ago

Indeed, apparently the ancestor operator is not supported. I'll have a closer look.

pheyvaer commented 6 years ago

Apparently the XML/XPath library that we are using does not supported the ancestor operator. If you by any chance know about a Java library that does we can help in replacing the current one with the new one.

rajaram5 commented 6 years ago

I don't work much with XML library but I can have a look