2

I have seen some examples where there is a possibility to convert known serializations in RDF/XML but when the input format (e.g. XML/Turtle/N3) is not known, is there any way of achieving the conversion?

I am writing a tool that receives RDF in different serializations (Turtle/xml/n3) but when I call

 model.read(InputStream in, "", "") 

method of Model Class from Jena, there are exceptions.

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
  • 1
    Could you please elaborate? For example: 1) Sample input RDF, 2) how the result RDF looks, and 3) most important - what errors are you getting. Sample code would be nice, too :) – paulsm4 Feb 08 '13 at 18:26
  • @paulsm4 Some typical errors/exceptions: org.xml.sax.SAXParseException: Content is not allowed in prolog & java.lang.NoClassDefFoundError: antlr/TokenStream (Even though the jar is inside the lib & Classpath). 1) My incoming messages from JMS can be any RDF (XML, N3, Turtle). I need to convert any type of incoming messages to RDF/XML in all cases. – Muntazir Mehdi Feb 12 '13 at 21:16

1 Answers1

3

It's an input stream - you have to tell it the format. model.read(in, base, "TURTLE"). It does not sniff the stream. You could do a sequence of model.read each inside a try-catch until one does not cause an exception.

AndyS
  • 16,345
  • 17
  • 21
  • This solution from AndyS seems to work, but what are the compromises in terms of performance. E.g. if i have a list of lang (Turtle, XML, N3) & i iterate over it to create the model each time unless i get one. – Muntazir Mehdi Feb 12 '13 at 21:19