Search in sources :

Example 56 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 57 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 58 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 59 with Graph

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

the class DatasetGraphAccessorBasic method httpDelete.

@Override
public void httpDelete(Node graphName) {
    Graph ng = dataset.getGraph(graphName);
    if (ng == null)
        return;
    dataset.removeGraph(graphName);
// clearGraph(ng) ;
}
Also used : DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Graph(org.apache.jena.graph.Graph)

Example 60 with Graph

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

the class DatasetGraphAccessorBasic method httpPost.

@Override
public void httpPost(Node graphName, Graph data) {
    Graph ng = dataset.getGraph(graphName);
    if (ng == null) {
        dataset.addGraph(graphName, data);
        return;
    }
    mergeGraph(ng, data);
}
Also used : DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Graph(org.apache.jena.graph.Graph)

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