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:constant
s only and not rr:template
s :( . 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).
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" ];
].