Package org.apache.jena.riot.lang

Examples of org.apache.jena.riot.lang.LangRIOT


            errorHandler = ErrorHandlerFactory.getDefaultErrorHandler() ;
        }

        @Override
        public void read(InputStream in, String baseURI, ContentType ct, StreamRDF output, Context context) {
            @SuppressWarnings("deprecation")
            LangRIOT parser = RiotReader.createParser(in, lang, baseURI, output) ;
            if ( parserProfile != null )
                parser.setProfile(parserProfile);
            if ( errorHandler != null )
                parser.getProfile().setHandler(errorHandler) ;
            parser.parse() ;
        }
View Full Code Here


            parser.parse() ;
        }

        @Override
        public void read(Reader in, String baseURI, ContentType ct, StreamRDF output, Context context) {
            @SuppressWarnings("deprecation")
            LangRIOT parser = RiotReader.createParser(in, lang, baseURI, output) ;
            parser.getProfile().setHandler(errorHandler) ;
            parser.parse() ;
        }
View Full Code Here

        String baseURI = "http://example/base" ;
           
        // It is always better to use an  InputStream, rather than a Java Reader.
        // The parsers will do the necessary character set conversion. 
        in = new FileInputStream("data.trig") ;
        LangRIOT parser = RiotReader.createParser(in, RDFLanguages.TRIG, "http://example/base", noWhere) ;
       
        // Access the setup of the RIOT built-in parsers.
       
        // Parser to first error or warning.
        ErrorHandler errHandler = ErrorHandlerFactory.errorHandlerStrict ;

        // Now enable stricter checking, even N-TRIPLES must have absolute URIs.
        ParserProfile profile = RiotLib.profile(baseURI, true, true, errHandler) ;

        // Just set the error handler.
        parser.getProfile().setHandler(errHandler) ;
       
        // Or replace the whole parser profile.
        parser.setProfile(profile) ;

        // Do the work.
        parser.parse() ;
    }
View Full Code Here

        {
            return new ReaderRIOT() {
                @Override
                public void read(InputStream in, String baseURI, ContentType ct, StreamRDF output, Context context)
                {
                    LangRIOT parser = RiotReader.createParser(in, lang, baseURI, output) ;
                    parser.parse() ;
                }
            } ;
        }
View Full Code Here

    {
        // Not as good as from an InputStream - RDF/XML not supported
        ContentType ct = determineCT(base, null, lang) ;
        if ( ct == null )
            throw new RiotException("Failed to determine the triples content type: (URI="+base+" : hint="+lang+")") ;
        LangRIOT parser ;
        if ( lang == null )
            throw new RiotException("No language specificied") ;

        if ( RDFLanguages.sameLang(RDFLanguages.RDFXML, lang) )
            parser = LangRDFXML.create(in, base, base, ErrorHandlerFactory.errorHandlerStd, output) ;
        else
        {
            Tokenizer tokenizer =
                RDFLanguages.RDFJSON.equals(lang)?
                              new TokenizerJSON(PeekReader.make(in)) :  
                              TokenizerFactory.makeTokenizer(in) ;
            parser = RiotReader.createParser(tokenizer, lang, base, output) ;
        }
        parser.parse() ;
    }
View Full Code Here

   
    // java.io.Readers are NOT preferred.
    private static void process(StreamRDF dest, String base, Reader in, Lang hintLang, Context context)
    {
        Tokenizer tokenizer = TokenizerFactory.makeTokenizer(in) ;
        LangRIOT parser = RiotReader.createParser(tokenizer, hintLang, base, dest) ;
        parser.parse() ;
    }
View Full Code Here

            s = InfFactory.inf(s, setup) ;
        StreamRDFCounting sink = StreamRDFLib.count(s) ;
        s = null ;
       
        // Need low level control over the parser.
        LangRIOT parser = RiotReader.createParser(in, lang, baseURI, sink) ;
        try
        {
            if ( checking )
            {
                if ( parser.getLang() == RDFLanguages.NTRIPLES ||  parser.getLang() == RDFLanguages.NQUADS )
                    parser.setProfile(RiotLib.profile(baseURI, false, true, errHandler)) ;
                else
                    parser.setProfile(RiotLib.profile(baseURI, true, true, errHandler)) ;
            }
            else
                parser.setProfile(RiotLib.profile(baseURI, false, false, errHandler)) ;
           
            if ( labelsAsGiven )
                parser.getProfile().setLabelToNode(LabelToNode.createUseLabelAsGiven()) ;
            modTime.startTimer() ;
            parser.parse() ;
        }
        catch (RiotException ex)
        {
            // Should have handled the exception and logged a message by now.
            //System.err.println("++++"+ex.getMessage());
View Full Code Here

                    if ( lang == null )
                        // Desperate.
                        lang = RDFLanguages.RDFXML ;

                    StreamRDF dest = StreamRDFLib.graph(graphDst) ;
                    LangRIOT parser = RiotReader.createParser(stream, lang, base, dest) ;
                    parser.getProfile().setHandler(errorHandler) ;
                    log.info(format("[%d] Upload: Filename: %s, Content-Type=%s, Charset=%s => %s",
                                    action.id, name,  ct.getContentType(), ct.getCharset(), lang.getName())) ;
                    try { parser.parse() ; }
                    catch (RiotException ex) { errorBadRequest("Parse error: "+ex.getMessage()) ; }
                }
            }   

            if ( graphName == null )
View Full Code Here

    private static DatasetGraph parse(HttpActionREST action, Lang lang, String base, InputStream input)
    {
        Graph graphTmp = GraphFactory.createGraphMem() ;
       
        StreamRDF dest = StreamRDFLib.graph(graphTmp) ;
        LangRIOT parser = RiotReader.createParser(input, lang, base, dest) ;
        parser.getProfile().setHandler(errorHandler) ;
        try { parser.parse() ; }
        catch (RiotException ex) { errorBadRequest("Parse error: "+ex.getMessage()) ; }
        DatasetGraph dsgTmp = DatasetGraphFactory.create(graphTmp) ;
        return dsgTmp ;
    }
View Full Code Here

        action.beginWrite() ;
        try {
            String name = action.request.getRequestURL().toString() ;
            DatasetGraph dsg = action.getActiveDSG() ;
            StreamRDF dest = StreamRDFLib.dataset(dsg) ;
            LangRIOT parser = RiotReader.createParser(action.request.getInputStream(), lang, name , dest) ;
            parser.parse() ;
            action.commit();
            success(action) ;
        } catch (IOException ex) { action.abort() ; }
        finally { action.endWrite() ; }
    }
View Full Code Here

TOP

Related Classes of org.apache.jena.riot.lang.LangRIOT

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.