gpt4 book ai didi

java - 如何为没有 id 的 XML 节点迭代 RML 映射语言?

转载 作者:行者123 更新时间:2023-11-30 06:21:02 25 4
gpt4 key购买 nike

我想使用不带 id 属性的迭代来迭代 XML 节点,如我的代码中所示,这可能吗?我是 RML 映射语言的初学者。我正在使用 RML 映射工具,其链接在这里 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 映射输出:

<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 映射中迭代员工节点明智和指示节点明智迭代。您可以提供您的评论吗?我必须使我的 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”和“InductionNo”创建主题。但这取决于您的源数据,这些属性是否足以用于 IRI 生成。

关于java - 如何为没有 id 的 XML 节点迭代 RML 映射语言?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48145682/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com