Managing the conversion of RDF to prettier JSON-LD

I know that converting RDF to JSON-LD has some limitations, but I am wondering if there is a good way to do the conversion without using empty nodes?

For example, given the RDF graph:

@prefix ex: <http://example.org/ontology#> . <http://example.org/x123> ex:house [ a ex:House ; ex:houseNumber "1a" ; ex:doorColour "blue" ] ; ex:house [ a ex:House ; ex:houseNumber "1b" ; ex:doorColour "green" ] . 

Is it possible using (Java) JSON-LD to force conversion to an array-based bnodes view:

 { "id": "http://example.org/x123", "house": [{ "type": "House", "houseNumber": "1a", "doorColour": "blue" }, { "type": "House", "houseNumber": "1b", "doorColour": "green" }], "@context": { "ex": "http://example.org/ontology#", "house": "ex:house", "houseNumber": "ex:houseNumber", "doorColour": "ex:doorColour", "House": "ex:House", "id": "@id", "type": "@type" } } 

Instead of something like:

 { "@graph": [ { "@id": "_:b0", "@type": "http://example.org/ontology#House", "http://example.org/ontology#doorColour": "blue", "http://example.org/ontology#houseNumber": "1a" }, { "@id": "_:b1", "@type": "http://example.org/ontology#House", "http://example.org/ontology#doorColour": "green", "http://example.org/ontology#houseNumber": "1b" }, { "@id": "http://example.org/x123", "http://example.org/ontology#house": [ { "@id": "_:b0" }, { "@id": "_:b1" } ] } ] } 

At the moment, I am repeating the instructions on the chart and manually creating JSON, but is it possible to do this using libraries such as java-jsonld or some other JSON-LD method?

+5
source share
1 answer

You can use crop to achieve this. See an example library on the JSON-LD playground. Unfortunately, it is not yet standardized, so different implementations may not create exactly the same output and / or super-different functions.

+4
source

Source: https://habr.com/ru/post/1243859/


All Articles