RMLio / yarrrml-parser

A YARRRML parser library and CLI in Javascript
MIT License
41 stars 17 forks source link

Using references for datatypes #162

Closed JBPressac closed 2 years ago

JBPressac commented 2 years ago

Issue type: :unicorn: Feature

Description

The usage of references to build language tags is working but not the usage of references to build datatypes

For instance, using a reference with ~lang:

 AppelationPersonneMapping:
  sources: prelib_appellationpersonne
  predicateobjects:
  - [a, crm:E41_Appellation]
  - [crm-sup:P21_has_value, $(appellation), $(code_iso_639_3)~lang]

generates the rule (this is an extract) :

:map_AppelationPersonneMapping_000 rr:predicateObjectMap :pom_021.
:pm_021 a rr:PredicateMap.
:pom_021 rr:predicateMap :pm_021.
:pm_021 rr:constant crm-sup:P21_has_value.
:pom_021 rr:objectMap :om_021.
:om_021 a rr:ObjectMap;
    rml:reference "appellation";
    rr:termType rr:Literal;
    rml:languageMap :language_001.
:language_001 rml:reference "code_iso_639_3".

However, using a reference with datatype:

# date_naissance_dtype = gYear or date
 TimeSpanBirthMapping:
  sources: prelib_personne
  predicateobjects:
   - [a, crm:E52_Time-Span]
   - p: crm:P82_at_some_time_within
     o: $(date_naissance)
     datatype: xsd:$(date_naissance_dtype)

generates the following where _date_naissancedtype is not interpreted as a reference:

:map_TimeSpanBirthMapping_000 rr:predicateObjectMap :pom_036.
:pm_036 a rr:PredicateMap.
:pom_036 rr:predicateMap :pm_036.
:pm_036 rr:constant crm:P82_at_some_time_within.
:pom_036 rr:objectMap :om_036.
:om_036 a rr:ObjectMap;
    rml:reference "date_naissance";
    rr:termType rr:Literal;
    rr:datatype <http://www.w3.org/2001/XMLSchema#$(date_naissance_dtype)>.

Why it is useful

Literal datatypes could change for the same object, for instance a date of birth could be of type xsd:gYear or xsd:date. Retrieving the dataype from a source could be helpfull.

Existing features it breaks

List all existing features that this new feature will break.

pheyvaer commented 2 years ago

Hi @JBPressac

Thanks for reporting this! It should indeed work as you expect. We will fix this.

pheyvaer commented 2 years ago

I looked into this and actually you can't use references to generate datatypes. In other words, it have to be constants. That is due to a limitation in [R2]RML.

JBPressac commented 2 years ago

Hello, Thank you for your answer. I will find a workaround, then.

pheyvaer commented 2 years ago

Technically speaking we could add this to YARRRML syntax-wise but it wouldn't be executable by an [R2]RML processor.

JBPressac commented 2 years ago

Hello, Here is the workaround to select the appropriate datatype (xsd:gYear or xsd:date) for the value of crm:P82_at_some_time_within according to the value of the $(date_naissance_dtype) reference:

 TimeSpanBirthMapping:
  sources: prelib_personne
  predicateobjects:
   - [a, crm:E52_Time-Span]
   - p: crm:P82_at_some_time_within
     o: $(date_naissance)
     datatype: xsd:gYear
     condition:
      function: equal
      parameters:
       - [str1, $(date_naissance_dtype)]
       - [str2, 'gYear']
   - p: crm:P82_at_some_time_within
     o: $(date_naissance)
     datatype: xsd:date
     condition:
      function: equal
      parameters:
       - [str1, $(date_naissance_dtype)]
       - [str2, 'date']