1

I'm playing around with R2RML and I was wondering if I can create a property depending on the content of a RDB table cell.

The D2RQ mapping language has d2rq:condition that can handle that.

e.g.:

if value in column/table cell 'name' is 'abc' create property 'abc'

rr:predicateObjectMap [
    rr:predicate ex:abc
    rr:objectMap [ 
        rr:column "name"; 
        rr:datatype xsd:string; 
        # equivalent for d2rq:condition "name='abc'"
    ];
]

if value in column/table cell 'name' is 'xyz' create property 'xyz'

rr:predicateObjectMap [
    rr:predicate ex:xyz
    rr:objectMap [ 
        rr:column "name"; 
        rr:datatype xsd:decimal; 
        # equivalent for d2rq:condition "name='xyz'"
    ];
];

I couldn't find any suggestion in W3C's R2RML Recommendation.

Any ideas? :-)


Update:

I had the idea of using rr:sqlQuery e.g.

rr:SQLQuery """
   select (case TABLENAME.COLUMNNAME
      when 'this' then 'propertyOne'
      when 'that' then 'propertyTwo'
      end) as VARIABLE_PREDICATE
   from TABLENAME """;

and apply it to a rr:predicate or rr:predicateMap with

rr:predicateObjectMap [
        rr:predicateMap [ rr:template "ex:{VARIABLE_PREDICATE}" ];
        rr:objectMap [ rr:column "COLUMNNAME"; ];
];

But that didn't work. I guess predicateMaps can be rr:constants only and not rr:templates :( . At least the W3C Recommendation just shows constants within predicateMap.

Still searching for a solution... :/

P.S. I'm disappointed that a proprietary language like d2rq seems to be more powerful (at this point).

Kody
  • 1,154
  • 3
  • 14
  • 31
  • This document mentions `rr:joinCondition` as similar to `d2rq:condition` : https://github.com/RMLio/D2RQ_to_R2RML – CaptSolo Mar 09 '16 at 17:10
  • Thanks for the link! But unfortunately that's not correct. I was checking the W3C Recommendation page for R2RML and also this page https://www.w3.org/ns/r2rml#joinCondition .... It just works for joins :( – Kody Mar 09 '16 at 20:54
  • A pity it did not work. Perhaps there is a mailing list where to ask about this? – CaptSolo Mar 09 '16 at 21:21
  • I am guessing you need to add 2 case statements in SQL: one for abc and one for xyz. Both either return a value or null. Then you can keep the 2 predicate object maps as in your first example. – Natan Cox Mar 15 '16 at 14:01

2 Answers2

1

R2RML doesn't have conditional properties (like in D2RQ). The design was done on purpose in order not to complicate the language. Any type of "complex" mapping requires SQL.

A solution is the following:

@prefix rr: <http://www.w3.org/ns/r2rml#>.

<#Mapping> a rr:TriplesMap;
    rr:logicalTable [ rr:SQLQuery """
        select id, COLUMNNAME, (case TABLENAME.COLUMNNAME
        when 'this' then 'http://ex.com/propertyOne'
        when 'that' then 'http://ex.com/propertyTwo'
        end) as VARIABLE_PREDICATE
        from TABLENAME """; ];
    rr:subjectMap [
       rr:template "http://ex.com/foo/{id}";
   ];

   rr:predicateObjectMap [
      rr:predicateMap [ rr:column "VARIABLE_PREDICATE" ];
      rr:objectMap [ rr:column "COLUMNNAME" ];
   ].
Juan Sequeda
  • 151
  • 4
  • I tried that with 'r2rml parser', but it totally ignored the sqlQuery part and did'n create a triple regarding the variable property. which r2rml processor/mapper do you use? :) – Kody Mar 15 '16 at 17:53
  • I use Ultrawrap from Capsenta. Disclaimer, I work for Capsenta. – Juan Sequeda Mar 16 '16 at 00:56
  • That's cool :) ... Don't get me wrong... but are you sure you can apply a `rr:column` to a `rr:predicate` or `rr:predicateMap`? In all r2rml files I've seen, there are just `rr:constants` that are applied to predicates/predicateMaps. – Kody Mar 16 '16 at 10:23
  • 1
    Yes you can. You usually see rr:constants (or the shortcut rr:predicate) because that is the most common usecase. What you are trying to do does not fall in the common use cases (at least in my experience). Your relational database is storing the metadata also as data. A predicate map is a term map (https://www.w3.org/TR/r2rml/#dfn-predicate-map). A term map must be either a constant-valued (the common case), a column-valued (your use case) or template-valued term map (see https://www.w3.org/TR/r2rml/#dfn-term-map). Btw, if it doesn't work with r2rml parser, means that they don't support it. – Juan Sequeda Mar 16 '16 at 16:57
0

We routinely do that in mapping the Getty vocabs, for props that depend on key values (flags). Eg

<#ContribTermRelPreferred>
    a rr:TriplesMap;
    rr:logicalTable [ rr:sqlQuery """
    SELECT ...
        UDF_LOD_LOOKUP_PROPERTY('contrib_rels_term','preferred',CRT.PREFERRED) CONTRIBPREF
    """ ];
rr:predicateObjectMap [
    rr:predicateMap [ rr:column "CONTRIBPREF" ];
    rr:objectMap [ rr:template "http://vocab.getty.edu/aat/contrib/{CONTRIB_ID}" ];
].
Vladimir Alexiev
  • 2,477
  • 1
  • 20
  • 31