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
154 stars 61 forks source link

RMLMapper: URI Encoding Issue with Colon (:) in RDF Subjects #243

Open Yunheng-Tian opened 4 days ago

Yunheng-Tian commented 4 days ago

Hello,

I am experiencing an issue with RMLMapper where colons (:) in the id field of my JSON data are getting encoded into %3A in the resulting RDF knowledge graph. Below are the details of my input files and mapping.

JSON Input

[
    {
        "id": "HotelRoom:room_101",
        "type": "HotelRoom",
        "hasLocation": {
            "type": "Text",
            "value": "Floor:1",
            "metadata": {}
        },
        "name": {
            "type": "Text",
            "value": "room_101",
            "metadata": {}
        }
    }
]

RML Mapping File

@prefix rr: <http://www.w3.org/ns/r2rml#> .
@prefix rml: <http://semweb.mmlab.be/ns/rml#> .
@prefix ql: <http://semweb.mmlab.be/ns/ql#> .
@prefix brick: <https://brickschema.org/schema/1.4/Brick#> .
@prefix ex: <http://example.com#> .
@prefix rec: <https://w3id.org/rec/core#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .

ex:MappingHotelRoom
    a rr:TriplesMap ;
    rml:logicalSource [
        rml:source "entities_example.json" ;
        rml:referenceFormulation ql:JSONPath ;
        rml:iterator "$[?(@.type == 'HotelRoom')]" ;
    ] ;
    rr:subjectMap [
        rr:template "http://example.com/hotel/{id}" ;
        rr:class rec:Room ;
    ] ;
    rr:predicateObjectMap [
        rr:predicate brick:hasLocation ;
        rr:objectMap [
            rml:reference "hasLocation.value" ;
        ] ;
    ] ;
    rr:predicateObjectMap [
        rr:predicate rdfs:label ;
        rr:objectMap [
            rml:reference "name.value" ;
        ] ;
    ] .

Output RDF

<http://example.com/hotel/HotelRoom%3Aroom_101> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://w3id.org/rec/core#Room> .
<http://example.com/hotel/HotelRoom%3Aroom_101> <http://www.w3.org/2000/01/rdf-schema#label> "room_101" .
<http://example.com/hotel/HotelRoom%3Aroom_101> <https://brickschema.org/schema/1.4/Brick#hasLocation> "Floor:1" .

Issue

As seen in the RDF output, the colon (:) in the id field (HotelRoom:room_101) has been URL-encoded as %3A. I would like to prevent this encoding and preserve the original id value in the URI, i.e., I want it to appear as http://example.com/hotel/HotelRoom:room_101 instead of http://example.com/hotel/HotelRoom%3Aroom_101.

Question

Is there any option in RMLMapper to disable or customize the URI encoding for the id values, especially for characters like the colon (:)? Alternatively, is there a specific configuration I should use in the RML mapping file to achieve this?

Any guidance or suggestions would be greatly appreciated!

bjdmeest commented 4 days ago

I have the feeling this is a similar issue as https://github.com/RMLio/rmlmapper-java/issues/219 , with follow-up action captured at https://github.com/kg-construct/rml-core/issues/72 : i'm afraid the only current solution is following something similar to #219

Yunheng-Tian commented 4 days ago

Hello,

Thank you for the quick reply. I tried to modify the mapping file. However, I got some error information. Could you help me to identify what is the problem?

I have the feeling this is a similar issue as #219 , with follow-up action captured at kg-construct/rml-core#72 : i'm afraid the only current solution is following something similar to #219

Modified RML Mapping File

@prefix rr: <http://www.w3.org/ns/r2rml#> .
@prefix rml: <http://semweb.mmlab.be/ns/rml#> .
@prefix ql: <http://semweb.mmlab.be/ns/ql#> .
@prefix brick: <https://brickschema.org/schema/Brick#> .
@prefix ex: <http://example.com#> .
@prefix rec: <https://w3id.org/rec/core#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix fnml: <http://semweb.mmlab.be/ns/fnml#> .
@prefix fno: <https://w3id.org/function/ontology#> .
@prefix grel: <http://users.ugent.be/~bjdmeest/function/grel.ttl#> .

# Mapping for HotelRoom
ex:MappingHotelRoom
    a rr:TriplesMap ;
    rml:logicalSource [
        rml:source "entities_example.json" ;
        rml:referenceFormulation ql:JSONPath ;
        rml:iterator "$[?(@.type == 'HotelRoom')]" ;
    ] ;
     rr:subjectMap [
        fnml:functionValue [
            fnml:execution [
                fno:function grel:concat ;
                grel:inputString1 [ rr:constant "http://example.com/hotel/" ] ;
                grel:inputString2 [ rml:reference "id" ] ;
            ] ;
        ] ;
        rr:class rec:Room ;
    ] ;
    rr:predicateObjectMap [
        rr:predicate brick:hasLocation ;
        rr:objectMap [
            rml:reference "hasLocation.value" ;
        ] ;
    ] ;
    rr:predicateObjectMap [
        rr:predicate rdfs:label ;
        rr:objectMap [
            rml:reference "name.value" ;
        ] ;
    ] .

Error information

17:42:55.028 [main] ERROR be.ugent.rml.cli.Main               .run(423) - No function was defined for parameters: []
17:42:55.031 [main] ERROR be.ugent.rml.cli.Main               .run(458) - No function was defined for parameters: []
java.lang.Exception: No function was defined for parameters: []
        at be.ugent.rml.functions.DynamicMultipleRecordsFunctionExecutor.execute(DynamicMultipleRecordsFunctionExecutor.java:81)
        at be.ugent.rml.functions.AbstractSingleRecordFunctionExecutor.execute(AbstractSingleRecordFunctionExecutor.java:16)
        at be.ugent.rml.termgenerator.NamedNodeGenerator.generate(NamedNodeGenerator.java:40)
        at be.ugent.rml.Executor.getSubject(Executor.java:318)
        at be.ugent.rml.Executor.executeWithFunction(Executor.java:169)
        at be.ugent.rml.Executor.execute(Executor.java:152)
        at be.ugent.rml.cli.Main.run(Main.java:421)
        at be.ugent.rml.cli.Main.main(Main.java:47)
java.lang.Exception: No function was defined for parameters: []