Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Absolute context is made relative #304

Closed
whikloj opened this issue Jan 8, 2021 · 3 comments
Closed

Absolute context is made relative #304

whikloj opened this issue Jan 8, 2021 · 3 comments
Assignees
Labels

Comments

@whikloj
Copy link

whikloj commented Jan 8, 2021

I'll say up front that my Json-LD spec fluency is not strong. Anyways...

We are using opaque IRI IDs internally and transforming them to URIs when returned to users to avoid storing hostnames.

It appears like the changes (perhaps in response to #232) is causing us some trouble.

I wrote a small class based on the area of Jena that seemed to be failing.
https://gist.github.com/whikloj/29f61a883dd14cb0cf17e2f292621957

My two tests are as follows.

With regular URI as the it works

> java -jar build/libs/JsonLdTest-1.0-SNAPSHOT-all.jar 'http://fedora/jared' '{ "@context": "https://json-ld.org/contexts/person.jsonld", "@id": "http://dbpedia.org/resource/John_Lennon", "name": "John Lennon", "born": "1940-10-09" }'
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Triples
http://dbpedia.org/resource/John_Lennon @http://schema.org/birthDate "1940-10-09"^^http://www.w3.org/2001/XMLSchema#date
http://dbpedia.org/resource/John_Lennon @http://xmlns.com/foaf/0.1/name "John Lennon"
Quads

With an opaque IRI is does not

> java -jar build/libs/JsonLdTest-1.0-SNAPSHOT-all.jar 'info:fedora/jared' '{ "@context": "https://json-ld.org/contexts/person.jsonld", "@id": "http://dbpedia.org/resource/John_Lennon", "name": "John Lennon", "born": "1940-10-09" }'
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" com.github.jsonldjava.core.JsonLdError: loading remote context failed: info:fedora/https://json-ld.org/contexts/person.jsonld
	at com.github.jsonldjava.core.DocumentLoader.loadDocument(DocumentLoader.java:74)
	at com.github.jsonldjava.core.Context.parse(Context.java:199)
	at com.github.jsonldjava.core.Context.parse(Context.java:146)
	at com.github.jsonldjava.core.Context.parse(Context.java:299)
	at com.github.jsonldjava.core.JsonLdApi.expand(JsonLdApi.java:550)
	at com.github.jsonldjava.core.JsonLdApi.expand(JsonLdApi.java:1027)
	at com.github.jsonldjava.core.JsonLdProcessor.expand(JsonLdProcessor.java:139)
	at com.github.jsonldjava.core.JsonLdProcessor.toRDF(JsonLdProcessor.java:528)
	at Tester.parse(Tester.java:85)
	at Tester.main(Tester.java:37)
Caused by: java.net.MalformedURLException: unknown protocol: info
	at java.base/java.net.URL.<init>(URL.java:634)
	at java.base/java.net.URL.<init>(URL.java:523)
	at java.base/java.net.URL.<init>(URL.java:470)
	at com.github.jsonldjava.core.DocumentLoader.loadDocument(DocumentLoader.java:72)
	... 9 more

This might be faulty understanding on our or Apache Jena's side, but it seems like using an IRI does not work as you are only expecting URIs. So I thought I would raise it here first. Thanks

@dr0i dr0i self-assigned this Jan 15, 2021
@whikloj
Copy link
Author

whikloj commented Jan 22, 2021

I still believe this is an issue, but we are switching our processing to using the external URI when parsing the incoming RDF and then translating the subsequent graph. Thanks. fcrepo/fcrepo#1847

@dr0i
Copy link
Member

dr0i commented Jan 25, 2021

@whikloj thx for reporting this issue. Apologizing for the late response.
It seems indeed a bug, as your using of a base IRI is defined in several documents as:

The base IRI is used to turn relative IRIs into absolute IRIs.

(https://json-ld.org/spec/latest/json-ld-api/#dfn-base-iris)

and

Please note that the @base will be ignored if used in external contexts.

(https://www.w3.org/TR/json-ld11/)

So the remote context you gave (https://json-ld.org/contexts/person.jsonld) should be untouched when defining info:fedora as a base IRI and thus not turning your remote context into info:fedora/https://json-ld.org/contexts/person.jsonld (which obviously cannot be resolved).

dr0i added a commit that referenced this issue Jan 26, 2021
If the remote context is not relative and seems to be a http URI
don't prefix the base IRI to it.

The remote context is not validated nor tested if it's resolvable.
It's just tested if it's not a relative URI - which is totally possible
and would, in conjunction with a base IRI, made into valid remote
context.

See #304.
dr0i added a commit that referenced this issue Jan 26, 2021
If the remote context is not relative and seems to be a http URI
don't prefix the base IRI to it.

The remote context is not validated nor tested if it's resolvable.
It's just tested if it's not a relative URI - which is totally possible
and would, in conjunction with a base IRI, made into valid remote
context.

See #304.
@dr0i dr0i added the Bug label Jan 28, 2021
@dr0i
Copy link
Member

dr0i commented Jan 28, 2021

Fix in master. Should come into next release.
Thx @whikloj for reporting.
Closing.

@dr0i dr0i closed this as completed Jan 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants