通过使用RML-Mapper库将xml文件转换为RDF的最佳mapping.ttl文件是什么?



我正在使用RML-Mapper库将xml文件转换为rdf文件。 对于以下 xml 文件,目录.xml,我在编写最佳 mapping.ttl 时遇到了麻烦。我的问题是,该特定 xml 的最佳 mapping.ttl 文件是什么?我在下面提供目录.xml和catalog_mapping.ttl文件...

目录.xml文件

<catalog>
<product description="Cardigan Sweater" product_image="cardigan.jpg">
<catalog_item gender="Men's">
<item_number>QWZ5671</item_number>
<price>39.95</price>
<size description="Medium">
<color_swatch image="red_cardigan.jpg">Red</color_swatch>
<color_swatch image="burgundy_cardigan.jpg">Burgundy</color_swatch>
</size>
<size description="Large">
<color_swatch image="red_cardigan.jpg">Red</color_swatch>
<color_swatch image="burgundy_cardigan.jpg">Burgundy</color_swatch>
</size>
</catalog_item>
<catalog_item gender="Women's">
<item_number>RRX9856</item_number>
<price>42.50</price>
<size description="Small">
<color_swatch image="red_cardigan.jpg">Red</color_swatch>
<color_swatch image="navy_cardigan.jpg">Navy</color_swatch>
<color_swatch image="burgundy_cardigan.jpg">Burgundy</color_swatch>
</size>
<size description="Medium">
<color_swatch image="red_cardigan.jpg">Red</color_swatch>
<color_swatch image="navy_cardigan.jpg">Navy</color_swatch>
<color_swatch image="burgundy_cardigan.jpg">Burgundy</color_swatch>
<color_swatch image="black_cardigan.jpg">Black</color_swatch>
</size>
<size description="Large">
<color_swatch image="navy_cardigan.jpg">Navy</color_swatch>
<color_swatch image="black_cardigan.jpg">Black</color_swatch>
</size>
<size description="Extra Large">
<color_swatch image="burgundy_cardigan.jpg">Burgundy</color_swatch>
<color_swatch image="black_cardigan.jpg">Black</color_swatch>
</size>
</catalog_item>
</product>
<product description="Turkish Jeans" product_image="cardigan.jpg">
<catalog_item gender="Men's">
<item_number>FDE456</item_number>
<price>22</price>
<size description="Small">
<color_swatch image="red_cardigan.jpg">Blue</color_swatch>
<color_swatch image="burgundy_cardigan.jpg">Black</color_swatch>
</size>
<size description="Extra Small">
<color_swatch image="red_cardigan.jpg">White</color_swatch>
<color_swatch image="burgundy_cardigan.jpg">Transparent</color_swatch>
</size>
</catalog_item>
<catalog_item gender="Women's">
<item_number>LKO478</item_number>
<price>35</price>
<size description="Small">
<color_swatch image="red_cardigan.jpg">Red</color_swatch>
<color_swatch image="navy_cardigan.jpg">Blue</color_swatch>
<color_swatch image="burgundy_cardigan.jpg">Orange</color_swatch>
</size>
<size description="Large">
<color_swatch image="navy_cardigan.jpg">Navy</color_swatch>
<color_swatch image="black_cardigan.jpg">Black</color_swatch>
</size>
<size description="Extra Large">
<color_swatch image="burgundy_cardigan.jpg">Pink</color_swatch>
<color_swatch image="black_cardigan.jpg">Yellow</color_swatch>
</size>
</catalog_item>
</product>
</catalog>

catalog_mapping.ttl

@prefix rr: <http://www.w3.org/ns/r2rml#>.
@prefix rml: <http://semweb.mmlab.be/ns/rml#>.
@prefix ex: <http://example.com/ns#>.
@prefix ql: <http://semweb.mmlab.be/ns/ql#>.
@prefix transit: <http://vocab.org/transit/terms/>.
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.

rr:ProductMapping
rml:logicalSource [
rml:source "Catalogs.xml";
rml:referenceFormulation ql:XPath;
rml:iterator "/catalog/product"
];
rr:subjectMap [
rr:template "http://ex.com/{@description}";
rr:class ex:product
];
rr:predicateObjectMap [
rr:predicate ex:catalog_item;
rr:objectMap [
rr:parentTriplesMap rr:CatalogItemMapping;
rr:joinCondition [
rr:child "/catalog/product/catalog_item";
rr:parent "/catalog/product"
]
]
].
rr:CatalogItemMapping
rml:logicalSource [
rml:source "Catalogs.xml";
rml:referenceFormulation ql:XPath;
rml:iterator "/catalog/product/catalog_item"
];
rr:subjectMap [
rr:template "http://ex.com/{@gender}/id={item_number}";
];
rr:predicateObjectMap [
rr:predicate ex:item_number;
rr:objectMap [
rml:reference "item_number"
]
];
rr:predicateObjectMap [
rr:predicate ex:price;
rr:objectMap [
rml:reference "price"
]
];
rr:predicateObjectMap [
rr:predicate ex:size_and_color;
rr:objectMap [
rr:template "{size/@description}_{size/color_swatch}"
]
].

这是我目前的结果...


<http://ex.com/Cardigan%20Sweater> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.com/ns#product> null
<http://ex.com/Turkish%20Jeans> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.com/ns#product> null
<http://ex.com/Men%27s/id=QWZ5671> <http://example.com/ns#item_number> "QWZ5671" null
<http://ex.com/Men%27s/id=QWZ5671> <http://example.com/ns#price> "39.95" null
<http://ex.com/Men%27s/id=QWZ5671> <http://example.com/ns#size_and_color> <Medium_Red> null
<http://ex.com/Men%27s/id=QWZ5671> <http://example.com/ns#size_and_color> <Large_Red> null
<http://ex.com/Men%27s/id=QWZ5671> <http://example.com/ns#size_and_color> <Medium_Burgundy> null
<http://ex.com/Men%27s/id=QWZ5671> <http://example.com/ns#size_and_color> <Large_Burgundy> null
<http://ex.com/Women%27s/id=RRX9856> <http://example.com/ns#item_number> "RRX9856" null
<http://ex.com/Women%27s/id=RRX9856> <http://example.com/ns#price> "42.50" null
<http://ex.com/Women%27s/id=RRX9856> <http://example.com/ns#size_and_color> <Small_Red> null
<http://ex.com/Women%27s/id=RRX9856> <http://example.com/ns#size_and_color> <Medium_Red> null
<http://ex.com/Women%27s/id=RRX9856> <http://example.com/ns#size_and_color> <Large_Red> null
<http://ex.com/Women%27s/id=RRX9856> <http://example.com/ns#size_and_color> <Extra%20Large_Red> null
<http://ex.com/Women%27s/id=RRX9856> <http://example.com/ns#size_and_color> <Small_Navy> null
<http://ex.com/Women%27s/id=RRX9856> <http://example.com/ns#size_and_color> <Medium_Navy> null
<http://ex.com/Women%27s/id=RRX9856> <http://example.com/ns#size_and_color> <Large_Navy> null
<http://ex.com/Women%27s/id=RRX9856> <http://example.com/ns#size_and_color> <Extra%20Large_Navy> null
<http://ex.com/Women%27s/id=RRX9856> <http://example.com/ns#size_and_color> <Small_Burgundy> null
<http://ex.com/Women%27s/id=RRX9856> <http://example.com/ns#size_and_color> <Medium_Burgundy> null
<http://ex.com/Women%27s/id=RRX9856> <http://example.com/ns#size_and_color> <Large_Burgundy> null
<http://ex.com/Women%27s/id=RRX9856> <http://example.com/ns#size_and_color> <Extra%20Large_Burgundy> null
<http://ex.com/Women%27s/id=RRX9856> <http://example.com/ns#size_and_color> <Small_Black> null
<http://ex.com/Women%27s/id=RRX9856> <http://example.com/ns#size_and_color> <Medium_Black> null
<http://ex.com/Women%27s/id=RRX9856> <http://example.com/ns#size_and_color> <Large_Black> null
<http://ex.com/Women%27s/id=RRX9856> <http://example.com/ns#size_and_color> <Extra%20Large_Black> null
<http://ex.com/Men%27s/id=FDE456> <http://example.com/ns#item_number> "FDE456" null
<http://ex.com/Men%27s/id=FDE456> <http://example.com/ns#price> "22" null
<http://ex.com/Men%27s/id=FDE456> <http://example.com/ns#size_and_color> <Small_Blue> null
<http://ex.com/Men%27s/id=FDE456> <http://example.com/ns#size_and_color> <Extra%20Small_Blue> null
<http://ex.com/Men%27s/id=FDE456> <http://example.com/ns#size_and_color> <Small_Black> null
<http://ex.com/Men%27s/id=FDE456> <http://example.com/ns#size_and_color> <Extra%20Small_Black> null
<http://ex.com/Men%27s/id=FDE456> <http://example.com/ns#size_and_color> <Small_White> null
<http://ex.com/Men%27s/id=FDE456> <http://example.com/ns#size_and_color> <Extra%20Small_White> null
<http://ex.com/Men%27s/id=FDE456> <http://example.com/ns#size_and_color> <Small_Transparent> null
<http://ex.com/Men%27s/id=FDE456> <http://example.com/ns#size_and_color> <Extra%20Small_Transparent> null
<http://ex.com/Women%27s/id=LKO478> <http://example.com/ns#item_number> "LKO478" null
<http://ex.com/Women%27s/id=LKO478> <http://example.com/ns#price> "35" null
<http://ex.com/Women%27s/id=LKO478> <http://example.com/ns#size_and_color> <Small_Red> null
<http://ex.com/Women%27s/id=LKO478> <http://example.com/ns#size_and_color> <Large_Red> null
<http://ex.com/Women%27s/id=LKO478> <http://example.com/ns#size_and_color> <Extra%20Large_Red> null
<http://ex.com/Women%27s/id=LKO478> <http://example.com/ns#size_and_color> <Small_Blue> null
<http://ex.com/Women%27s/id=LKO478> <http://example.com/ns#size_and_color> <Large_Blue> null
<http://ex.com/Women%27s/id=LKO478> <http://example.com/ns#size_and_color> <Extra%20Large_Blue> null
<http://ex.com/Women%27s/id=LKO478> <http://example.com/ns#size_and_color> <Small_Orange> null
<http://ex.com/Women%27s/id=LKO478> <http://example.com/ns#size_and_color> <Large_Orange> null
<http://ex.com/Women%27s/id=LKO478> <http://example.com/ns#size_and_color> <Extra%20Large_Orange> null
<http://ex.com/Women%27s/id=LKO478> <http://example.com/ns#size_and_color> <Small_Navy> null
<http://ex.com/Women%27s/id=LKO478> <http://example.com/ns#size_and_color> <Large_Navy> null
<http://ex.com/Women%27s/id=LKO478> <http://example.com/ns#size_and_color> <Extra%20Large_Navy> null
<http://ex.com/Women%27s/id=LKO478> <http://example.com/ns#size_and_color> <Small_Black> null
<http://ex.com/Women%27s/id=LKO478> <http://example.com/ns#size_and_color> <Large_Black> null
<http://ex.com/Women%27s/id=LKO478> <http://example.com/ns#size_and_color> <Extra%20Large_Black> null
<http://ex.com/Women%27s/id=LKO478> <http://example.com/ns#size_and_color> <Small_Pink> null
<http://ex.com/Women%27s/id=LKO478> <http://example.com/ns#size_and_color> <Large_Pink> null
<http://ex.com/Women%27s/id=LKO478> <http://example.com/ns#size_and_color> <Extra%20Large_Pink> null
<http://ex.com/Women%27s/id=LKO478> <http://example.com/ns#size_and_color> <Small_Yellow> null
<http://ex.com/Women%27s/id=LKO478> <http://example.com/ns#size_and_color> <Large_Yellow> null
<http://ex.com/Women%27s/id=LKO478> <http://example.com/ns#size_and_color> <Extra%20Large_Yellow> null

这个结果是好的还是有更好的 catalog_mapping.ttl 可以得出更好的结果?

映射规则已经相当不错了,我做了以下改进:

  1. rr:<name of TriplesMap>不应用作您自己的前缀 三重地图。rr前缀由 R2RML 规范。 为了解决这个问题,我添加了@base http://example.org并删除了rr前缀 三重地图:
@base <http://example.org/> .
<#ProductMapping>
a rr:TriplesMap;
  1. >我为每个 RML 处理器的 TriplesMap 添加了a rr:TriplesMap以查看 RDF实际上是在描述一个 三重地图:
<#ProductMapping>
a rr:TriplesMap;
  1. 为了更容易查询RDF,我将ex:size_and_color拆分 进入不同的三重地图。这样,颜色和大小就会得到自己的 IRI,从而 只能用于查询产品的尺寸或颜色。 另请注意,我使用了rml:reference而不是rr:template因为我们只 需要值,而不是创建字符串模板。rml:reference您可以在 RML 规范。
rr:predicateObjectMap [
rr:predicate ex:color;
rr:objectMap [
rml:reference "size/color_swatch"
]
];
rr:predicateObjectMap [
rr:predicate ex:size;
rr:objectMap [
rml:reference "size/@description"
]
].

所有映射规则

@base <http://example.org/> .
@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 transit: <http://vocab.org/transit/terms/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix ex: <http://example.org/ns#> .
<#ProductMapping>
a rr:TriplesMap;
rml:logicalSource [
rml:source "Catalogs.xml";
rml:referenceFormulation ql:XPath;
rml:iterator "/catalog/product";
];
rr:subjectMap [
rr:template "http://example.org/product/{@description}";
rr:class ex:product;
];
rr:predicateObjectMap [
rr:predicate ex:catalogItem;
rr:objectMap [
rr:parentTriplesMap <#CatalogItemMapping>;
rr:joinCondition [
rr:child "@description";
rr:parent "../@description";
];
];
].
<#CatalogItemMapping>
a rr:TriplesMap;
rml:logicalSource [
rml:source "Catalogs.xml";
rml:referenceFormulation ql:XPath;
rml:iterator "/catalog/product/catalog_item";
];
rr:subjectMap [
rr:template "http://example.org/item?id={item_number}";
];
rr:predicateObjectMap [
rr:predicate ex:item_number;
rr:objectMap [
rml:reference "item_number";
];
];
rr:predicateObjectMap [
rr:predicate ex:price;
rr:objectMap [
rml:reference "price";
];
];
rr:predicateObjectMap [
rr:predicate ex:size;
rr:objectMap [
rr:parentTriplesMap <#SizeMapping>;
rr:joinCondition [
rr:child "@gender";
rr:parent "../@gender";
];
rr:joinCondition [
rr:child "item_number";
rr:parent "../item_number";
];
];
].
<#SizeMapping>
a rr:TriplesMap;
rml:logicalSource [
rml:source "Catalogs.xml";
rml:referenceFormulation ql:XPath;
rml:iterator "/catalog/product/catalog_item/size";
];
rr:subjectMap [
rr:template "http://example.org/item?id={../item_number}&size={@description}";
];
rr:predicateObjectMap [
rr:predicate ex:color;
rr:objectMap [
rr:parentTriplesMap <#ColorMapping>;
rr:joinCondition [
rr:child "@description";
rr:parent "../@description";
];
rr:joinCondition [
rr:child "../item_number";
rr:parent "../../item_number";
]
];
].
<#ColorMapping>
a rr:TriplesMap;
rml:logicalSource [
rml:source "Catalogs.xml";
rml:referenceFormulation ql:XPath;
rml:iterator "//color_swatch";
];
rr:subjectMap [
rr:template "http://example.org/color/{.}";
].

输出

<http://example.org/product/Cardigan%20Sweater> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/ns#product>.
<http://example.org/product/Cardigan%20Sweater> <http://example.org/ns#catalogItem> <http://example.org/item?id=QWZ5671>.
<http://example.org/product/Cardigan%20Sweater> <http://example.org/ns#catalogItem> <http://example.org/item?id=RRX9856>.
<http://example.org/product/Turkish%20Jeans> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/ns#product>.
<http://example.org/product/Turkish%20Jeans> <http://example.org/ns#catalogItem> <http://example.org/item?id=FDE456>.
<http://example.org/product/Turkish%20Jeans> <http://example.org/ns#catalogItem> <http://example.org/item?id=LKO478>.
<http://example.org/item?id=QWZ5671&size=Medium> <http://example.org/ns#color> <http://example.org/color/Red>.
<http://example.org/item?id=QWZ5671&size=Medium> <http://example.org/ns#color> <http://example.org/color/Burgundy>.
<http://example.org/item?id=QWZ5671&size=Large> <http://example.org/ns#color> <http://example.org/color/Red>.
<http://example.org/item?id=QWZ5671&size=Large> <http://example.org/ns#color> <http://example.org/color/Burgundy>.
<http://example.org/item?id=RRX9856&size=Small> <http://example.org/ns#color> <http://example.org/color/Red>.
<http://example.org/item?id=RRX9856&size=Small> <http://example.org/ns#color> <http://example.org/color/Navy>.
<http://example.org/item?id=RRX9856&size=Small> <http://example.org/ns#color> <http://example.org/color/Burgundy>.
<http://example.org/item?id=RRX9856&size=Medium> <http://example.org/ns#color> <http://example.org/color/Red>.
<http://example.org/item?id=RRX9856&size=Medium> <http://example.org/ns#color> <http://example.org/color/Navy>.
<http://example.org/item?id=RRX9856&size=Medium> <http://example.org/ns#color> <http://example.org/color/Burgundy>.
<http://example.org/item?id=RRX9856&size=Medium> <http://example.org/ns#color> <http://example.org/color/Black>.
<http://example.org/item?id=RRX9856&size=Large> <http://example.org/ns#color> <http://example.org/color/Navy>.
<http://example.org/item?id=RRX9856&size=Large> <http://example.org/ns#color> <http://example.org/color/Black>.
<http://example.org/item?id=RRX9856&size=Extra%20Large> <http://example.org/ns#color> <http://example.org/color/Burgundy>.
<http://example.org/item?id=RRX9856&size=Extra%20Large> <http://example.org/ns#color> <http://example.org/color/Black>.
<http://example.org/item?id=FDE456&size=Small> <http://example.org/ns#color> <http://example.org/color/Blue>.
<http://example.org/item?id=FDE456&size=Small> <http://example.org/ns#color> <http://example.org/color/Black>.
<http://example.org/item?id=FDE456&size=Extra%20Small> <http://example.org/ns#color> <http://example.org/color/White>.
<http://example.org/item?id=FDE456&size=Extra%20Small> <http://example.org/ns#color> <http://example.org/color/Transparent>.
<http://example.org/item?id=LKO478&size=Small> <http://example.org/ns#color> <http://example.org/color/Red>.
<http://example.org/item?id=LKO478&size=Small> <http://example.org/ns#color> <http://example.org/color/Blue>.
<http://example.org/item?id=LKO478&size=Small> <http://example.org/ns#color> <http://example.org/color/Orange>.
<http://example.org/item?id=LKO478&size=Large> <http://example.org/ns#color> <http://example.org/color/Navy>.
<http://example.org/item?id=LKO478&size=Large> <http://example.org/ns#color> <http://example.org/color/Black>.
<http://example.org/item?id=LKO478&size=Extra%20Large> <http://example.org/ns#color> <http://example.org/color/Pink>.
<http://example.org/item?id=LKO478&size=Extra%20Large> <http://example.org/ns#color> <http://example.org/color/Yellow>.
<http://example.org/item?id=QWZ5671> <http://example.org/ns#price> "39.95".
<http://example.org/item?id=QWZ5671> <http://example.org/ns#size> <http://example.org/item?id=QWZ5671&size=Medium>.
<http://example.org/item?id=QWZ5671> <http://example.org/ns#size> <http://example.org/item?id=QWZ5671&size=Large>.
<http://example.org/item?id=QWZ5671> <http://example.org/ns#item_number> "QWZ5671".
<http://example.org/item?id=RRX9856> <http://example.org/ns#price> "42.50".
<http://example.org/item?id=RRX9856> <http://example.org/ns#size> <http://example.org/item?id=RRX9856&size=Small>.
<http://example.org/item?id=RRX9856> <http://example.org/ns#size> <http://example.org/item?id=RRX9856&size=Medium>.
<http://example.org/item?id=RRX9856> <http://example.org/ns#size> <http://example.org/item?id=RRX9856&size=Large>.
<http://example.org/item?id=RRX9856> <http://example.org/ns#size> <http://example.org/item?id=RRX9856&size=Extra%20Large>.
<http://example.org/item?id=RRX9856> <http://example.org/ns#item_number> "RRX9856".
<http://example.org/item?id=FDE456> <http://example.org/ns#price> "22".
<http://example.org/item?id=FDE456> <http://example.org/ns#size> <http://example.org/item?id=FDE456&size=Small>.
<http://example.org/item?id=FDE456> <http://example.org/ns#size> <http://example.org/item?id=FDE456&size=Extra%20Small>.
<http://example.org/item?id=FDE456> <http://example.org/ns#item_number> "FDE456".
<http://example.org/item?id=LKO478> <http://example.org/ns#price> "35".
<http://example.org/item?id=LKO478> <http://example.org/ns#size> <http://example.org/item?id=LKO478&size=Small>.
<http://example.org/item?id=LKO478> <http://example.org/ns#size> <http://example.org/item?id=LKO478&size=Large>.
<http://example.org/item?id=LKO478> <http://example.org/ns#size> <http://example.org/item?id=LKO478&size=Extra%20Large>.
<http://example.org/item?id=LKO478> <http://example.org/ns#item_number> "LKO478".

注意:我为 RML 及其技术做出贡献。

最新更新