Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Controlling conversion of RDF to "prettier" JSON-LD

I'm aware that conversion of RDF to JSON-LD has some limitations, but I wonder if there is a good way of making the conversion avoid use of blank nodes?

For example, given an 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 enforce conversion to an array-based representation of the bnodes:

{
  "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"
  }
}

Rather than 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'm iterating over the statements in the graph and manually producing the JSON, but is it at all possible to do this using libraries like java-jsonld or some other JSON-LD technique?

like image 663
brinxmat Avatar asked Sep 25 '22 06:09

brinxmat


1 Answers

You can use framing to achieve that. Have a look at the library example in the JSON-LD playground. Unfortunately it is not standardized yet so various implementations may not produce exactly the same output and/or super different features

like image 175
Markus Lanthaler Avatar answered Oct 11 '22 17:10

Markus Lanthaler