6 Replies Latest reply on Jul 14, 2016 5:29 PM by 3274437

    R2RML Typed Literals (rr:datatype)


      Dear all,


      I'm trying to use the R2RML rr:datatype property in order to explicit specify the type of a literal object (ref. https://www.w3.org/2001/sw/rdb2rdf/r2rml/#typed-literals).

      My R2RML configuration in ntriples format is:




      Note that in the last three lines I'm setting up the objectMap of the property "<http://mapping.org/order>"  to a constant "1" and saying it is a xsd:decimal and a rr:Literal.


      After the materialization, when I execute the following query:


      'SELECT ?sOrder WHERE {  ?s <http://mapping.org/order> ?sOrder  } ',


      I get the following result:


      If I execute a BIND converting the value explicitly to xsd:decimal, it works:


      'SELECT ?sOrder WHERE {  ?s <http://mapping.org/order> ?sOrder .  BIND ( <http://www.w3.org/2001/XMLSchema#decimal>(str(?sOrder)) AS ?sOrder2) } ',
      SEM_Models('prolab_mat'),NULL, NULL,NULL));




      I there another way to do the type specification directly through R2RML mapping? I would not like to use the BIND function all the time.

      Thanks in advance,


        • 1. Re: R2RML Typed Literals (rr:datatype)

          Hi Elisa,


          Please use the following in the R2RML mapping:

            rr:constant "1"^^xsd:decimal .

          instead of

            rr:constant "1" ;

            rr:datatype xsd:decimal .


          Please refer to the following note in the W3C R2RML specification: "

          Constant-valued term maps are not considered as having a term type, and specifying rr:termType on these term maps has no effect. The type of the generated RDF term is determined directly by the value of rr:constant: If it is an IRI, then an IRI will be generated; if it is a literal, a literal will be generated.



          When in an rr:ObjectMap one specifies a value for rr:constant, R2RML does not look ignores any specified value for rr:termType or rr:datatype, because the specified rdfterm constant implicitly says what its term type and data type are. A value of "1" tells R2RML that it as a plain literal, whereas a value of"1"^^xsd:decimal tells R2RML that it is the numeric value 1.


          Hope this helps,

          - Souri.

          • 2. Re: R2RML Typed Literals (rr:datatype)

            Hi Souri,


            Thanks very much for the reply! It worked perfectly for constants!


            But I also tried the rr:datatype with rr:template and rr:column and it did not work either! So I tried something like:

                 rr:column "VALUE"^^xsd:decimal


            But it raises an error:


            ORA-55328: literal value string insert attempt failed. "VALUE"^^xsd:decimal

            ORA-06512: em "MDSYS.SDO_RDF_INTERNAL", line 15330

            ORA-06512: em "MDSYS.SDO_RDF", line 3829

            ORA-06512: em "MDSYS.RDF_APIS", line 1276

            ORA-06512: em line 1


            The column "VALUE" in Oracle is a varchar but it has only integer values. So, how can I do the type specification with columns or templates?


            Thanks in advance,


            • 3. Re: R2RML Typed Literals (rr:datatype)

              Hi Elisa,


              For column-valued mapping, you need to explicitly set the target datatype (unless target datatype is same as the column's datatype in the database).

              Please try:

                rr:objectMap [ rr:column "VALUE" ; rr:datatype xsd:decimal ]



              - Souri.

              1 person found this helpful
              • 4. Re: R2RML Typed Literals (rr:datatype)

                Hi Souri,


                Thanks again for the reply! Sorry, I made a mistake with rr:column and rr:datatype, but after I fixed it worked perfectly!


                And how about rr:template? I tried something like:

                     rr:objectMap [ rr:termType rr:Literal ; rr:datatype xsd:decimal ; rr:template "{VALUE}" ]

                But it didn't work. How can I do the type specification in this case?

                Thanks in advance,


                • 5. Re: R2RML Typed Literals (rr:datatype)



                  Do you have a real need for a template-valued ObjectMap to map to a datatype that is neither string nor a user-defined type?


                  For ObjectMap with template-valued mapping, we currently allow rr:datatype to be either xsd:string or a user-defined datatype e.g., <http://myDataType>.

                  If you specify rr:datatype to be anything else (e.g., xsd:decimal), it would raise an error like the following:

                      ORA-13199: R2RML mapping has rr:template mapping to literals of type other than STRING and user-defined types


                  Of course, if you do need such mapping, use of rr:sqlQuery or database views can always be used as a workaround.



                  - Souri.

                  1 person found this helpful
                  • 6. Re: R2RML Typed Literals (rr:datatype)

                    Hi Souri,


                    Yes, it would be useful in this particular case that I have! But no problem, it can be solved with views for sure!


                    Thanks for all the help,