Dynamic Predicate in R2RML

181 views Asked by At

I need to make a mapping that involve one simple table, however my predicate needs to be dynamic based on the values coming from one column.

This is my query:

SELECT  
    item_id, 
    Concat_WS('@', metadatavalue.text_value, cast(metadatavalue.text_lang as text)) AS textValue,
    (CASE metadata_field_id 
        WHEN '3' THEN 'creator'
        WHEN '79' THEN 'docnumber'
     END) AS Field 
FROM
    metadatavalue
ORDER BY
    item_id, Field, textValue;

The values from field returns the predicate to use.

I want to produce triple of the form

<pub:1234> dc:creator “jean francois”@en
<pub:1234> dc:docnumber 1345
<pub:1234> dc:subject “poverty”@en

So basically all my predicate are in the column metadata_field_id the values are the identifier of the predicate.

I am not sure but it seems like R2RML is supposed to support that.

1

There are 1 answers

0
Juan Sequeda On

Yes, you can do that in R2RML.

There are two ways:

1) Use an rr:template as the predicate.

:Map1
    a rr:TriplesMap ;
    rr:logicalTable [ rr:sqlQuery "SELECT ..... " ] ;
    rr:predicateObjectMap [ 
        rr:objectMap [ rr:column "COLUMNNAME" ] ;
        rr:predicateMap [ rr:template  "http://purl.org/dc/elements/1.1/{Field}" ] ;
    ] ;
    rr:subjectMap [ rr:template  "http://www.example.com/data/{id}" ] .

2) Use an rr:column as the predicate. In this case, create the actual URI in the SQL query:

:Map1
    a rr:TriplesMap ;
    rr:logicalTable [ rr:sqlQuery "SELECT ..... " ] ;
    rr:predicateObjectMap [ 
        rr:objectMap [ rr:column "COLUMNNAME" ] ;
        rr:predicateMap [ rr:column "Field" ] ;
    ] ;
    rr:subjectMap [ rr:template "http://www.example.com/data/{id}" ] .