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());
}
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();
}
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;
}
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();
}
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();
}
Aggregations