如何为没有 id 的 XML 节点迭代 RML 映射语言?
How to itearate RML Mapping language for XML node not having id?
我想用不带 id 属性的迭代来迭代 XML 节点,就像在我的代码中那样可能吗?。
我是 RML 映射语言的初学者。
我正在使用 RML 映射工具,它的 link 在这里 https://github.com/RMLio/RML-Mapper
我已经成功地使用 "ID" 进行迭代,但我不想使用 id 进行迭代,因为我的 XML 数据不包含 id,所以是否可以在没有 ID 属性的情况下进行迭代,或者在 RML Mapping 中必须使用 id 进行迭代。请给你建议
这是我的 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 映射输出:
<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.can 你提供你的评论我必须使我的 XML 文档节点像示例员工节点一样,指示节点等具有属性 id 或没有它也是可能的。
在您当前的映射中,您没有使用 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 生成,则取决于您的源数据。
我想用不带 id 属性的迭代来迭代 XML 节点,就像在我的代码中那样可能吗?。 我是 RML 映射语言的初学者。 我正在使用 RML 映射工具,它的 link 在这里 https://github.com/RMLio/RML-Mapper
我已经成功地使用 "ID" 进行迭代,但我不想使用 id 进行迭代,因为我的 XML 数据不包含 id,所以是否可以在没有 ID 属性的情况下进行迭代,或者在 RML Mapping 中必须使用 id 进行迭代。请给你建议
这是我的 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 映射输出:
<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.can 你提供你的评论我必须使我的 XML 文档节点像示例员工节点一样,指示节点等具有属性 id 或没有它也是可能的。
在您当前的映射中,您没有使用 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 生成,则取决于您的源数据。