簡體   English   中英

如何使用 RML 映射 xml 文件的子元素以創建 RDF?

[英]How to map children element of an xml file using RML to create an RDF?

我想使用 RML 映射創建 RDF。 XML 部分如下所示。 我為“屬性”和“FB”制作了三重地圖。 其中一個 FB 有一個子“屬性”,但在結果中,每個“FB”三元組都有“屬性”。 是否有任何解決方案可以使子“屬性”僅對一個“FB”元素具有唯一性?

  <Application ID="A4ABD8400116F035" Name="HotWater">
<SubAppNetwork>
  <FB ID="3D77F5AE3E23F522" Name="HW_setpoint" Type="CAThmiInput" x="360" y="880" Namespace="nxtControl.Tutorial" />
  <FB ID="38615A5C87F12AA3" Name="HW_pump1" Type="CATmotor" x="2760" y="260" Namespace="nxtControl.Tutorial" />
  <FB ID="3632883FE07D2F09" Name="HW_pump2" Type="CATmotor" x="2760" y="860" Namespace="nxtControl.Tutorial">
    <Parameter Name="AutoOn" Value="TRUE" />
  </FB>
  <FB ID="FB64994118EB2489" Name="HW_pidController" Type="CATpidController" x="1000" y="260" Namespace="nxtControl.Tutorial" />
  <FB ID="1C32C8BEDD84AAA7" Name="HW_sensor" Type="CATsensor" x="360" y="260" Namespace="nxtControl.Tutorial" />
  <FB ID="97DE5397424C589F" Name="HW_valve" Type="CATvalve" x="1620" y="260" Namespace="nxtControl.Tutorial" />
  <FB ID="3A265436F99A7B87" Name="HW_compare" Type="COMPARE_1990CFD1468AAE4A6" x="2220" y="260" Namespace="Main">
    <Attribute Name="Configuration.GenericFBType.InterfaceParams" Value="Runtime.Standard#CNT:=2;IN${CNT}:LREAL" />
    <Parameter Name="IN2" Value="0.0" />
  </FB>
  <EventConnections>
    <Connection Source="HW_sensor.CNF" Destination="HW_pidController.REQ" />
    <Connection Source="HW_setpoint.CNF" Destination="HW_pidController.REQ" dx1="110.7709">
      <AvoidsNodes>false</AvoidsNodes>
    </Connection>
    <Connection Source="HW_pidController.CNF" Destination="HW_valve.REQ" />
    <Connection Source="HW_valve.CNF" Destination="HW_compare.REQ" />
    <Connection Source="HW_compare.CNF" Destination="HW_pump1.REQ" />
  </EventConnections>
  <DataConnections>
    <Connection Source="HW_sensor.outValue" Destination="HW_pidController.pv" dx1="41.3125" />
    <Connection Source="HW_setpoint.value" Destination="HW_pidController.sp" dx1="170.7709">
      <AvoidsNodes>false</AvoidsNodes>
    </Connection>
    <Connection Source="HW_pidController.cp" Destination="HW_valve.AutoSP" />
    <Connection Source="HW_compare.GT" Destination="HW_pump1.AutoOn" dx1="70" />
    <Connection Source="HW_valve.cp" Destination="HW_compare.IN1" />
  </DataConnections>
</SubAppNetwork>

映射:

  <#AttributeMapping>
  a rr:TriplesMap;
  rml:logicalSource [
    rml:source "System.xml" ;
    rml:iterator "/System/Application/SubAppNetwork/FB/Attribute";
    rml:referenceFormulation ql:XPath
  ];

rr:subjectMap [
rr:template "http://sth/example#/SubAppNetwork/FB/Attribute-{@Name}";
rr:class iec61499:Attribute
];

rr:predicateObjectMap [
rr:predicate iec61499:hasName;
rr:objectMap [
  rml:reference "@Name"
];
];

rr:predicateObjectMap [
rr:predicate iec61499:hasValue;
rr:objectMap [
  rml:reference "@Value"
];
].


<#FBMapping>
a rr:TriplesMap;
rml:logicalSource [
rml:source "System.xml" ;
rml:iterator "/System/Application/SubAppNetwork/FB";
rml:referenceFormulation ql:XPath
];

rr:subjectMap [
rr:template "http://sth/example#/SubAppNetwork/FB-{../../../@Name}-{@ID}";
rr:class iec61499:FB
];

rr:predicateObjectMap [
rr:predicate iec61499:hasID;
rr:objectMap [
  rml:reference "@ID"
];
];

rr:predicateObjectMap [
rr:predicate iec61499:hasName;
rr:objectMap [
  rml:reference "@Name"
];
];

rr:predicateObjectMap [
rr:predicate iec61499:hasType;
rr:objectMap [
  rml:reference "@Type"
];
];

rr:predicateObjectMap [
rr:predicate iec61499:hasX;
rr:objectMap [
  rml:reference "@x"
];
];

rr:predicateObjectMap [
rr:predicate iec61499:hasY;
rr:objectMap [
  rml:reference "@y"
];
];

rr:predicateObjectMap [
rr:predicate iec61499:hasNamespace;
rr:objectMap [
  rml:reference "@Namespace"
];
];

rr:predicateObjectMap [
rr:predicate iec61499:hasAttribute;
rr:objectMap [
  rr:parentTriplesMap <#AttributeMapping>
];
].

您可以使用rr:joinCondition在 RML rr:joinCondition

rr:predicateObjectMap [
        rr:predicate iec61499:hasAttribute;
        rr:objectMap [
            rr:parentTriplesMap <#AttributeMapping>;
            rr:joinCondition [
                rr:child "@Name";
                rr:parent "../@Name"
            ];
        ];
    ].

rr:joinCondition將確保僅當rr:childrr:parent彼此相等時才進行連接。

我修改了您的數據,因為 XML 無效, </Application>結束標記丟失,您可以在下面找到新數據:

<Application ID="A4ABD8400116F035" Name="HotWater">
    <SubAppNetwork>
        <FB ID="3D77F5AE3E23F522" Name="HW_setpoint" Type="CAThmiInput" x="360" y="880" Namespace="nxtControl.Tutorial" />
        <FB ID="38615A5C87F12AA3" Name="HW_pump1" Type="CATmotor" x="2760" y="260" Namespace="nxtControl.Tutorial" />
        <FB ID="3632883FE07D2F09" Name="HW_pump2" Type="CATmotor" x="2760" y="860" Namespace="nxtControl.Tutorial">
            <Parameter Name="AutoOn" Value="TRUE" />
        </FB>
        <FB ID="FB64994118EB2489" Name="HW_pidController" Type="CATpidController" x="1000" y="260" Namespace="nxtControl.Tutorial" />
        <FB ID="1C32C8BEDD84AAA7" Name="HW_sensor" Type="CATsensor" x="360" y="260" Namespace="nxtControl.Tutorial" />
        <FB ID="97DE5397424C589F" Name="HW_valve" Type="CATvalve" x="1620" y="260" Namespace="nxtControl.Tutorial" />
        <FB ID="3A265436F99A7B87" Name="HW_compare" Type="COMPARE_1990CFD1468AAE4A6" x="2220" y="260" Namespace="Main">
            <Attribute Name="Configuration.GenericFBType.InterfaceParams" Value="Runtime.Standard#CNT:=2;IN${CNT}:LREAL" />
            <Parameter Name="IN2" Value="0.0" />
        </FB>
        <EventConnections>
            <Connection Source="HW_sensor.CNF" Destination="HW_pidController.REQ" />
            <Connection Source="HW_setpoint.CNF" Destination="HW_pidController.REQ" dx1="110.7709">
                <AvoidsNodes>false</AvoidsNodes>
            </Connection>
            <Connection Source="HW_pidController.CNF" Destination="HW_valve.REQ" />
            <Connection Source="HW_valve.CNF" Destination="HW_compare.REQ" />
            <Connection Source="HW_compare.CNF" Destination="HW_pump1.REQ" />
        </EventConnections>
        <DataConnections>
            <Connection Source="HW_sensor.outValue" Destination="HW_pidController.pv" dx1="41.3125" />
            <Connection Source="HW_setpoint.value" Destination="HW_pidController.sp" dx1="170.7709">
                <AvoidsNodes>false</AvoidsNodes>
            </Connection>
            <Connection Source="HW_pidController.cp" Destination="HW_valve.AutoSP" />
            <Connection Source="HW_compare.GT" Destination="HW_pump1.AutoOn" dx1="70" />
            <Connection Source="HW_valve.cp" Destination="HW_compare.IN1" />
        </DataConnections>
    </SubAppNetwork>
</Application>

我將您的示例減少到最低限度,並添加了rr:joinCondition以僅在FBName屬性與父級及其子級匹配時才執行連接:

@base <http://example.org/> .
@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 rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix schema: <http://schema.org/> .
@prefix dbo: <http://dbpedia.org/ontology/> .
@prefix iec61499: <http://example.org/iec61499/> . 

<#AttributeMapping>
    a rr:TriplesMap;
    rml:logicalSource [
        rml:source "System.xml";
        rml:referenceFormulation ql:XPath;
        rml:iterator "/Application/SubAppNetwork/FB/Attribute"
    ];

    rr:subjectMap [
        rr:template "http://sth/example#/SubAppNetwork/FB/Attribute-{@Name}";
        rr:class iec61499:Attribute
    ];

    rr:predicateObjectMap [
        rr:predicate iec61499:hasName;
        rr:objectMap [
            rml:reference "@Name"
        ];
    ].

<#FBMapping>
    a rr:TriplesMap;
    rml:logicalSource [
        rml:source "System.xml" ;
        rml:iterator "/Application/SubAppNetwork/FB";
        rml:referenceFormulation ql:XPath
    ];

    rr:subjectMap [
        rr:template "http://sth/example#/SubAppNetwork/FB-{../../@Name}-{@ID}";
        rr:class iec61499:FB
    ];

    rr:predicateObjectMap [
        rr:predicate iec61499:hasName;
        rr:objectMap [
            rml:reference "@Name"
        ];
    ];

    rr:predicateObjectMap [
        rr:predicate iec61499:hasAttribute;
        rr:objectMap [
            rr:parentTriplesMap <#AttributeMapping>;
            rr:joinCondition [
                rr:child "@Name";
                rr:parent "../@Name"
            ];
        ];
    ].

如果您向 RML 處理器提供這些映射和數據,您將獲得以下輸出:

<http://sth/example#/SubAppNetwork/FB/Attribute-Configuration.GenericFBType.InterfaceParams> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/iec61499/Attribute>.
<http://sth/example#/SubAppNetwork/FB/Attribute-Configuration.GenericFBType.InterfaceParams> <http://example.org/iec61499/hasName> "Configuration.GenericFBType.InterfaceParams".
<http://sth/example#/SubAppNetwork/FB-HotWater-3D77F5AE3E23F522> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/iec61499/FB>.
<http://sth/example#/SubAppNetwork/FB-HotWater-3D77F5AE3E23F522> <http://example.org/iec61499/hasName> "HW_setpoint".
<http://sth/example#/SubAppNetwork/FB-HotWater-38615A5C87F12AA3> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/iec61499/FB>.
<http://sth/example#/SubAppNetwork/FB-HotWater-38615A5C87F12AA3> <http://example.org/iec61499/hasName> "HW_pump1".
<http://sth/example#/SubAppNetwork/FB-HotWater-3632883FE07D2F09> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/iec61499/FB>.
<http://sth/example#/SubAppNetwork/FB-HotWater-3632883FE07D2F09> <http://example.org/iec61499/hasName> "HW_pump2".
<http://sth/example#/SubAppNetwork/FB-HotWater-FB64994118EB2489> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/iec61499/FB>.
<http://sth/example#/SubAppNetwork/FB-HotWater-FB64994118EB2489> <http://example.org/iec61499/hasName> "HW_pidController".
<http://sth/example#/SubAppNetwork/FB-HotWater-1C32C8BEDD84AAA7> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/iec61499/FB>.
<http://sth/example#/SubAppNetwork/FB-HotWater-1C32C8BEDD84AAA7> <http://example.org/iec61499/hasName> "HW_sensor".
<http://sth/example#/SubAppNetwork/FB-HotWater-97DE5397424C589F> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/iec61499/FB>.
<http://sth/example#/SubAppNetwork/FB-HotWater-97DE5397424C589F> <http://example.org/iec61499/hasName> "HW_valve".
<http://sth/example#/SubAppNetwork/FB-HotWater-3A265436F99A7B87> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/iec61499/FB>.
<http://sth/example#/SubAppNetwork/FB-HotWater-3A265436F99A7B87> <http://example.org/iec61499/hasName> "HW_compare".
<http://sth/example#/SubAppNetwork/FB-HotWater-3A265436F99A7B87> <http://example.org/iec61499/hasAttribute> <http://sth/example#/SubAppNetwork/FB/Attribute-Configuration.GenericFBType.InterfaceParams>.

注意:我為 RML 及其技術做出了貢獻。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM