2016-11-22 84 views
1

我想使用R2RML和Virtuoso映射MySql源中的某些表。 我有一個表「Things」,我希望它們的謂詞不是URI,而是來自通過thingID連接的表「Values」中的名稱列。 我可以通過「Thing」的ID將表「Values」映射到「Values」的thingId - 但通過此映射,我只能獲取各個「Values」條目的URI。我想要的是存儲在「Value」列中的字符串。R2RML映射與另一個表中的值

預期所得三重應該是例如:

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" ]; ] . 
所述值表的

<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 

實施例

回答

1

最簡單的方法是使用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」] 
]. 

然而,像這樣將不會與炫技工作。根據他們的文檔,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屬性定義爲表Types主題的URI。因此,即使您加入Things.typeIdTypes.ID之間,R2RML處理器也應該使用<#TriplesMapTypes>TriplesMap的主題定義。

如果Types.Name不是唯一鍵,那麼您必須使用SQL查詢來完成此操作。

請注意,如果您需要複雜映射(如您正在嘗試執行的操作),R2RML被設計爲使用SQL查詢。

相關問題