Package org.apache.jena.riot.lang

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


            public void flush() {}
            String formatNode(Node n) { return FmtUtils.stringForNode(n, sCxt) ; }
        } ;

        StreamRDF dest = StreamRDFLib.sinkQuads(sink) ;
        LangRIOT parser = RiotReader.createParser(tokenizer, language, null, dest) ;
        // Don't resolve IRIs.  Do checking.
        parser.setProfile(RiotLib.profile(null, false, true, errorHandler)) ;
        return parser ;
    }
View Full Code Here


        // else use NodeToLabel.createBNodeByLabel() ;
        // Also, as URI.
        final boolean labelsAsGiven = false ;
       
        SinkCounting<?> sink ;
        LangRIOT parser ;
       
        NodeToLabel labels = SyntaxLabels.createNodeToLabel() ;
        if ( labelsAsGiven )
            labels = NodeToLabel.createBNodeByLabelEncoded() ;
       
        // Uglyness because quads and triples aren't subtype of some Tuple<Node>
        // Replace with StreamRDF all the way through.
       
        if ( RDFLanguages.isTriples(lang) )
        {
            Sink<Triple> s = SinkNull.create() ;
            if ( ! modLangParse.toBitBucket() )
                s = new SinkTripleOutput(output, null, labels) ;
            if ( setup != null )
                s = InfFactory.infTriples(s, setup) ;
           
            SinkCounting<Triple> sink2 = new SinkCounting<Triple>(s) ;
            StreamRDF dest = StreamRDFLib.sinkTriples(sink2) ;
            parser = RiotReader.createParser(in, lang, baseURI, dest) ;
           
            sink = sink2 ;
        }
        else
        {
            Sink <Quad> s = SinkNull.create() ;
            if ( ! modLangParse.toBitBucket() )
                s = new SinkQuadOutput(output, null, labels) ;
            if ( setup != null )
                s = InfFactory.infQuads(s, setup) ;
           
            SinkCounting<Quad> sink2 = new SinkCounting<Quad>(s) ;
            StreamRDF dest = StreamRDFLib.sinkQuads(sink2) ;
            parser = RiotReader.createParser(in, lang, baseURI, dest) ;
            sink = sink2 ;
        }
       
        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 ( RDFLanguages.isTriples(lang) )
        {
            InputStream in = IO.openFile(filename) ;
            sink = StreamRDFLib.extendTriplesToQuads(sink) ;
            LangRIOT parser = RiotReader.createParser(in, lang, baseURI, sink) ;
            parser.parse() ;
            return ;
        }
        else
        {
            InputStream in = IO.openFile(filename) ;
            LangRIOT parser = RiotReader.createParser(in, lang, baseURI, sink) ;
            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) ;
       
        // 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

    {
        // 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

                        lang = RDFLanguages.RDFXML ;

                    // We read into a in-memory graph, then (if successful) update the dataset.
                    // This isolates errors.
                    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

   
    protected void parse(StreamRDF sink, String... strings )
    {
        String string = StrUtils.strjoin("\n", strings) ;
        Tokenizer tokenizer = tokenizer(string) ;
        LangRIOT parser = createParser(tokenizer(string), sink) ;
        parser.getProfile().setHandler(new ErrorHandlerEx()) ;
        parser.parse() ;
    }
View Full Code Here

    final protected void parseCheck(String... strings)
    {
        String string = StrUtils.strjoin("\n", strings) ;
        Tokenizer tokenizer = tokenizer(string) ;
        RDFParserOutputCounting sink = StreamRDFLib.count() ;
        LangRIOT x = RiotReader.createParserNQuads(tokenizer, sink) ;
        x.setProfile(RiotLib.profile(null, false, true, new ErrorHandlerEx())) ;
        x.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

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.