URI.resolve() will not assume anything. Base URI normally ends with a /. Don’t know if this is the best reference, but close: https://tools.ietf.org/html/rfc3986#section-6.2.3
You need to check the URI RFC and its resolution algorithm. On Wed, 4 Mar 2020 at 16.57, Erich Bremer <er...@ebremer.com> wrote: > This also works: > > URI uri = new URI("http://mysite.net"); > System.out.println(uri.resolve("/picture.jpg")); > > but if no trailing "/" and no leading "/" on path will yield the > concatenated http://mysite.netpicture.jpg which then gets tossed and a > blank node is formed. > > Should URI.resolve assume a "/" if no trailing nor leading "/" is present? > - Erich > > On Wed, Mar 4, 2020 at 10:52 AM Erich Bremer <er...@ebremer.com> wrote: > > > The program works if I specify the base with a trailing slash as " > > http://mysite.net/" > > I ran through the code and the problem appears to be here: > > > > > https://github.com/jsonld-java/jsonld-java/blob/66012db2f53b009cedeae50c83b5594b9dd05e11/core/src/main/java/com/github/jsonldjava/utils/JsonLdUrl.java#L283 > > > > In the short code segment here, you can see: > > URI uri = new URI("http://mysite.net"); > > System.out.println(uri.resolve("picture.jpg")); > > > > Output: > > http://mysite.netpicture.jpg > > > > > > On Wed, Mar 4, 2020 at 10:05 AM Erich Bremer <er...@ebremer.com> wrote: > > > >> Same thing: > >> Source JSONLD > >> { > >> "@context": [ > >> "http://schema.org" > >> ], > >> "@graph": [ > >> { > >> "@type": "CreativeWork", > >> "@id": "picture.jpg" > >> }, > >> { > >> "@id": "./", > >> "@type": "DataSet" > >> } > >> ] > >> } > >> AFTER loading > ============================================================ > >> Base : http://mysite.net > >> 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. > >> [ { > >> "@type" : [ "http://schema.org/CreativeWork" ] > >> }, { > >> "@id" : "http://mysite.net", > >> "@type" : [ "http://schema.org/DataSet" ] > >> } ] > >> > >> > >> CODE ==================================== > >> package com.mycompany.tesjsonld; > >> > >> import com.github.jsonldjava.core.JsonLdOptions; > >> import com.github.jsonldjava.core.JsonLdProcessor; > >> import com.github.jsonldjava.utils.JsonUtils; > >> import java.io.ByteArrayInputStream; > >> import java.io.FileNotFoundException; > >> import java.io.IOException; > >> import java.io.InputStream; > >> import java.nio.charset.Charset; > >> > >> /** > >> * > >> * @author erich > >> */ > >> public class tryme { > >> > >> public static void main(String[] args) throws FileNotFoundException, > >> IOException { > >> String json = "{\n" + > >> " \"@context\": [\n" + > >> " \"http://schema.org\"\n" + > >> " ],\n" + > >> " \"@graph\": [\n" + > >> " {\n" + > >> " \"@type\": \"CreativeWork\",\n" + > >> " \"@id\": \"picture.jpg\"\n" + > >> " },\n" + > >> " {\n" + > >> " \"@id\": \"./\",\n" + > >> " \"@type\": \"DataSet\"\n" + > >> " }\n" + > >> " ]\n" + > >> "}"; > >> > >> System.out.println(json); > >> > >> > System.out.println("============================================================"); > >> InputStream inputStream = new > >> ByteArrayInputStream(json.getBytes(Charset.forName("UTF-8"))); > >> Object jsonObject = JsonUtils.fromInputStream(inputStream); > >> JsonLdOptions options = new JsonLdOptions("http://mysite.net"); > >> System.out.println("Base : "+options.getBase()); > >> //Object compact = JsonLdProcessor.compact(jsonObject, null, > >> options); > >> Object compact = JsonLdProcessor.expand(jsonObject, options); > >> System.out.println(JsonUtils.toPrettyString(compact)); > >> } > >> } > >> > >> On Wed, Mar 4, 2020 at 9:44 AM Erich Bremer <er...@ebremer.com> wrote: > >> > >>> I will try with the other library to check. > >>> > >>> On Wed, Mar 4, 2020 at 4:29 AM Rob Vesse <rve...@dotnetrdf.org> wrote: > >>> > >>>> This may be an upstream bug or it could be a bug in how we configure > >>>> the underlying parser > >>>> > >>>> Jena's JSON-LD support is based upon the > >>>> https://github.com/jsonld-java/jsonld-java library so you could try > >>>> and reproduce your test case just using their library directly which > would > >>>> determine if it is their bug or our bug > >>>> > >>>> Rob > >>>> > >>>> On 04/03/2020, 00:11, "Erich Bremer" <er...@ebremer.com> wrote: > >>>> > >>>> I'm trying to use a "@id": "./" in a jsonld file and in another > >>>> triple > >>>> "@id": "picture.jpg". The "./" will be correctly changed to the > >>>> base URL, > >>>> but the "@id": "picture.jpg" just gets dropped and a blank node is > >>>> created. Below is the code segment that I used to generate this > >>>> output: > >>>> { > >>>> "@context": [ > >>>> "http://schema.org" > >>>> ], > >>>> "@graph": [ > >>>> { > >>>> "@type": "CreativeWork", > >>>> "@id": "picture.jpg" > >>>> }, > >>>> { > >>>> "@id": "./", > >>>> "@type": "DataSet" > >>>> } > >>>> ] > >>>> } > >>>> _:Bd42dbcf4e4ffb76e199766bf5e4c1e4b < > >>>> http://www.w3.org/1999/02/22-rdf-syntax-ns#type> < > >>>> http://schema.org/CreativeWork> . > >>>> <http://mydomain.com> < > >>>> http://www.w3.org/1999/02/22-rdf-syntax-ns#type> < > >>>> http://schema.org/DataSet> . > >>>> > >>>> If I use https://json-ld.org/playground/ on the same jsonld, I > get: > >>>> > >>>> <https://json-ld.org/playground/> < > >>>> http://www.w3.org/1999/02/22-rdf-syntax-ns#type> < > >>>> http://schema.org/DataSet> > >>>> . > >>>> <https://json-ld.org/playground/picture.jpg> < > >>>> http://www.w3.org/1999/02/22-rdf-syntax-ns#type> < > >>>> http://schema.org/CreativeWork> . > >>>> > >>>> which is what I expected. Am I missing something here? - Erich > >>>> > >>>> String json = "{\n" + > >>>> " \"@context\": [\n" + > >>>> " \"http://schema.org\"\n" + > >>>> " ],\n" + > >>>> " \"@graph\": [\n" + > >>>> " {\n" + > >>>> " \"@type\": \"CreativeWork\",\n" + > >>>> " \"@id\": \"picture.jpg\"\n" + > >>>> " },\n" + > >>>> " {\n" + > >>>> " \"@id\": \"./\",\n" + > >>>> " \"@type\": \"DataSet\"\n" + > >>>> " }\n" + > >>>> " ]\n" + > >>>> "}"; > >>>> System.out.println(json); > >>>> Model m = ModelFactory.createDefaultModel(); > >>>> InputStream inputStream = new > >>>> ByteArrayInputStream(json.getBytes(Charset.forName("UTF-8"))); > >>>> RDFParser.create() > >>>> .base("http://mydomain.com") > >>>> .source(inputStream) > >>>> .lang(RDFLanguages.JSONLD) > >>>> .parse(m); > >>>> RDFDataMgr.write(System.out, m, RDFFormat.NQUADS) ; > >>>> > >>>> > >>>> > >>>> > >>>> > >>>> >