TextDatasetAssembler extends AssemblerBase implements Assembler { @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) ; TextDocProducer textDocProducer = null ; if (null != textDocProducerNode) { Class<?> c = ClsLoader.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(ClsLoader.class, "Exception during instantiation '"+className+"' no TextIndex or DatasetGraph,Index constructor" ); } } catch (Exception ex) { Log.warn(ClsLoader.class, "Exception during instantiation '"+className+"': "+ex.getMessage()) ; return null ; } } Dataset dst = TextDatasetFactory.create(ds, textIndex, true, textDocProducer) ; return dst ; }  static Resource getType(); @Override Dataset open(Assembler a, Resource root, Mode mode);  }
@Test public void testSimpleDatasetAssembler() { Dataset dataset = (Dataset) Assembler.general.open(spec1); assertTrue(dataset.getContext().get(TextQuery.textIndex) instanceof TextIndexLucene); dataset.close(); }
@Test(expected = AssemblerException.class) public void testErrorOnNoDataset() { Assembler.general.open(noDatasetPropertySpec); }
@Test(expected = AssemblerException.class) public void testErrorOnNoIndex() { Assembler.general.open(noIndexPropertySpec); }
@Test public void testCustomTextDocProducer() { Dataset dataset = (Dataset)Assembler.general.open(customTextDocProducerSpec) ; DatasetGraphText dsgText = (DatasetGraphText)dataset.asDatasetGraph() ; assertTrue(dsgText.getMonitor() instanceof CustomTextDocProducer) ; dataset.close(); }
@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: Node S = NodeFactory.createURI("http: Node P = NodeFactory.createURI("http: Node O = NodeFactory.createLiteral("http: dsgText.begin(ReadWrite.WRITE); dsgText.add(G, S, P, O); dsgText.commit(); }