Search in sources :

Example 46 with Dataset

use of org.apache.jena.query.Dataset in project jena by apache.

the class TestDatasetGraphInMemoryBasic method prefixesAreManaged.

@Test
public void prefixesAreManaged() {
    final Node graphName = createURI("http://example/g");
    final DatasetGraph dsg = emptyDataset();
    dsg.addGraph(graphName, createGraphMem());
    final Dataset dataset = DatasetFactory.wrap(dsg);
    Model model = dataset.getNamedModel(graphName.getURI());
    final String testPrefix = "example";
    final String testURI = "http://example/";
    model.setNsPrefix(testPrefix, testURI);
    assertEquals(testURI, model.getNsPrefixURI(testPrefix));
    model.close();
    model = dataset.getNamedModel(graphName.getURI());
    final String nsURI = dataset.getNamedModel(graphName.getURI()).getNsPrefixURI(testPrefix);
    assertNotNull(nsURI);
    assertEquals(testURI, nsURI);
}
Also used : Dataset(org.apache.jena.query.Dataset) SSE.parseNode(org.apache.jena.sparql.sse.SSE.parseNode) NodeFactory.createBlankNode(org.apache.jena.graph.NodeFactory.createBlankNode) Node(org.apache.jena.graph.Node) Model(org.apache.jena.rdf.model.Model) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Test(org.junit.Test)

Example 47 with Dataset

use of org.apache.jena.query.Dataset in project jena by apache.

the class AbstractTestDataset method dataset_01.

@Test
public void dataset_01() {
    Dataset ds = createDataset();
    assertNotNull(ds.getDefaultModel());
    assertNotNull(ds.asDatasetGraph());
}
Also used : Dataset(org.apache.jena.query.Dataset) BaseTest(org.apache.jena.atlas.junit.BaseTest) Test(org.junit.Test)

Example 48 with Dataset

use of org.apache.jena.query.Dataset in project jena by apache.

the class AbstractTestDataset method dataset_03.

@Test
public void dataset_03() {
    Dataset ds = createDataset();
    ds.setDefaultModel(model2);
    assertTrue(model2.isIsomorphicWith(ds.getDefaultModel()));
}
Also used : Dataset(org.apache.jena.query.Dataset) BaseTest(org.apache.jena.atlas.junit.BaseTest) Test(org.junit.Test)

Example 49 with Dataset

use of org.apache.jena.query.Dataset in project jena by apache.

the class AbstractTestDataset method dataset_04.

@Test
public void dataset_04() {
    String graphName = "http://example/";
    Dataset ds = createDataset();
    ds.addNamedModel(graphName, model1);
    assertTrue(ds.containsNamedModel(graphName));
    List<String> x = Iter.toList(ds.listNames());
    assertEquals(1, x.size());
    assertEquals(graphName, x.get(0));
    assertFalse(model1.isIsomorphicWith(ds.getDefaultModel()));
    Model m = ds.getNamedModel(graphName);
    assertNotNull(m);
    assertTrue(model1.isIsomorphicWith(m));
    ds.removeNamedModel(graphName);
    // Not getNamedModel and test for null as some datasets are "auto graph creating"
    assertFalse(ds.containsNamedModel(graphName));
}
Also used : Dataset(org.apache.jena.query.Dataset) Model(org.apache.jena.rdf.model.Model) BaseTest(org.apache.jena.atlas.junit.BaseTest) Test(org.junit.Test)

Example 50 with Dataset

use of org.apache.jena.query.Dataset in project jena by apache.

the class sse_query method exec.

@Override
protected void exec() {
    Op op = modAlgebra.getOp();
    if (op == null) {
        System.err.println("No query expression to execute");
        throw new TerminationException(9);
    }
    Dataset dataset = modDataset.getDataset();
    // Check there is a dataset.
    if (dataset == null)
        dataset = DatasetFactory.createGeneral();
    modTime.startTimer();
    DatasetGraph dsg = dataset.asDatasetGraph();
    if (printOp || printPlan) {
        if (printOp) {
            divider();
            IndentedWriter out = new IndentedWriter(System.out, true);
            op.output(out);
            out.flush();
        }
        if (printPlan) {
            QueryIterator qIter = Algebra.exec(op, dsg);
            Plan plan = new PlanOp(op, null, qIter);
            divider();
            IndentedWriter out = new IndentedWriter(System.out, false);
            plan.output(out);
            out.flush();
        }
    //return ;
    }
    // Do not optimize.  Execute as-is.
    QueryExecUtils.execute(op, dsg, modResults.getResultsFormat());
    long time = modTime.endTimer();
    if (modTime.timingEnabled())
        System.out.println("Time: " + modTime.timeStr(time));
}
Also used : IndentedWriter(org.apache.jena.atlas.io.IndentedWriter) PlanOp(org.apache.jena.sparql.engine.PlanOp) Op(org.apache.jena.sparql.algebra.Op) TerminationException(jena.cmd.TerminationException) QueryIterator(org.apache.jena.sparql.engine.QueryIterator) ModDataset(arq.cmdline.ModDataset) Dataset(org.apache.jena.query.Dataset) PlanOp(org.apache.jena.sparql.engine.PlanOp) Plan(org.apache.jena.sparql.engine.Plan) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

Aggregations

Dataset (org.apache.jena.query.Dataset)138 Test (org.junit.Test)63 BaseTest (org.apache.jena.atlas.junit.BaseTest)39 Model (org.apache.jena.rdf.model.Model)31 Resource (org.apache.jena.rdf.model.Resource)20 Node (org.apache.jena.graph.Node)13 RDFNode (org.apache.jena.rdf.model.RDFNode)8 UpdateBuilder (org.apache.jena.arq.querybuilder.UpdateBuilder)7 RDFConnection (org.apache.jena.rdfconnection.RDFConnection)7 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)7 ConfigTest (org.apache.jena.tdb.ConfigTest)7 CmdException (jena.cmd.CmdException)6 Graph (org.apache.jena.graph.Graph)6 SelectBuilder (org.apache.jena.arq.querybuilder.SelectBuilder)5 JenaTransactionException (org.apache.jena.sparql.JenaTransactionException)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 Path (java.nio.file.Path)4 Property (org.apache.jena.rdf.model.Property)4 OutputStream (java.io.OutputStream)3 Triple (org.apache.jena.graph.Triple)3