我想迭代使用没有id属性的迭代的XML节点,因为我的代码是可能的吗? 我是RML映射语言的初学者。 我正在使用RML Mapping工具,其链接在https://github.com/RMLio/RML-Mapper
我使用“ID”成功迭代,但我不想使用id进行迭代,因为我的XML数据不包含id,所以可以在没有ID属性的情况下进行迭代,或者必须使用id来迭代在RML映射中。请给你建议
这是我的XML文件数据
<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>
这是我的RML映射文件:
@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";
];
].
这是我的RML Mapping输出:
<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" .
例如,我想在RMl Mapping中迭代Employee节点和指示节点智能迭代。你提供你的注释,我必须创建我的XML文档节点,例如带有属性id的示例员工节点,指示节点等或者没有它可以做到。
答案 0 :(得分:1)
在当前的映射中,您没有使用id属性进行迭代。因为你的迭代器是
rml:iterator "/MainNode/Employees/Employee";
和
rml:iterator "/MainNode/Employees/Employee/Indications/Indication";
请注意缺少id属性。
您似乎只使用id属性进行主题IRI生成:
rr:subjectMap [
rr:template "http://www.example.com/Employee#{@id}";
rr:class test:Employee;
];
和
rr:subjectMap [
rr:template "http://www.example.com/Employee/Indication#{@id}";
rr:class test:Indication;
];
你可以,例如分别根据“EmpNo”和“IndicationNo”创建主题。但这取决于您的源数据,如果仅这些属性足以区别对待IRI生成。