Package org.openjena.riot.lang

Examples of org.openjena.riot.lang.LangRIOT


        // 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>
        // That would change a lot (Triples came several years before Quads).
       
        if ( lang.isTriples() )
        {
            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) ;
           
            if ( lang.equals(Lang.RDFXML) )
                // Adapter round ARP RDF/XML reader.
                parser = LangRDFXML.create(in, baseURI, filename, errHandler, sink2) ;
            else
                parser = RiotReader.createParserTriples(in, lang, baseURI, sink2) ;
           
            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) ;
            parser = RiotReader.createParserQuads(in, lang, baseURI, sink2) ;
            sink = sink2 ;
        }
       
        // Pending log message having he filename in them.
        // output(filename) ;
        try
        {
            // Default behaviour is "check":
           
            if ( checking )
            {
                if ( parser.getLang() == Lang.NTRIPLES ||  parser.getLang() == Lang.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


    {
        DatasetGraph dsg = DatasetLib.createDatasetGraphMem() ;
        Sink<Quad> sink = RiotLoader.datasetSink(dsg) ;
        Tokenizer tokenizer = TokenizerFactory.makeTokenizerString(string) ;

        LangRIOT parser = RiotReader.createParserQuads(tokenizer, language, baseURI, sink) ;
        try
            parser.parse() ;
        } finally { sink.close() ; }
        return dsg;
    }
View Full Code Here

    public static Graph graphFromString(String string, Lang language, String baseURI)
    {
        Graph g = Factory.createDefaultGraph() ;
        Sink<Triple> sink = graphSink(g) ;
        Tokenizer tokenizer = TokenizerFactory.makeTokenizerString(string) ;
        LangRIOT parser = RiotReader.createParserTriples(tokenizer, language, baseURI, sink) ;
        try {
            parser.parse() ;
        } finally { sink.close() ; }
        return g ;
    }
View Full Code Here

    {
        if ( ! language.isQuads() )
        //if ( language != Lang.NQUADS && language != Lang.TRIG )
            throw new RiotException("Language not supported for quads: "+language) ;
       
        LangRIOT parser = RiotReader.createParserQuads(input, language, baseURI, sink) ;
        parser.parse() ;
        sink.flush() ;
    }
View Full Code Here

    /** Parse an input stream and send the triples to the sink */
    public static void readTriples(InputStream input, Lang language, String baseURI, Sink<Triple> sink)
    {
        if ( ! language.isTriples() )
            throw new RiotException("Language not supported for triples: "+language) ;
        LangRIOT parser = RiotReader.createParserTriples(input, language, baseURI, sink) ;
        parser.parse() ;
        sink.flush();
    }
View Full Code Here

    private Graph parseAsRDFJSON (ByteArrayOutputStream bout)
    {
        ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()) ;
        Graph graph = GraphFactory.createGraphMem() ;
        Sink<Triple> sink = new SinkTriplesToGraph(graph) ;
        LangRIOT parser = RiotReader.createParserRdfJson(bin, sink) ;
        parser.parse() ;
        return graph ;
    }
View Full Code Here

       
        if ( lang.isTriples() )
        {
            InputStream in = IO.openFile(filename) ;
            Sink<Triple> sink2 = new SinkExtendTriplesToQuads(sink) ;
            LangRIOT parser = RiotReader.createParserTriples(in, lang, baseURI, sink2) ;
            parser.parse() ;
            return ;
        }
        else
        {
            InputStream in = IO.openFile(filename) ;
            LangRIOT parser = RiotReader.createParserQuads(in, lang, baseURI, sink) ;
            parser.parse() ;
        }       
    }
View Full Code Here

                   
                    String base = "http://example/upload-base/" ;
                    // We read into a in-memory graph, then (if successful) update the dataset.
                    // This isolates errors.
                    Sink<Triple> sink = new SinkTriplesToGraph(graphTmp) ;
                    LangRIOT parser = RiotReader.createParserTriples(stream, lang, base, sink) ;
                    parser.getProfile().setHandler(errorHandler) ;
                    try {
                        parser.parse() ;
                    }
                    catch (RiotException ex) { errorBadRequest("Parse error: "+ex.getMessage()) ; }
                    finally { sink.close() ; }
                   
                    tripleCount = graphTmp.size() ;
View Full Code Here

    private static DatasetGraph parse(HttpActionREST action, Lang lang, String base, InputStream input)
    {
        Graph graphTmp = GraphFactory.createGraphMem() ;
        Sink<Triple> sink = new SinkTriplesToGraph(graphTmp) ;
        LangRIOT parser = RiotReader.createParserTriples(input, lang, base, sink) ;
        parser.getProfile().setHandler(errorHandler) ;
        try {
            parser.parse() ;
        }
        catch (RiotException ex) { errorBadRequest("Parse error: "+ex.getMessage()) ; }
        finally { sink.close() ; }
        DatasetGraph dsgTmp = DatasetGraphFactory.create(graphTmp) ;
       
View Full Code Here

       
        // TODO Conneg - awiting RIOT code upgrade.
        // WebReader.
        InputStream input = Fuseki.webFileManager.open(uri) ;
       
        LangRIOT parser = RiotReader.createParserTriples(input, lang, uri, sink) ;
        try {
            parser.parse() ;
        } catch (RiotException ex) { throw ex ; }
    }
View Full Code Here

TOP

Related Classes of org.openjena.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.