18

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).

Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
Akku
  • 4,373
  • 4
  • 48
  • 67
  • This is a good, clear, question, but it's probably off-topic for StackOverflow, as "Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it." You might have better luck with it on http://answers.semanticweb.com, though, as it already has a number of questions about JSON-LD and how to write it, &c. – Joshua Taylor Sep 05 '13 at 12:09
  • I got into contact with the creator of the website, which is basically a Python tool on AppEngine. He told me that the problem was the upload time timeout of Google App Engine and that the best route would be to try to use it on my local system. I did exactly that. Now the upload to the localhost app works, but the response that should get written to my filesystem is too big. I'll check out what I can do about that tomorrow, or if I can just change the code to have it write the JSON-LD response into a file instead. Joshua: I don't think this will attract spam, there's nothing usable out there. – Akku Sep 05 '13 at 15:46
  • I agree that it's not likely to attract much spam, but it's certainly a request to "recommend or find a tool, library or favorite off-site resource". At any rate, searching for JSON-LD on answers.semanticweb.com finds a number of similar questions with answers pointing to different JSON-LD libraries. The website of the tool that you're using also mentions what it's using: "rdflib-rdfjson for RDF/JSON, and rdflib-jsonld for parsing and serializing JSON-LD". – Joshua Taylor Sep 05 '13 at 15:52
  • As a suggestion for a question, you could post the issue with getting the response written to disk as a question, and if you've solved it, post the answer. That might help future users in the same situation. – Joshua Taylor Sep 05 '13 at 15:54
  • Didn't get to the task today, but will improve the question as soon as I know more. – Akku Sep 06 '13 at 14:47
  • See [similar question on answers.semanticweb.com](http://answers.semanticweb.com/questions/28966/big-rdfxml-file-to-json-ld) for some additional recommendations. – Jeen Broekstra Jul 05 '14 at 08:17
  • Take a look at http://stackoverflow.com/questions/42910063 and http://stackoverflow.com/questions/43638342 for a java solution – jschnasse May 19 '17 at 08:55

3 Answers3

15

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')
Ming Chan
  • 1,938
  • 11
  • 21
  • 1
    This can also be done with http://rdflib.readthedocs.org/en/latest/apidocs/rdflib.tools.html#module-rdflib.tools.rdfpipe at the command line: http://manpages.ubuntu.com/manpages/trusty/man1/rdfpipe.1.html – Wes Turner Sep 30 '14 at 23:41
5

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.

Akku
  • 4,373
  • 4
  • 48
  • 67
3

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...
Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
  • I'll try that, sounds like a good answer. I'll report back when I've tried. – Akku Sep 05 '13 at 15:45
  • @Akku OK, but like I said at the beginning, this produces RDF/JSON, _not_ JSON-LD. They are _not_ the same thing. However, apparently, there [has been work](http://mail-archives.apache.org/mod_mbox/jena-dev/201303.mbox/%3C513248F7.5010803@apache.org%3E) on JSON-LD support in Jena. – Joshua Taylor Sep 05 '13 at 15:46
  • best answer... Use Jena. 1) download; 2) prepare termonal env with https://jena.apache.org/documentation/tools/ – Peter Krauss Sep 21 '17 at 06:34
  • 2
    `rdfcat` **UPDATING** for 2017, as terminal shows, *"DEPRECATED: Please use riot instead"*... So, with `riot` (see `--help`) you can use JSON-LD, see `.jsonld` extension at http://jena.apache.org/documentation/io/#formats – Peter Krauss Sep 21 '17 at 06:37