Is there any way in rml / r2rml to take a value as an IRI?

459 views Asked by At

I'm using RMLMapper to transfrom JSON to RDF. One of the values stored in the JSON is a URL. I would like to use this as the basis of an IRI for the object of RDF statements.

The input is

{
  "documentId": {
    "value": "http://example.org/345299"
  },
...

I want the IRI for the subject of statements to be http://example.org/345299#item, e.g. <http://example.org/345299#item> a <http://schema.org/Thing> .

I tried

@prefix rr: <http://www.w3.org/ns/r2rml#>.
@prefix rml: <http://semweb.mmlab.be/ns/rml#>.
@prefix ql: <http://semweb.mmlab.be/ns/ql#>.
<#Mapping> a rr:TriplesMap ;
  rml:logicalSource [
    rml:source "input.json";
    rml:referenceFormulation ql:JSONPath;
    rml:iterator "$"
  ];

  rr:subjectMap [
    rr:template "{documentId.value}#item" ;
    rr:class schema:Thing
  ]

gives and error that rr:template "{documentId.value}#item" doesn't produce a valid IRI.

Providing a value for @base gives a valid IRI, but it is the base with the url-encoded value appended to the base, e.g. <http://example.org/http%3A%2F%2Fexample.org%2Fjobposts%2F345299#item>

So is there any way in r2rml / rml to take a value and just use it as an IRI? Or to convert a string in to an IRI?

2

There are 2 answers

0
Phil Barker On

rml:reference is close enough.

  rr:subjectMap [
    rml:reference "documentId.value" ;
    rr:class schema:Thing
  ]

Doesn't seem to let me append #item but it'll do for now.

0
Thomas Delva On

One option would be to not use a rr:template, but instead an FnO function to concatenate the stored URI with #item.

Documentation on how to do this can be found here.

In the example you give, replacing the subject map with this gives the required solution:

<#Mapping> rr:subjectMap [
  a fnml:FunctionTermMap;
  rr:termType rr:IRI;
  fnml:functionValue [
    rml:logicalSource <#Source> ;
    rr:predicateObjectMap [
      rr:predicate fno:executes ;
      rr:objectMap [ rr:constant grel:array_join ] ;
    ] ;
    rr:predicateObjectMap [
      rr:predicate grel:p_array_a ;
      rr:objectMap [ rml:reference "documentId.value" ] ;
    ] ;
    rr:predicateObjectMap [
      rr:predicate grel:p_array_a ;
      rr:objectMap [ rr:constant "#item" ] ;
    ] ;
  ] .

Note: I contribute to RML and its technologies.