2016-11-22 3 views
1

Je souhaite utiliser R2RML et Virtuoso pour mapper certaines tables à partir d'une source MySql. J'ai une table avec "Things" et je veux qu'ils aient des prédicats qui ne sont pas des URI mais qui viennent de la colonne name d'une table "Values" connectée via le thingID. Je peux mapper la table "Valeurs" via l'ID d'une "Chose" à la thingId de "Valeurs" - mais avec cette cartographie je reçois seulement l'URI de l'entrée "Valeurs" respective. Ce que je veux avoir, c'est la chaîne stockée dans la colonne "Value".Mappage R2RML avec les valeurs d'une autre table

Le escomptables triple devrait être par exemple:

<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 

Exemple de la table des valeurs:

ID thingId Value 
1 1   VMware Virtual Platform 

C'est mon application à ce jour:

<#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" ]; ] . 

Répondre

1

La façon la plus simple est d'utiliser des requêtes 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”] 
]. 

Cependant, ressemble à ceci ne fonctionne pas avec Virtuoso. Selon leur documentation, rr:sqlQuery is not supported.

Si Types.Name est une clé unique, je crois que vous pouvez faire ce qui suit:

<#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”] 
]. 

Notez que vous définissez le sujet URIs pour la table Types en utilisant l'attribut Name. Ainsi, même si vous vous joignez entre Things.typeId et Types.ID, le processeur R2RML doit utiliser la définition du sujet <#TriplesMapTypes>TriplesMap.

Si Types.Name n'est pas une clé unique, vous devez le faire en utilisant des requêtes SQL.

Notez que R2RML a été conçu pour utiliser des requêtes SQL au cas où vous auriez besoin de mappages complexes (comme celui que vous essayez de faire).