Search in sources :

Example 91 with Dataset

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

the class TestDatasetTDBPersist method dataset4.

@Test
public void dataset4() {
    String graphName = "http://example/";
    Triple triple = SSE.parseTriple("(<x> <y> <z>)");
    Node gn = org.apache.jena.graph.NodeFactory.createURI(graphName);
    Dataset ds = graphLocation.getDataset();
    // ?? See TupleLib.
    ds.asDatasetGraph().deleteAny(gn, null, null, null);
    Graph g2 = ds.asDatasetGraph().getGraph(gn);
    //        if ( true )
    //        {
    //            PrintStream ps = System.err ;
    //            ps.println("Dataset names: ") ;
    //            Iter.print(ps, ds.listNames()) ;
    //        }
    // Graphs only exists if they have a triple in them
    assertFalse(ds.containsNamedModel(graphName));
    List<String> names = Iter.toList(ds.listNames());
    assertEquals(0, names.size());
    assertEquals(0, ds.asDatasetGraph().size());
}
Also used : Triple(org.apache.jena.graph.Triple) Graph(org.apache.jena.graph.Graph) Dataset(org.apache.jena.query.Dataset) Node(org.apache.jena.graph.Node) Test(org.junit.Test) ConfigTest(org.apache.jena.tdb.ConfigTest) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Example 92 with Dataset

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

the class textindexer method processModulesAndArgs.

@Override
protected void processModulesAndArgs() {
    super.processModulesAndArgs();
    // Two forms : with and without arg.
    // Maximises similarity with other tools.
    String file;
    if (!super.contains(assemblerDescDecl) && getNumPositional() == 0)
        throw new CmdException("No assembler description given");
    if (super.contains(assemblerDescDecl)) {
        if (getValues(assemblerDescDecl).size() != 1)
            throw new CmdException("Multiple assembler descriptions given via --desc");
        if (getPositional().size() != 0)
            throw new CmdException("Additional assembler descriptions given");
        file = getValue(assemblerDescDecl);
    } else {
        if (getNumPositional() != 1)
            throw new CmdException("Multiple assembler descriptions given as positional arguments");
        file = getPositionalArg(0);
    }
    if (file == null)
        throw new CmdException("No dataset specified");
    // Assumes a single test dataset description in the assembler file.
    Dataset ds = TextDatasetFactory.create(file);
    if (ds == null)
        throw new CmdException("No dataset description found");
    // get index.
    dataset = (DatasetGraphText) (ds.asDatasetGraph());
    textIndex = dataset.getTextIndex();
    if (textIndex == null)
        throw new CmdException("Dataset has no text index");
    entityDefinition = textIndex.getDocDef();
}
Also used : CmdException(jena.cmd.CmdException) Dataset(org.apache.jena.query.Dataset)

Example 93 with Dataset

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

the class TextDatasetAssembler method open.

/*
<#text_dataset> rdf:type     text:Dataset ;
    text:dataset <#dataset> ;
    text:index   <#index> ;
    .

     */
@Override
public Dataset open(Assembler a, Resource root, Mode mode) {
    Resource dataset = GraphUtils.getResourceValue(root, pDataset);
    Resource index = GraphUtils.getResourceValue(root, pIndex);
    Resource textDocProducerNode = GraphUtils.getResourceValue(root, pTextDocProducer);
    Dataset ds = (Dataset) a.open(dataset);
    TextIndex textIndex = (TextIndex) a.open(index);
    // Null will use the default producer
    TextDocProducer textDocProducer = null;
    if (null != textDocProducerNode) {
        Class<?> c = Loader.loadClass(textDocProducerNode.getURI(), TextDocProducer.class);
        String className = textDocProducerNode.getURI().substring(ARQConstants.javaClassURIScheme.length());
        Constructor<?> dyadic = getConstructor(c, DatasetGraph.class, TextIndex.class);
        Constructor<?> monadic = getConstructor(c, TextIndex.class);
        try {
            if (dyadic != null) {
                textDocProducer = (TextDocProducer) dyadic.newInstance(ds.asDatasetGraph(), textIndex);
            } else if (monadic != null) {
                textDocProducer = (TextDocProducer) monadic.newInstance(textIndex);
            } else {
                Log.warn(Loader.class, "Exception during instantiation '" + className + "' no TextIndex or DatasetGraph,Index constructor");
            }
        } catch (Exception ex) {
            Log.warn(Loader.class, "Exception during instantiation '" + className + "': " + ex.getMessage());
            return null;
        }
    }
    Dataset dst = TextDatasetFactory.create(ds, textIndex, true, textDocProducer);
    return dst;
}
Also used : TextVocab.pTextDocProducer(org.apache.jena.query.text.assembler.TextVocab.pTextDocProducer) TextDocProducer(org.apache.jena.query.text.TextDocProducer) TextIndex(org.apache.jena.query.text.TextIndex) TextVocab.textDataset(org.apache.jena.query.text.assembler.TextVocab.textDataset) TextVocab.pDataset(org.apache.jena.query.text.assembler.TextVocab.pDataset) Dataset(org.apache.jena.query.Dataset) Resource(org.apache.jena.rdf.model.Resource) Loader(org.apache.jena.sparql.util.Loader)

Example 94 with Dataset

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

the class TestTextDatasetAssembler method testCustomTextDocProducerDyadicConstructor.

@Test
public void testCustomTextDocProducerDyadicConstructor() {
    Dataset dataset = (Dataset) Assembler.general.open(customDyadicTextDocProducerSpec);
    DatasetGraphText dsgText = (DatasetGraphText) dataset.asDatasetGraph();
    assertTrue(dsgText.getMonitor() instanceof CustomDyadicTextDocProducer);
    Node G = NodeFactory.createURI("http://example.com/G");
    Node S = NodeFactory.createURI("http://example.com/S");
    Node P = NodeFactory.createURI("http://example.com/P");
    Node O = NodeFactory.createLiteral("http://example.com/O");
    dsgText.begin(ReadWrite.WRITE);
    dsgText.add(G, S, P, O);
    dsgText.commit();
    dataset.close();
}
Also used : Dataset(org.apache.jena.query.Dataset) Node(org.apache.jena.graph.Node) Test(org.junit.Test)

Example 95 with Dataset

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

the class TestTextDatasetAssembler method testCustomTextDocProducer.

@Test
public void testCustomTextDocProducer() {
    Dataset dataset = (Dataset) Assembler.general.open(customTextDocProducerSpec);
    DatasetGraphText dsgText = (DatasetGraphText) dataset.asDatasetGraph();
    assertTrue(dsgText.getMonitor() instanceof CustomTextDocProducer);
    dataset.close();
}
Also used : Dataset(org.apache.jena.query.Dataset) Test(org.junit.Test)

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