R2RML 与来自另一个 table 的值的映射
R2RML mapping with values from another table
我想使用 R2RML 和 Virtuoso 从 MySql 源映射一些 table。
我有一个 table 和 "Things",我希望它们具有不是 URI 的谓词,而是来自通过 thingID 连接的 table "Values" 的名称列。
我可以通过 "Thing" 的 ID 将 table "Values" 映射到 "Values" 的 thingId - 但是通过此映射,我只能获得相应 [=25= 的 URI ] 入口。我想要的是存储在 "Value".
列中的字符串
预期的结果三元组应该是例如:
<http://localhost:8890/ex/things/1> rdf:type <http://localhost:8890/ex/types/vmware> ;
ex:hasValue "Name from the table Values" .
Example of Things table:
ID typeId
1 3
Example of the Types table:
ID Name
3 vmware
值示例 table:
ID thingId Value
1 1 VMware Virtual Platform
这是我目前的映射:
<#TriplesMapThings> a rr:TriplesMap; rr:logicalTable [ rr:tableSchema "exdb" ; rr:tableOwner "ex" ; rr:tableName "Things" ];
rr:subjectMap [ rr:termType rr:IRI ; rr:template "http://localhost:8890/ex/things/{id}"; rr:class ex:Things; rr:graph <http://localhost:8890/ex_test#> ];
rr:predicateObjectMap [ rr:predicateMap [ rr:constant ex:id ] ; rr:objectMap [ rr:column "id" ]; ] ;
rr:predicateObjectMap [ rr:predicateMap [ rr:constant ex:typeid ] ; rr:objectMap [ rr:column "typeId" ]; ] ;
rr:predicateObjectMap [ rr:predicateMap [ rr:constant rdf:type ] ; rr:objectMap [ rr:parentTriplesMap <#TriplesMapTypes>; rr:joinCondition [rr:child "typeId"; rr:parent "id";]; ];] ;
rr:predicateObjectMap [ rr:predicateMap [ rr:constant ex:hasValue ] ; rr:objectMap [ rr:parentTriplesMap <#TriplesMapValues>; rr:joinCondition [rr:child "id"; rr:parent "thingId";]; ];] .
<#TriplesMapTypes> a rr:TriplesMap; rr:logicalTable [ rr:tableSchema "exdb" ; rr:tableOwner "ex" ; rr:tableName "Types" ];
rr:subjectMap [ rr:termType rr:IRI ; rr:template "http://localhost:8890/ex/types/{nameUri}"; rr:class owl:Class; rr:graph <http://localhost:8890/ex_test#> ];
rr:predicateObjectMap [ rr:predicateMap [ rr:constant ex:id ] ; rr:objectMap [ rr:column "id" ]; ] ;
rr:predicateObjectMap [ rr:predicateMap [ rr:constant ex:name ] ; rr:objectMap [ rr:column "name" ]; ] .
<#TriplesMapValues> a rr:TriplesMap; rr:logicalTable [ rr:tableSchema "exdb" ; rr:tableOwner "ex" ; rr:tableName "Values" ];
rr:subjectMap [ rr:termType rr:IRI ; rr:template "http://localhost:8890/ex/values/{id}"; rr:class ex:Values; rr:graph <http://localhost:8890/ex_test#> ];
rr:predicateObjectMap [ rr:predicateMap [ rr:constant rdf:type ] ; rr:objectMap [ rr:parentTriplesMap <#TriplesMapAttributes>; rr:joinCondition [rr:child "attributeId"; rr:parent "id";]; ];] ;
rr:predicateObjectMap [ rr:predicateMap [ rr:constant ex:hasThing ] ; rr:objectMap [ rr:parentTriplesMap <#TriplesMapThings>; rr:joinCondition [rr:child "thingId"; rr:parent "id";]; ];] ;
rr:predicateObjectMap [ rr:predicateMap [ rr:constant ex:id ] ; rr:objectMap [ rr:column "id" ]; ] ;
rr:predicateObjectMap [ rr:predicateMap [ rr:constant ex:thingid ] ; rr:objectMap [ rr:column "thingId" ]; ] ;
rr:predicateObjectMap [ rr:predicateMap [ rr:constant ex:value ] ; rr:objectMap [ rr:column "value" ]; ] .
最简单的方法是使用SQL查询:
<#TriplesMapThings> a rr:TriplesMap;
rr:logicalTable [rr:sqlQuery “SELECT Things.ID, Types.Name FROM Things, Types WHERE Things.typeId = Types.ID” ];
rr:subjectMap [ rr:template “http://localhost:8890/ex/things/{ID}”];
rr:predicateObjectMap [
rr:predicate rdf:type;
rr:objectMap [ rr:template “http://localhost:8890/ex/types/{Name}”]
].
<#TriplesMapValues> a rr:TriplesMap;
rr:logicalTable [rr:tableName “Values” ];
rr:subjectMap [ rr:template “http://localhost:8890/ex/things/{thingId}”];
rr:predicateObjectMap [
rr:predicate ex:hasValue;
rr:objectMap [ rr:column “Value”]
].
但是,看起来这不适用于 Virtuoso。根据他们的文档,rr:sqlQuery
is not supported。
如果Types.Name
是唯一键,我相信你可以这样做:
<#TriplesMapThings> a rr:TriplesMap;
rr:logicalTable [rr:tableName “Things” ];
rr:subjectMap [ rr:template “http://localhost:8890/ex/things/{ID}”];
rr:predicateObjectMap [
rr:predicate rdf:type;
rr:objectMap [
rr:parentTriplesMap <#TriplesMapTypes>;
rr:joinCondition [ rr:child “typeId”; rr:parent “ID”];
]
].
<#TriplesMapTypes> a rr:TriplesMap;
rr:logicalTable [rr:tableName “Types” ];
rr:subjectMap [ rr:template “http://localhost:8890/ex/types/{Name}”].
<#TriplesMapValues> a rr:TriplesMap;
rr:logicalTable [rr:tableName “Values” ];
rr:subjectMap [ rr:template “http://localhost:8890/ex/things/{thingId}”];
rr:predicateObjectMap [
rr:predicate ex:hasValue;
rr:objectMap [ rr:column “Value”]
].
请注意,您正在使用 Name
属性为 table Types
定义主题 URI。因此,即使您在 Things.typeId
和 Types.ID
之间加入,R2RML 处理器也应该使用 <#TriplesMapTypes>
TriplesMap
的主题定义。
如果 Types.Name
不是唯一键,则必须使用 SQL 查询来完成。
请注意,R2RML 旨在使用 SQL 查询,以防您需要复杂的映射(就像您正在尝试做的那样)。
我想使用 R2RML 和 Virtuoso 从 MySql 源映射一些 table。 我有一个 table 和 "Things",我希望它们具有不是 URI 的谓词,而是来自通过 thingID 连接的 table "Values" 的名称列。 我可以通过 "Thing" 的 ID 将 table "Values" 映射到 "Values" 的 thingId - 但是通过此映射,我只能获得相应 [=25= 的 URI ] 入口。我想要的是存储在 "Value".
列中的字符串预期的结果三元组应该是例如:
<http://localhost:8890/ex/things/1> rdf:type <http://localhost:8890/ex/types/vmware> ;
ex:hasValue "Name from the table Values" .
Example of Things table:
ID typeId
1 3
Example of the Types table:
ID Name
3 vmware
值示例 table:
ID thingId Value
1 1 VMware Virtual Platform
这是我目前的映射:
<#TriplesMapThings> a rr:TriplesMap; rr:logicalTable [ rr:tableSchema "exdb" ; rr:tableOwner "ex" ; rr:tableName "Things" ];
rr:subjectMap [ rr:termType rr:IRI ; rr:template "http://localhost:8890/ex/things/{id}"; rr:class ex:Things; rr:graph <http://localhost:8890/ex_test#> ];
rr:predicateObjectMap [ rr:predicateMap [ rr:constant ex:id ] ; rr:objectMap [ rr:column "id" ]; ] ;
rr:predicateObjectMap [ rr:predicateMap [ rr:constant ex:typeid ] ; rr:objectMap [ rr:column "typeId" ]; ] ;
rr:predicateObjectMap [ rr:predicateMap [ rr:constant rdf:type ] ; rr:objectMap [ rr:parentTriplesMap <#TriplesMapTypes>; rr:joinCondition [rr:child "typeId"; rr:parent "id";]; ];] ;
rr:predicateObjectMap [ rr:predicateMap [ rr:constant ex:hasValue ] ; rr:objectMap [ rr:parentTriplesMap <#TriplesMapValues>; rr:joinCondition [rr:child "id"; rr:parent "thingId";]; ];] .
<#TriplesMapTypes> a rr:TriplesMap; rr:logicalTable [ rr:tableSchema "exdb" ; rr:tableOwner "ex" ; rr:tableName "Types" ];
rr:subjectMap [ rr:termType rr:IRI ; rr:template "http://localhost:8890/ex/types/{nameUri}"; rr:class owl:Class; rr:graph <http://localhost:8890/ex_test#> ];
rr:predicateObjectMap [ rr:predicateMap [ rr:constant ex:id ] ; rr:objectMap [ rr:column "id" ]; ] ;
rr:predicateObjectMap [ rr:predicateMap [ rr:constant ex:name ] ; rr:objectMap [ rr:column "name" ]; ] .
<#TriplesMapValues> a rr:TriplesMap; rr:logicalTable [ rr:tableSchema "exdb" ; rr:tableOwner "ex" ; rr:tableName "Values" ];
rr:subjectMap [ rr:termType rr:IRI ; rr:template "http://localhost:8890/ex/values/{id}"; rr:class ex:Values; rr:graph <http://localhost:8890/ex_test#> ];
rr:predicateObjectMap [ rr:predicateMap [ rr:constant rdf:type ] ; rr:objectMap [ rr:parentTriplesMap <#TriplesMapAttributes>; rr:joinCondition [rr:child "attributeId"; rr:parent "id";]; ];] ;
rr:predicateObjectMap [ rr:predicateMap [ rr:constant ex:hasThing ] ; rr:objectMap [ rr:parentTriplesMap <#TriplesMapThings>; rr:joinCondition [rr:child "thingId"; rr:parent "id";]; ];] ;
rr:predicateObjectMap [ rr:predicateMap [ rr:constant ex:id ] ; rr:objectMap [ rr:column "id" ]; ] ;
rr:predicateObjectMap [ rr:predicateMap [ rr:constant ex:thingid ] ; rr:objectMap [ rr:column "thingId" ]; ] ;
rr:predicateObjectMap [ rr:predicateMap [ rr:constant ex:value ] ; rr:objectMap [ rr:column "value" ]; ] .
最简单的方法是使用SQL查询:
<#TriplesMapThings> a rr:TriplesMap;
rr:logicalTable [rr:sqlQuery “SELECT Things.ID, Types.Name FROM Things, Types WHERE Things.typeId = Types.ID” ];
rr:subjectMap [ rr:template “http://localhost:8890/ex/things/{ID}”];
rr:predicateObjectMap [
rr:predicate rdf:type;
rr:objectMap [ rr:template “http://localhost:8890/ex/types/{Name}”]
].
<#TriplesMapValues> a rr:TriplesMap;
rr:logicalTable [rr:tableName “Values” ];
rr:subjectMap [ rr:template “http://localhost:8890/ex/things/{thingId}”];
rr:predicateObjectMap [
rr:predicate ex:hasValue;
rr:objectMap [ rr:column “Value”]
].
但是,看起来这不适用于 Virtuoso。根据他们的文档,rr:sqlQuery
is not supported。
如果Types.Name
是唯一键,我相信你可以这样做:
<#TriplesMapThings> a rr:TriplesMap;
rr:logicalTable [rr:tableName “Things” ];
rr:subjectMap [ rr:template “http://localhost:8890/ex/things/{ID}”];
rr:predicateObjectMap [
rr:predicate rdf:type;
rr:objectMap [
rr:parentTriplesMap <#TriplesMapTypes>;
rr:joinCondition [ rr:child “typeId”; rr:parent “ID”];
]
].
<#TriplesMapTypes> a rr:TriplesMap;
rr:logicalTable [rr:tableName “Types” ];
rr:subjectMap [ rr:template “http://localhost:8890/ex/types/{Name}”].
<#TriplesMapValues> a rr:TriplesMap;
rr:logicalTable [rr:tableName “Values” ];
rr:subjectMap [ rr:template “http://localhost:8890/ex/things/{thingId}”];
rr:predicateObjectMap [
rr:predicate ex:hasValue;
rr:objectMap [ rr:column “Value”]
].
请注意,您正在使用 Name
属性为 table Types
定义主题 URI。因此,即使您在 Things.typeId
和 Types.ID
之间加入,R2RML 处理器也应该使用 <#TriplesMapTypes>
TriplesMap
的主题定义。
如果 Types.Name
不是唯一键,则必须使用 SQL 查询来完成。
请注意,R2RML 旨在使用 SQL 查询,以防您需要复杂的映射(就像您正在尝试做的那样)。