Search code examples
javaxmlrdfjena

How to itearate RML Mapping language for XML node not having id?


I want to iterate XML node with iteration without id attribute as in my code is it possible?. I am a beginner in RML mapping language. I am using the RML Mapping tool its link is here https://github.com/RMLio/RML-Mapper

I have iterate successfully with using "ID" but I don't want to iterate with id because my XML data doesn't contain id so is it possible to do it without ID attribute or it's compulsory to use the id to iterate in RML Mapping. PLease give you suggestions

here is my XML file data

<MainNode>
   <Header>
      <code>404</code>
      <title>demoxml1</title>
   </Header>
   <Employees>
      <Employee **id="1"**>
         <EmpNo>1</EmpNo>
         <EmpSex>2</EmpSex>
         <BirthYear>1991</BirthYear>
         <Postcode>12345</Postcode>         
         <Indications>
            <Indication id="2">
               <IndicationNo>1</IndicationNo>
               <StartDate>11-12-2016</StartDate>               
            </Indication>
         </Indications>
      </Employee>
      <Employee id="2">
         <EmpNo>2</EmpNo>
         <EmpSex>2</EmpSex>
         <BirthYear>1992</BirthYear>
         <Postcode>12345</Postcode>
         <Indications>
            <Indication id="2">
               <IndicationNo>1</IndicationNo>
               <StartDate>11-12-2016</StartDate>               
            </Indication>
         </Indications>
      </Employee>
   </Employees>
</MainNode>

here is my RML Mapping File:

@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 test: <http://www.example.com/organization>.
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
@prefix ex: <http://www.example.com/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
@prefix ns1: <http://www.example.com/organization/DataProperty/Employee/> .
@prefix ns2: <http://www.example.com/organization/DataProperty/Employee/Indication/> .

<#EmployeeMapping>
rml:logicalSource [ 
    rml:source "src/test/rmlmapping/test_example.xml";
    rml:iterator "/MainNode/Employees/Employee";
    rml:referenceFormulation ql:XPath;
];
rr:subjectMap [
        rr:template "http://www.example.com/Employee#{@id}"; 
        rr:class test:Employee;
            ];


    rr:predicateObjectMap [

        rr:predicate ns1:EmpNo;
        rr:objectMap [ rml:reference "EmpNo" ];
    ];

        rr:predicateObjectMap [
        rr:predicate ns1:EmpSex;
        rr:objectMap [ rml:reference "EmpSex" ];
    ];

    rr:predicateObjectMap [
        rr:predicate ns1:BirthYear;
        rr:objectMap [ rml:reference "BirthYear" ];
    ];
    rr:predicateObjectMap [
        rr:predicate ns1:Postcode;
        rr:objectMap [ rml:reference "Postcode" ];
    ];

    rr:predicateObjectMap [
        rr:predicate ns1:Indication;
        rr:objectMap [ 
            rr:parentTriplesMap <#IndicatieMapping>;            
        ];
    ].
<#IndicatieMapping>
  rml:logicalSource [
    rml:source "src/test/rmlmapping/test_example.xml" ;
    rml:iterator "/MainNode/Employees/Employee/Indications/Indication";
    rml:referenceFormulation ql:XPath;
  ];

  rr:subjectMap [ 
    rr:template "http://www.example.com/Employee/Indication#{@id}";
    rr:class test:Indication;   
  ];

  rr:predicateObjectMap [
    rr:predicate ns2:IndicationNo;
    rr:objectMap [
      rml:reference "IndicationNo";
    ]; 
  ];

  rr:predicateObjectMap [
    rr:predicate ns2:StartDate;
    rr:objectMap [
      rml:reference "StartDate";
    ]; 
  ].

here is my RML Mapping output:

<http://www.example.com/Employee#1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.example.com/organizationEmployee> .
<http://www.example.com/Employee#1> <http://www.example.com/organization/DataProperty/Employee/Indication> <http://www.example.com/Employee/Indication#2> .
<http://www.example.com/Employee/Indication#2> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.example.com/organizationIndication> .
<http://www.example.com/Employee/Indication#2> <http://www.example.com/organization/DataProperty/Employee/Indication/StartDate> "11-12-2016" .
<http://www.example.com/Employee/Indication#2> <http://www.example.com/organization/DataProperty/Employee/Indication/IndicationNo> "1" .
<http://www.example.com/Employee#1> <http://www.example.com/organization/DataProperty/Employee/BirthYear> "1991" .
<http://www.example.com/Employee#1> <http://www.example.com/organization/DataProperty/Employee/EmpNo> "1" .
<http://www.example.com/Employee#1> <http://www.example.com/organization/DataProperty/Employee/EmpSex> "2" .
<http://www.example.com/Employee#1> <http://www.example.com/organization/DataProperty/Employee/Postcode> "12345" .
<http://www.example.com/Employee#2> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.example.com/organizationEmployee> .
<http://www.example.com/Employee#2> <http://www.example.com/organization/DataProperty/Employee/Indication> <http://www.example.com/Employee/Indication#2> .
<http://www.example.com/Employee/Indication#2> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.example.com/organizationIndication> .
<http://www.example.com/Employee/Indication#2> <http://www.example.com/organization/DataProperty/Employee/Indication/StartDate> "11-12-2016" .
<http://www.example.com/Employee/Indication#2> <http://www.example.com/organization/DataProperty/Employee/Indication/IndicationNo> "1" .
<http://www.example.com/Employee#2> <http://www.example.com/organization/DataProperty/Employee/BirthYear> "1992" .
<http://www.example.com/Employee#2> <http://www.example.com/organization/DataProperty/Employee/EmpNo> "2" .
<http://www.example.com/Employee#2> <http://www.example.com/organization/DataProperty/Employee/EmpSex> "2" .
<http://www.example.com/Employee#2> <http://www.example.com/organization/DataProperty/Employee/Postcode> "12345" .

For example, I want to iterate Employee node wise and indication node wise iteration in RMl Mapping.can you provide your comment will I have to make my XML document node like in example employee node, indication node, etc. with attribute id or it is possible to do without it.


Solution

  • In your current mapping you aren't iterating using the id attribute. Since your iterators are

    rml:iterator "/MainNode/Employees/Employee";
    

    and

    rml:iterator "/MainNode/Employees/Employee/Indications/Indication";
    

    Note the absence of an id attribute.

    You seem to only use the id attribute for subject IRI generation:

      rr:subjectMap [
        rr:template "http://www.example.com/Employee#{@id}"; 
        rr:class test:Employee;
      ];
    

    and

      rr:subjectMap [ 
        rr:template "http://www.example.com/Employee/Indication#{@id}";
        rr:class test:Indication;   
      ];
    

    You could e.g. create the subjects based on "EmpNo" and "IndicationNo" respectively. But it depends on your source data if these attributes alone are discriminating enough to be used for IRI generation.