Search in sources :

Example 21 with Graph

use of org.apache.jena.graph.Graph in project jena by apache.

the class TestAPI method testARQConstructQuad_bnodes.

@Test
public void testARQConstructQuad_bnodes() {
    String queryString = "PREFIX : <http://example/> CONSTRUCT { :s :p :o GRAPH _:a { :s :p :o1 } } WHERE { }";
    Query q = QueryFactory.create(queryString, Syntax.syntaxARQ);
    QueryExecution qExec = QueryExecutionFactory.create(q, d);
    Dataset ds = qExec.execConstructDataset();
    assertEquals(1, Iter.count(ds.asDatasetGraph().listGraphNodes()));
    Node n = ds.asDatasetGraph().listGraphNodes().next();
    assertTrue(n.isBlank());
    Graph g = ds.asDatasetGraph().getGraph(n);
    assertNotNull(g);
    assertFalse(g.isEmpty());
}
Also used : DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Graph(org.apache.jena.graph.Graph) Node(org.apache.jena.graph.Node) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Example 22 with Graph

use of org.apache.jena.graph.Graph in project jena by apache.

the class TestAssemblerGroup method assertMemoryModel.

protected void assertMemoryModel(Object object) {
    if (object instanceof Model) {
        Graph g = ((Model) object).getGraph();
        assertInstanceOf(GraphMemBase.class, g);
    } else
        fail("expected a Model, but got a " + object.getClass());
}
Also used : Graph(org.apache.jena.graph.Graph) InfModel(org.apache.jena.rdf.model.InfModel) Model(org.apache.jena.rdf.model.Model)

Example 23 with Graph

use of org.apache.jena.graph.Graph in project jena by apache.

the class AbstractTripleBlankNodeTests method writeTuples.

@Override
protected void writeTuples(File f, List<Triple> tuples) throws FileNotFoundException {
    Graph g = GraphFactory.createGraphMem();
    for (Triple t : tuples) {
        g.add(t);
    }
    RDFDataMgr.write(new FileOutputStream(f), g, getLanguage());
}
Also used : Triple(org.apache.jena.graph.Triple) Graph(org.apache.jena.graph.Graph) FileOutputStream(java.io.FileOutputStream)

Example 24 with Graph

use of org.apache.jena.graph.Graph in project jena by apache.

the class TestEmbeddedFuseki method embedded_04.

@Test
public void embedded_04() {
    DatasetGraph dsg = dataset();
    Txn.executeWrite(dsg, () -> {
        Quad q = SSE.parseQuad("(_ :s :p _:b)");
        dsg.add(q);
    });
    // A service with just being able to do quads operations
    // That is, GET, POST, PUT on  "/data" in N-quads and TriG. 
    DataService dataService = new DataService(dsg);
    dataService.addEndpoint(OperationName.Quads_RW, "");
    dataService.addEndpoint(OperationName.Query, "");
    dataService.addEndpoint(OperationName.Update, "");
    int port = FusekiLib.choosePort();
    FusekiEmbeddedServer server = FusekiEmbeddedServer.create().setPort(port).add("/data", dataService).build();
    server.start();
    try {
        // Put data in.
        String data = "(graph (:s :p 1) (:s :p 2) (:s :p 3))";
        Graph g = SSE.parseGraph(data);
        HttpEntity e = graphToHttpEntity(g);
        HttpOp.execHttpPut("http://localhost:" + port + "/data", e);
        // Get data out.
        try (TypedInputStream in = HttpOp.execHttpGet("http://localhost:" + port + "/data")) {
            Graph g2 = GraphFactory.createDefaultGraph();
            RDFDataMgr.read(g2, in, RDFLanguages.contentTypeToLang(in.getContentType()));
            assertTrue(g.isIsomorphicWith(g2));
        }
        // Query.
        query("http://localhost:" + port + "/data", "SELECT * { ?s ?p ?o}", qExec -> {
            ResultSet rs = qExec.execSelect();
            int x = ResultSetFormatter.consume(rs);
            assertEquals(3, x);
        });
        // Update
        UpdateRequest req = UpdateFactory.create("CLEAR DEFAULT");
        UpdateExecutionFactory.createRemote(req, "http://localhost:" + port + "/data").execute();
        // Query again.
        query("http://localhost:" + port + "/data", "SELECT * { ?s ?p ?o}", qExec -> {
            ResultSet rs = qExec.execSelect();
            int x = ResultSetFormatter.consume(rs);
            assertEquals(0, x);
        });
    } finally {
        server.stop();
    }
}
Also used : Quad(org.apache.jena.sparql.core.Quad) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Graph(org.apache.jena.graph.Graph) HttpEntity(org.apache.http.HttpEntity) UpdateRequest(org.apache.jena.update.UpdateRequest) ResultSet(org.apache.jena.query.ResultSet) TypedInputStream(org.apache.jena.atlas.web.TypedInputStream) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) DataService(org.apache.jena.fuseki.server.DataService) Test(org.junit.Test)

Example 25 with Graph

use of org.apache.jena.graph.Graph in project jena by apache.

the class TestConnectionPooled method reuseJDBCConection.

@Test
public void reuseJDBCConection() {
    Triple t1 = SSE.parseTriple("(:x1 :p :z)");
    Triple t2 = SSE.parseTriple("(:x2 :p :z)");
    boolean explicitTransactions = false;
    // Make store.
    {
        SDBConnection sConn1 = SDBConnectionFactory.create(conn);
        Store store1 = StoreFactory.create(sConn1, store.getLayoutType(), store.getDatabaseType());
        if (explicitTransactions)
            store1.getConnection().getTransactionHandler().begin();
        Graph graph1 = SDBFactory.connectDefaultGraph(store1);
        graph1.add(t1);
        assertTrue(graph1.contains(t1));
        if (explicitTransactions) {
            store1.getConnection().getTransactionHandler().commit();
            assertTrue(graph1.contains(t1));
        }
    //store1.close() ;
    }
    // Mythically return conn to the pool.
    // Get from pool
    // i.e. same connection.  Make a store around it
    {
        SDBConnection sConn2 = SDBConnectionFactory.create(conn);
        Store store2 = StoreFactory.create(sConn2, store.getLayoutType(), store.getDatabaseType());
        if (explicitTransactions)
            store2.getConnection().getTransactionHandler().begin();
        Graph graph2 = SDBFactory.connectDefaultGraph(store2);
        assertTrue(graph2.contains(t1));
        graph2.add(t2);
        assertTrue(graph2.contains(t2));
        if (explicitTransactions)
            store2.getConnection().getTransactionHandler().commit();
    //store2.close() ;
    }
    System.exit(0);
}
Also used : Triple(org.apache.jena.graph.Triple) Graph(org.apache.jena.graph.Graph) SDBConnection(org.apache.jena.sdb.sql.SDBConnection) Store(org.apache.jena.sdb.Store) Test(org.junit.Test)

Aggregations

Graph (org.apache.jena.graph.Graph)247 Test (org.junit.Test)90 BaseTest (org.apache.jena.atlas.junit.BaseTest)56 Triple (org.apache.jena.graph.Triple)56 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)54 Node (org.apache.jena.graph.Node)46 AbstractTestGraph (org.apache.jena.graph.test.AbstractTestGraph)16 InfGraph (org.apache.jena.reasoner.InfGraph)16 ContractTest (org.xenei.junit.contract.ContractTest)16 Model (org.apache.jena.rdf.model.Model)14 MultiUnion (org.apache.jena.graph.compose.MultiUnion)9 Delta (org.apache.jena.graph.compose.Delta)8 BuilderGraph (org.apache.jena.sparql.sse.builders.BuilderGraph)8 StreamRDF (org.apache.jena.riot.system.StreamRDF)7 PrefixMapping (org.apache.jena.shared.PrefixMapping)7 GraphUnionRead (org.apache.jena.sparql.graph.GraphUnionRead)7 IOException (java.io.IOException)6 Dataset (org.apache.jena.query.Dataset)6 Rule (org.apache.jena.reasoner.rulesys.Rule)6 ConfigTest (org.apache.jena.tdb.ConfigTest)6