This is a lot more elegant. Thanks for the suggestion.

Praveen

On Tue, May 17, 2016, 1:42 AM Andy Seaborne <[email protected]> wrote:

> On 16/05/16 18:25, Praveen Balaji wrote:
> > Thanks Andy. Yes, I need to handle warnings because part of my use case
> is
> > to exit on malformed subjects, even if that doesn't mean a malformed TTL.
> >
> > I'll try it out. I was hoping I don't have to use a low-level API :)
>
> Rather than hook into the parser process itself, a different design is
> to create processing pipeline.
>
> Parsers send their output to a StreamRDF.
>
>     RDFDatMgr.parse(StreamRDF sink, String uri, Lang lang)
>
> A StreamRDF is an interface for a processing pipeline. StreamRDFLib has
> helpers for StreamRDF to put data into graphs and datasets.
>
> You could write a StreamRDF that checks the triples going though and
> send them onto to another StreamRDF (inherit from StreamRDFWrapper).
> Then you can customize the checking (e.g. subjects only, make then
> errors, whatever).  And it works for N-Triples that usually runs with
> minimal checking.
>
> The checking of IRIs is done by org.apache.jena.riot.system.IRIResolver.
>
> One thing - IRI parsing is a noticable cost - it is worth having a
> cache. See CheckerIRI.
>
> URIs in code repeat a lot across triples.
>
>      Andy
>
>
> >
> > Cheers
> > Praveen
> >
> > On Mon, May 16, 2016, 10:08 AM Andy Seaborne <[email protected]> wrote:
> >
> >> On 16/05/16 15:02, Praveen Balaji wrote:
> >>> Hi all
> >>> I'm trying to read from Turtle file using Jena Riot API. My input had a
> >>> malformed subject URI and the application exited without an exception.
> I
> >>> configured log4j and I was able to then see an error message.
> >>>
> >>> Is there a way to configure an error handler on the parser so I am
> >> notified
> >>> of errors and can handle them as needed?
> >>>
> >>> Thanks
> >>>
> >>
> >> Is the logging output saying its warning?
> >>
> >> A Turtle syntax error causes the parser to throw an exception. A warning
> >> is note that a URI is not good as per the RFCs but it is not a syntax
> >> error so the parser continues.
> >>
> >> If you really want warnings passed out - set the error handler via the
> >> low level APIs:
> >>
> >>         InputStream in = .... ;
> >>         StreamRDF dest = StreamRDFLib.graph(model.getGraph()) ;
> >>         ReaderRIOT r = RDFDataMgr.createReader(Lang.TTL) ;
> >>         r.setErrorHandler(null) ;
> >>         r.read(in, null, null, dest, null) ;
> >>          // data in the model.
> >>
> >>          Andy
> >>
> >>
> >
>
>

Reply via email to