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

What is the best mapping.ttl file for converting xml file into RDF by using RML-Mapper library?

我正在使用 RML-Mapper library 将 xml 文件转换为 rdf 文件。 对于下面的xml文件,catalogs.xml,我写出最好的mapping.ttl有困难。我的问题是,对于那个特定的 xml,最好的 mapping.ttl 文件是什么?我在下面提供 catalogs.xml 和 catalog_mapping.ttl 文件...

Catalogs.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>

目录_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 specification。 为了解决这个问题,我添加了 @base http://example.org 并删除了 rr 前缀 三元组地图:
@base <http://example.org/> .

<#ProductMapping>
    a rr:TriplesMap;
  1. 我为 RML 处理器的每个 TriplesMap 添加了 a rr:TriplesMap 以查看 RDF 实际上是在描述一个 TriplesMap:
<#ProductMapping>
    a rr:TriplesMap;
  1. 为了方便查询 RDF,我把 ex:size_and_color 分开了 进入不同的TripleMaps。这样,颜色和尺寸就有了自己的 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 及其技术做出贡献。