首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用另一个表的值进行R2RML映射

使用另一个表的值进行R2RML映射
EN

Stack Overflow用户
提问于 2016-11-22 17:00:42
回答 1查看 267关注 0票数 1

我想使用R2RML和Virtuoso从MySql源映射一些表。我有一个带有"Things“的表,我希望它们有一个谓词,这些谓词不是URI,而是来自名称列的谓词,来自通过thingID连接的表”值“。我可以通过"Thing“的ID将表”值“映射到”thingId“的”值“--但是通过这种映射,我只能得到相应”值“条目的URI。我想要的是存储在列"Value“中的字符串。

例如,预期结果的三倍应该是:

代码语言:javascript
复制
<http://localhost:8890/ex/things/1> rdf:type <http://localhost:8890/ex/types/vmware> ;
ex:hasValue "Name from the table Values" .
代码语言:javascript
复制
Example of Things table: 
ID  typeId 
1   3

Example of the Types table: 
ID   Name 
3    vmware

值表的示例:

代码语言:javascript
复制
ID   thingId   Value 
1    1         VMware Virtual Platform

到目前为止,这是我的地图:

代码语言:javascript
复制
<#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" ]; ] .
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-11-29 02:13:48

最简单的方法是使用SQL查询:

代码语言:javascript
复制
<#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。根据他们的文档, is not supported

如果Types.Name是唯一的密钥,我相信您可以执行以下操作:

代码语言:javascript
复制
<#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”]
].

注意,您正在使用Types属性为表Name定义主题URI。因此,即使在Things.typeIdTypes.ID之间加入,R2RML处理器也应该使用<#TriplesMapTypes> TriplesMap的主题定义。

如果Types.Name不是唯一的键,那么您必须使用SQL查询来完成它。

请注意,R2RML的设计是为了在需要复杂映射(就像您试图执行的映射)时使用SQL查询。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40747592

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档