Package com.hp.hpl.jena.graph

Examples of com.hp.hpl.jena.graph.Graph


        return graph ;
    }
   
    private static Graph data(Triple... triples)
    {
        Graph graph = Factory.createDefaultGraph();
        graph.getBulkUpdateHandler().add(triples);
        return graph;
    }
View Full Code Here


   
    @Test public void graph_03()
    {
        Node g = Node.createURI("g") ;
        DatasetGraph dsg = emptyDataset() ;
        Graph data = SSE.parseGraph("(graph (<s> <p> <o>))") ;
        dsg.addGraph(g, data) ;
        Quad quad = SSE.parseQuad("(quad <g> <s> <p> <o>)") ;
        assertTrue(dsg.contains(quad)) ;
    }
View Full Code Here

                InputStream instream = entity.getContent() ;
//                String mimeType = ConNeg.chooseContentType(request, rdfOffer, ConNeg.acceptRDFXML).getAcceptType() ;
//                String charset = ConNeg.chooseCharset(request, charsetOffer, ConNeg.charsetUTF8).getAcceptType() ;
                ts = new TypedInputStream(instream, contentType, charset) ;
            }
            Graph graph = GraphFactory.createGraphMem() ;
            if ( processBody )
                readGraph(graph, ts, null) ;
            if ( ts != null )
                ts.close() ;
            Graph graph2 = new UnmodifiableGraph(graph) ;
            return graph2 ;
        } catch (IOException ex)
        {
            httpRequest.abort() ;
            return null ;
View Full Code Here

{
    // ---- Model level
   
    public static Model readModel(String uri, int limit)
    {
        Graph g = Factory.createGraphMem() ;
        readUtil(g, uri, limit) ;
        return ModelFactory.createModelForGraph(g) ;
    }
View Full Code Here

        return ModelFactory.createModelForGraph(g) ;
    }
   
    public static void loadModel(Model model, String uri, int limit)
    {
        Graph g = model.getGraph() ;
        readUtil(g, uri, limit) ;
    }
View Full Code Here

    // ---- Graph level
   
    public static Graph readGraph(String uri, int limit)
    {
        Graph g = Factory.createGraphMem() ;
        readUtil(g, uri, limit) ;
        return g ;
    }
View Full Code Here

       
        ServletFileUpload upload = new ServletFileUpload();
        // Locking only needed over the insert into dataset
        try {
            String graphName = null ;
            Graph graphTmp = GraphFactory.createGraphMem() ;
            Node gn = null ;
            String name = null
            ContentType ct = null ;
            Lang lang = null ;
            int tripleCount = 0 ;
           
            FileItemIterator iter = upload.getItemIterator(request);
            while (iter.hasNext()) {
                FileItemStream item = iter.next();
                String fieldName = item.getFieldName();
                InputStream stream = item.openStream();
                if (item.isFormField())
                {
                    // Graph name.
                    String value = Streams.asString(stream, "UTF-8") ;
                    if ( fieldName.equals(HttpNames.paramGraph) )
                    {
                        graphName = value ;
                        if ( graphName != null && ! graphName.equals(HttpNames.valueDefault) )
                        {
                            IRI iri = IRIResolver.parseIRI(value) ;
                            if ( iri.hasViolation(false) )
                                errorBadRequest("Bad IRI: "+graphName) ;
                            if ( iri.getScheme() == null )
                                errorBadRequest("Bad IRI: no IRI scheme name: "+graphName) ;
                            if ( iri.getScheme().equalsIgnoreCase("http") || iri.getScheme().equalsIgnoreCase("https"))
                            {
                                // Redundant??
                                if ( iri.getRawHost() == null )
                                    errorBadRequest("Bad IRI: no host name: "+graphName) ;
                                if ( iri.getRawPath() == null || iri.getRawPath().length() == 0 )
                                    errorBadRequest("Bad IRI: no path: "+graphName) ;
                                if ( iri.getRawPath().charAt(0) != '/' )
                                    errorBadRequest("Bad IRI: Path does not start '/': "+graphName) ;
                            }
                            gn = Node.createURI(graphName) ;
                        }
                    }
                    else if ( fieldName.equals(HttpNames.paramDefaultGraphURI) )
                        graphName = null ;
                    else
                        // Add file type?
                        log.info(format("[%d] Upload: Field="+fieldName+" - ignored")) ;
                } else {
                    // Process the input stream
                    name = item.getName() ;
                    if ( name == null || name.equals("") || name.equals("UNSET FILE NAME") )
                        errorBadRequest("No name for content - can't determine RDF syntax") ;
                   
                    String contentTypeHeader = item.getContentType() ;
                    ct = ContentType.parse(contentTypeHeader) ;
                   
                    lang = FusekiLib.langFromContentType(ct.getContentType()) ;
                    if ( lang == null )
                        lang = Lang.guess(name) ;
                    if ( lang == null )
                        // Desperate.
                        lang = Lang.RDFXML ;
                   
                    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() ;
                    //DatasetGraph dsgTmp = DatasetGraphFactory.create(graphTmp) ;
                }
            }   
               
            if ( graphName == null )
View Full Code Here

            { super( name ); }
   
        @Override
        public Graph getGraph()
            {
            Graph base = Factory.createDefaultGraph();           
            return new ReificationWrapperGraph( base, ReificationStyle.Standard );
            }
View Full Code Here

    protected static void clearGraph(Target target)
    {
        if ( ! target.isGraphSet() )
        {
            Graph g = target.graph() ;
            g.getBulkUpdateHandler().removeAll() ;
        }
    }
View Full Code Here

    }

    protected static void addDataInto(Graph data, HttpActionREST action)
    {  
        Target dest = action.getTarget() ;
        Graph g = dest.graph() ;
        if ( g == null )
        {
            if ( dest.isDefault )
                errorOccurred("Dataset does not have a default graph") ;
            log.info(format("[%d] Creating in-memory graph for <%s>", action.id, dest.graphName)) ;
            // Not default graph.
            // Not an autocreate dataset - create something.
            g = GraphFactory.createDefaultGraph() ;
            dest.dsg.addGraph(dest.graphName, g) ;
        }
        g.getBulkUpdateHandler().add(data) ;
    }
View Full Code Here

TOP

Related Classes of com.hp.hpl.jena.graph.Graph

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.