RMLio / rmlmapper-java

The RMLMapper executes RML rules to generate high quality Linked Data from multiple originally (semi-)structured data sources
http://rml.io
MIT License
144 stars 61 forks source link

URL-encoded version of email address #219

Closed psiotwo closed 2 weeks ago

psiotwo commented 9 months ago

When transforming

napoleon.bonaparte@emperor.fr

through

rr:template "mailto:{USER_EMAIL}" ; rr:termType rr:IRI

I get @ URL-encoded.

<mailto:napoleon.bonaparte%40emperor.fr>

DylanVanAssche commented 9 months ago

That's expected, a rr:template will encode any referenced values if the term type is IRI as defined by the R2RML specification: https://www.w3.org/TR/r2rml/

bjdmeest commented 9 months ago

If you want to just join strings together without using the rr:template processing, you can use the grel:array_join function, you can see an example at https://github.com/RMLio/rmlmapper-java/blob/master/src/test/resources/rml-fno-test-cases/RMLFNOTCF008/mapping.rml.ttl#L80

psiotwo commented 9 months ago

@bjdmeest thanks for hints! Works well. But I am now getting empty values in case USER_EMAIL is not present (before the triple was not generated at all). Can this be avoided?

DylanVanAssche commented 9 months ago

You could solve this by composing multiple functions: a combination of contains and array_join

psiotwo commented 8 months ago

Thanks @DylanVanAssche. I have come up with this solution, but I guess (and hope very much) there must be a simpler way to do it, right?


 ,[ rr:predicate vcard:hasEmail ; rr:objectMap [ fnml:functionValue [
                                                                                   rr:predicateObjectMap [ rr:predicate fno:executes; rr:objectMap [ rr:constant idlab:trueCondition ]; ];
                                                                                   rr:predicateObjectMap [ rr:predicate idlab:str; rr:objectMap [ fnml:functionValue [ rr:predicateObjectMap [ rr:predicate fno:executes; rr:objectMap [ rr:constant grel:array_join ]; ];
                                                                                                                                                                       rr:predicateObjectMap [ rr:predicate grel:p_array_a; rr:objectMap [ rr:constant "mailto:"  ]; ];
                                                                                                                                                                       rr:predicateObjectMap [ rr:predicate grel:p_array_a; rr:objectMap [ rml:reference "USER_EMAIL" ]; ]; ]; ]; ];
                                                                                   rr:predicateObjectMap [ rr:predicate idlab:strBoolean; rr:objectMap [ fnml:functionValue [ rr:predicateObjectMap [ rr:predicate fno:executes; rr:objectMap [ rr:constant grel:boolean_not ]; ];
                                                                                                                                                                              rr:predicateObjectMap [ rr:predicate grel:bool_b; rr:objectMap [ fnml:functionValue [ rr:predicateObjectMap [ rr:predicate fno:executes; rr:objectMap [ rr:constant idlab:isNull ]; ];
                                                                                                                                                                                                                                                                    rr:predicateObjectMap [ rr:predicate idlab:str; rr:objectMap [ rml:reference "USER_EMAIL" ]; ]; ]; ]; ]; ]; ]; ]; ];
                                                            rr:termType rr:IRI ] ]
DylanVanAssche commented 8 months ago

there must be a simpler way to do it, right?

This is the solution if you have this in as an IRI because a template encodes the values you pass to it when the term type is an IRI. Otherwise you can never guarantee that the generated RDF has valid IRIs. The only way to circumvent this behavior is by using FnO functions as you did, but you risk to produce invalid IRIs if the parameters contains unsafe IRI characters.

DylanVanAssche commented 2 weeks ago

This issue has a solution, I will close it now.