filip26 / titanium-json-ld

A JSON-LD 1.1 Processor & API
https://apicatalog.com
Apache License 2.0
134 stars 33 forks source link

INVALID_IRI_MAPPING when using specific context in form of an array #149

Closed jakubklimek closed 3 years ago

jakubklimek commented 3 years ago

When trying to process a JSON-LD 1.1 file using Titanium (e.g. compact, but also other operations), I get the INVALID_IRI_MAPPING exception. The file processed is:

{
    "@context": [
        "https://pod-test.mvcr.gov.cz/otevřené-formální-normy/pracovní-místa/draft/kontexty/pracovní-místo.jsonld",
        {
            "@version": 1.1,
            "@import": "https://ofn.gov.cz/věc/2020-07-01/kontexty/věc.jsonld",
            "@propagate": true,
            "nedefinováno": "https://slovník.gov.cz/nedefinováno/",
            "místa": "https://slovník.gov.cz/generický/pracovní-místa/pojem/",
            "Pracovní místo ve vědě a výzkumu": {
                "@id": "nedefinováno:pracovní-místo-ve-vědě-a-výzkumu",
                "@context": {
                    "pracoviště": {
                        "@id": "místa:má-pracoviště",
                        "@context": "https://pod-test.mvcr.gov.cz/otevřené-formální-normy/věda-a-výzkum/draft/kontexty/věda-a-výzkum.jsonld"
                    }
                }
            }
        }
    ],
    "typ": [
        "Pracovní místo ve vědě a výzkumu"
    ],
    "iri": "https://data.mff.cuni.cz/zdroj/pracovní-místa-mff-uk/202008-AP1-KSI",
    "pracoviště": {
        "typ": "Pracoviště",
        "iri": "https://data.mff.cuni.cz/zdroj/číselník/organizační-struktura/oddělení/204"
    }
}

The weird thing is that when I leave only one of the two items in the @context array, the processing does not fail. It only fails when there are both items.

The exception:

Caused by: com.apicatalog.jsonld.JsonLdError: There was a problem encountered loading a remote context [code=LOADING_REMOTE_CONTEXT_FAILED].
    at com.apicatalog.jsonld.context.ActiveContextBuilder.fetch(ActiveContextBuilder.java:572)
    at com.apicatalog.jsonld.context.ActiveContextBuilder.create(ActiveContextBuilder.java:173)
    at com.apicatalog.jsonld.expansion.ObjectExpansion.initPropertyContext(ObjectExpansion.java:148)
    at com.apicatalog.jsonld.expansion.ObjectExpansion.expand(ObjectExpansion.java:99)
    at com.apicatalog.jsonld.expansion.Expansion.compute(Expansion.java:116)
    at com.apicatalog.jsonld.expansion.ObjectExpansion1314.expand(ObjectExpansion1314.java:905)
    at com.apicatalog.jsonld.expansion.ObjectExpansion.expand(ObjectExpansion.java:120)
    at com.apicatalog.jsonld.expansion.Expansion.compute(Expansion.java:116)
    at com.apicatalog.jsonld.processor.ExpansionProcessor.expand(ExpansionProcessor.java:124)
    at com.apicatalog.jsonld.api.ExpansionApi.get(ExpansionApi.java:142)
    at com.linkedpipes.plugin.transformer.jsonldformattitanium.TitaniumOperator.expand(TitaniumOperator.java:91)
    ... 6 common frames omitted
Caused by: com.apicatalog.jsonld.JsonLdError: The local context defined within a term definition is invalid [code=INVALID_SCOPED_CONTEXT].
    at com.apicatalog.jsonld.context.TermDefinitionBuilder.create(TermDefinitionBuilder.java:534)
    at com.apicatalog.jsonld.context.ActiveContextBuilder.create(ActiveContextBuilder.java:451)
    at com.apicatalog.jsonld.context.ActiveContextBuilder.fetch(ActiveContextBuilder.java:565)
    ... 16 common frames omitted
Caused by: com.apicatalog.jsonld.JsonLdError: A local context contains a term that has an invalid or missing IRI mapping [code=INVALID_IRI_MAPPING].
    at com.apicatalog.jsonld.context.TermDefinitionBuilder.create(TermDefinitionBuilder.java:358)
    at com.apicatalog.jsonld.context.ActiveContextBuilder.create(ActiveContextBuilder.java:451)
    at com.apicatalog.jsonld.context.TermDefinitionBuilder.create(TermDefinitionBuilder.java:531)
    ... 18 common frames omitted

Note that the referenced external contexts re-use each other, which even forms a cycle, but that should not be an issue, as it holds even when one of the two items in the @context array stays.

github-actions[bot] commented 3 years ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days

jakubklimek commented 3 years ago

This issue is still relevant and prohibits use of titanium in our use cases.

filip26 commented 3 years ago

Hi, I've created a test but I cannot reproduce the issue. Check input: issue149-in.json and result: issue-149-out.json. The output seems correct, please feel free to update the expected output or suggest other test.

for details see commit https://github.com/filip26/titanium-json-ld/commit/c294141809f6da439fcb3f3f7fa4721e8c61b93a

jakubklimek commented 3 years ago

Hi, I think this was fixed in https://github.com/skodapetr/titanium-json-ld/commit/3dddc0e6a4618c69dc2ea6e69e2984852fc0ebae and that is why it works now.

filip26 commented 3 years ago

that's great. Please re-open if the issue shows again.