json-ld parsing

35 views
Skip to first unread message

rdf 4j

unread,
May 20, 2021, 3:22:12 PM5/20/21
to RDF4J Users
Hi there, i try to parse this json-ld:

https://presdecheznous.gogocarto.fr/api/elements.jsonld?limit=1

   StringReader sr = new StringReader(body);
   Model model = Rio.parse(sr, RDFFormat.JSONLD);
   StringWriter sw = new StringWriter();
   Rio.write(model, sw, RDFFormat.TURTLE );
   System.out.println(sw.toString());

Output is only that:

@prefix geog: <http://www.w3.org/2003/01/geo/wgs84_pos#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix schema: <http://schema.org/> .
@prefix dct: <http://purl.org/dc/terms/> .
@prefix dbpedia: <http://dbpedia.org/resource/> .

_:genid-aa13bb8320f140ccbced9eff55868e48-b0 schema:addressCountry "FR";
  schema:addressLocality "Sainte-marie";
  schema:postalCode "97438";
  schema:streetAddress "461, rue Pointe Allisard" .

_:genid-aa13bb8320f140ccbced9eff55868e48-b1 geog:lat -2.089299E1;
  geog:long 5.552815E1 .


I didn't understand this json-ld thing, no matter where i meet it, it makes trouble ;-)


Can anybody see, if the input is wrong or if the parser has a problem?
Thanks


Jeen Broekstra

unread,
May 20, 2021, 7:38:05 PM5/20/21
to RDF4J Users
There's a couple of things wrong with the JSON-LD document, and they mostly have to do with how it uses an externally defined context (at https://rawgit.com/jmvanel/rdf-convert/master/context-gogo.jsonld ).

The first problem is that there is no base URI specified in the document itself. There is a @base directive set in the external context, but this is ignored by the parser (this is intended behavior, not a bug - see https://www.w3.org/TR/json-ld11/#base-iri).

Not having a base URI is not an error in itself, but it means that if you parse the document as you do (by just parsing the document as a string input without supplying a base URI yourself), none of the relative identifiers (such as "id" : "AEP") will resolve to full IRIs. You can fix this by doing this:

Model model = Rio.parse(sr, "http://example.org/base/uri/", RDFFormat.JSONLD);

...where of course the base URI should be something sensible (you could use the original URL of the document as its value, or perhaps the value of the @base directive set in the external context). 

The second problem is that a lot of the properties used in the document are not mapped to identifiers in the context.  The document uses properties such as "name" and "categories", the context contains no mapping for them. Therefore the parser will not be able to transform these properties into RDF statements, and this is why those do not show up in your output.

Cheers,

Jeen
--
You received this message because you are subscribed to the Google Groups "RDF4J Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rdf4j-users...@googlegroups.com.

Jerven Bolleman

unread,
May 21, 2021, 12:33:04 PM5/21/21
to rdf4j...@googlegroups.com
Hi,

I think the JSON-LD is correct, and a number of expected triples is not being generated.
Could you open a github issue please?

Regards,
Jerven

PS. I agree JSON-LD is really quite hard to translate mentally to triples.

--
You received this message because you are subscribed to the Google Groups "RDF4J Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rdf4j-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rdf4j-users/f8de64b9-ea7f-4f5e-996a-ea903b0390c2n%40googlegroups.com.


--
Jerven Bolleman
m...@jerven.eu

rdf 4j

unread,
May 22, 2021, 1:19:42 PM5/22/21
to RDF4J Users
Thanks!
Hope that is ok: https://github.com/eclipse/rdf4j/issues/3064
If anything is missing, let me know.
Fredy
Reply all
Reply to author
Forward
0 new messages