我正在尝试将 XML 源映射到 RDF,并且想知道如何在每次跟踪父属性的同时进行递归遍历。在所示示例中,我希望Person
提取所有节点,并将name
每个父节点的 附加到当前节点。考虑所有父名称是必要的,因为节点名称可能不是唯一的。(grandChild1
在例子中看两次)
请注意,我事先不知道嵌套可以进行多少级,因此为每个级别添加一个 TriplesMap 不是一个可行的选择。
以下是一个简化的 XML 示例、到目前为止我创建的 RML 映射、使用RMLMapper生成的当前 RDF 输出,以及我期望的 RDF 输出。
数据<Root>
<Person>
<name>parent1</name>
<Children>
<Person>
<name>child1</name>
<Person>
<name>grandchild1</name>
<Children>
<Person>
<name>greatgrandchild1</name>
</Person>
</Children>
</Person>
</Person>
<Person>
<name>child2</name>
<Person>
<name>grandchild1</name>
</Person>
</Person>
</Children>
</Person>
</Root>
映射
@prefix rml: <http://semweb.mmlab.be/ns/rml#> .
@prefix rr: <http://www.w3.org/ns/r2rml#> .
@prefix ql: <http://semweb.mmlab.be/ns/ql#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix testont: <http://www.example.com/ontology/> .
@prefix : <http://www.example.com/rules/> .
@base <http://www.example.com/instance/> .
:TriplesMapPerson a rr:TriplesMap;
rml:logicalSource [
rml:source "recursion_data.xml";
rml:referenceFormulation ql:XPath;
rml:iterator "//Root/Person"
].
:TriplesMapPerson rr:subjectMap [
rr:template "{name}"
].
:TriplesMapPerson rr:predicateObjectMap [
rr:predicate rdf:type;
rr:object testont:Person
].
:TriplesMapChild a rr:TriplesMap;
rml:logicalSource [
rml:source "recursion_data.xml";
rml:referenceFormulation ql:XPath;
rml:iterator "//Root/Person/Children/Person"
].
:TriplesMapChild rr:subjectMap [
rr:template "{name}_{../../name}"
].
:TriplesMapChild rr:predicateObjectMap [
rr:predicate rdf:type;
rr:object testont:Person
].
当前RDF
<http://www.example.com/instance/parent1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.example.com/ontology/Person>.
<http://www.example.com/instance/child1_parent1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.example.com/ontology/Person>.
<http://www.example.com/instance/child2_parent1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.example.com/ontology/Person>.
预期的 RDF
<http://www.example.com/instance/parent1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.example.com/ontology/Person>.
<http://www.example.com/instance/child1_parent1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.example.com/ontology/Person>.
<http://www.example.com/instance/grandchild1_child1_parent1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.example.com/ontology/Person>.
<http://www.example.com/instance/greatgrandchild1_grandchild1_child1_parent1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.example.com/ontology/Person>.
<http://www.example.com/instance/child2_parent1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.example.com/ontology/Person>.
<http://www.example.com/instance/grandchild1_child2_parent1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.example.com/ontology/Person>.
感谢您为解决此问题提供的任何帮助。提前致谢!