Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert or translate a big RDF/XML file to JSON-LD format - HOW?

Tags:

json

rdf

json-ld

I need to convert this 40MB file of RDF/XML to the JSON-LD format and I've only found this web tool, that doesn't work at all. When you paste 40MB of text, it crashes, and when you give it the URL of the file, it says that the service isn't available.

In theory the Jena API, or maybe Sesame should be able to do this, but I'm missing a starting point and the knowledge about these systems. Can someone give me a route, an example or a link to useful documentation for translating a big RDF/XML into JSON-LD?

(I'd be happy with Java, C# or a working solution where I don't need too much programming knowledge in another language / framework).

like image 370
Akku Avatar asked Sep 05 '13 08:09

Akku


People also ask

Is JSON an RDF LD?

Differences with RDF In JSON-LD properties can be IRIs or blank nodes whereas in RDF properties (predicates) have to be IRIs. This means that JSON-LD serializes generalized RDF Datasets. In JSON-LD lists are part of the data model whereas in RDF they are part of a vocabulary, namely [RDF11-SCHEMA].


3 Answers

You can just use RDFLib to read in RDF in RDF/XML format and the serialize it back to JSON-LD using the json-ld serializer

graph.parse(my_url, format='application/rdf+xml')


graph.serialize(my_url, format='application/json-ld')
like image 119
Ming Chan Avatar answered Oct 23 '22 17:10

Ming Chan


I did it using this tool: http://rdf-translator.appspot.com/

Sadly, upload- / download sizes were too big, so I got the code from here and ran it on a local Google App Engine from here on port 8999. Then I went to the directory with the owl file 'ds.owl' and used the following command to get it into the ds.json file:

curl --data-urlencode content@eclass_514en.owl http://localhost:8999/convert/detect/json-ld/content > ds.json

This was the only thing that worked, and I tried it with about 4 bigger ontology files.

like image 5
Akku Avatar answered Oct 23 '22 16:10

Akku


I don't know that the Jena API supports JSON-LD, but it supports RDF/JSON, a direct encoding of the RDF triples. You could use the Jena API, but a more convenient way to do this with Jena is using the Jena command line rdfcat tool. The help menu produced by the --help option is a bit out of date, but looks like this:

$ rdfcat --help
Usage: java jena.rdfcat (option|input)*
Concatenates the contents of zero or more input RDF documents.
Options: -out N3 | N-TRIPLE | RDF/XML | RDF/XML-ABBREV
         -n  expect subsequent inputs in N3 syntax
         -x  expect subsequent inputs in RDF/XML syntax
         -t  expect subsequent inputs in N-TRIPLE syntax
         -[no]include  include rdfs:seeAlso and owl:imports
input can be filename, URL, or - for stdin
Recognised aliases for -n are: -n3 -ttl or -N3
Recognised aliases for -x are: -xml -rdf or -rdfxml
Recognised aliases for -t are: -ntriple
Output format aliases: x, xml or rdf for RDF/XML, n, n3 or ttl for N3, t or ntriple for N-TRIPLE
See the Javadoc for jena.rdfcat for additional details.

What you'd want to know in addition to that is that you can pass the output format RDF/JSON. Using the well known Pizza ontology, for instance, we get:

$ rdfcat -out RDF/JSON ../sparql-pizza2/pizza.owl  | head -25
{ 
  "_:-b8ef06:140ee02a0b1:-7ff7" : { 
    "http://www.w3.org/1999/02/22-rdf-syntax-ns#rest" : [ { 
      "type" : "uri" ,
      "value" : "http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"
    }
     ] ,
    "http://www.w3.org/1999/02/22-rdf-syntax-ns#first" : [ { 
      "type" : "uri" ,
      "value" : "http://www.co-ode.org/ontologies/pizza/pizza.owl#TomatoTopping"
    }
     ]
  }
   ,
  "http://www.co-ode.org/ontologies/pizza/pizza.owl#Food" : { 
    "http://www.w3.org/2000/01/rdf-schema#subClassOf" : [ { 
      "type" : "uri" ,
      "value" : "http://www.co-ode.org/ontologies/pizza/pizza.owl#DomainConcept"
    }
     ] ,
    "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" : [ { 
      "type" : "uri" ,
      "value" : "http://www.w3.org/2002/07/owl#Class"
    }
     ]
...and so on...
like image 3
Joshua Taylor Avatar answered Oct 23 '22 17:10

Joshua Taylor