use of org.apache.uima.analysis_engine.AnalysisEngineDescription in project dkpro-lab by dkpro.
the class CpeExecutionEngine method run.
@Override
public String run(Task aConfiguration) throws ExecutionException, LifeCycleException {
if (!(aConfiguration instanceof UimaTask)) {
throw new ExecutionException("This engine can only execute [" + UimaTask.class.getName() + "]");
}
UimaTask configuration = (UimaTask) aConfiguration;
// Create persistence service for injection into analysis components
TaskContext ctx = contextFactory.createContext(aConfiguration);
try {
ResourceManager resMgr = newDefaultResourceManager();
// Make sure the descriptor is fully resolved. It will be modified and
// thus should not be modified again afterwards by UIMA.
AnalysisEngineDescription analysisDesc = configuration.getAnalysisEngineDescription(ctx);
analysisDesc.resolveImports(resMgr);
// Scan components that accept the service and bind it to them
bindResource(analysisDesc, TaskContext.class, TaskContextProvider.class, TaskContextProvider.PARAM_FACTORY_NAME, contextFactory.getId(), TaskContextProvider.PARAM_CONTEXT_ID, ctx.getId());
CpeBuilder mgr = new CpeBuilder();
ctx.message("CPE will be using " + Runtime.getRuntime().availableProcessors() + " parallel threads to optimally utilize your cpu cores");
mgr.setMaxProcessingUnitThreadCount(Runtime.getRuntime().availableProcessors());
mgr.setReader(configuration.getCollectionReaderDescription(ctx));
mgr.setAnalysisEngine(analysisDesc);
StatusCallbackListenerImpl status = new StatusCallbackListenerImpl(ctx);
CollectionProcessingEngine engine = mgr.createCpe(status);
// Now the setup is complete
ctx.getLifeCycleManager().initialize(ctx, aConfiguration);
// Start recording
ctx.getLifeCycleManager().begin(ctx, aConfiguration);
// Run the experiment
engine.process();
try {
synchronized (status) {
while (status.isProcessing) {
status.wait();
}
}
} catch (InterruptedException e) {
ctx.message("CPE interrupted.");
}
if (status.exceptions.size() > 0) {
throw status.exceptions.get(0);
}
// End recording
ctx.getLifeCycleManager().complete(ctx, aConfiguration);
return ctx.getId();
} catch (LifeCycleException e) {
ctx.getLifeCycleManager().fail(ctx, aConfiguration, e);
throw e;
} catch (Throwable e) {
ctx.getLifeCycleManager().fail(ctx, aConfiguration, e);
throw new ExecutionException(e);
} finally {
if (ctx != null) {
ctx.getLifeCycleManager().destroy(ctx, aConfiguration);
}
}
}
use of org.apache.uima.analysis_engine.AnalysisEngineDescription in project dkpro-lab by dkpro.
the class SimpleExecutionEngineTest method testInit.
@Test
public void testInit() throws Exception {
File repo = new File("target/repository");
FileUtils.deleteDirectory(repo);
((FileSystemStorageService) storageService).setStorageRoot(repo);
assertNotNull(executionService);
assertNotNull(contextFactory);
TypeSystemDescription tsd = createTypeSystemDescription(new String[0]);
AnalysisEngineDescription desc = createEngineDescription(DummyAE.class, tsd);
DefaultUimaTask cfg = new DefaultUimaTask();
cfg.setReaderDescription(createReaderDescription(TestReader.class, tsd));
cfg.setAnalysisEngineDescription(desc);
TaskExecutionEngine runner = executionService.createEngine(cfg);
String uuid = runner.run(cfg);
System.out.println("=== Experiments in repository ===");
List<TaskContextMetadata> experiments = storageService.getContexts();
for (TaskContextMetadata e : experiments) {
System.out.println(e);
}
final StringBuilder sb = new StringBuilder();
storageService.retrieveBinary(uuid, "test", new StreamReader() {
@Override
public void read(InputStream aInputStream) throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
Util.shoveAndClose(aInputStream, bos);
sb.append(new String(bos.toByteArray(), "UTF-8"));
}
});
assertEquals("works", sb.toString());
}
use of org.apache.uima.analysis_engine.AnalysisEngineDescription in project webanno by webanno.
the class Conll2009ReaderWriterTest method test.
@Test
public void test() throws Exception {
CollectionReaderDescription reader = createReaderDescription(Conll2009Reader.class, Conll2009Reader.PARAM_SOURCE_LOCATION, "src/test/resources/conll/2009", Conll2009Reader.PARAM_PATTERNS, "en-orig.conll");
AnalysisEngineDescription writer = createEngineDescription(Conll2009Writer.class, Conll2009Writer.PARAM_TARGET_LOCATION, "target/test-output/Conll2009ReaderWriterTest-test", Conll2009Writer.PARAM_FILENAME_EXTENSION, ".conll", Conll2009Writer.PARAM_STRIP_EXTENSION, true);
runPipeline(reader, writer);
String reference = FileUtils.readFileToString(new File("src/test/resources/conll/2009/en-ref.conll"), "UTF-8").trim();
String actual = FileUtils.readFileToString(new File("target/test-output/Conll2009ReaderWriterTest-test/en-orig.conll"), "UTF-8").trim();
assertTrue(IOUtils.contentEqualsIgnoreEOL(new StringReader(reference), new StringReader(actual)));
}
use of org.apache.uima.analysis_engine.AnalysisEngineDescription in project webanno by webanno.
the class ConllUReaderWriterTest method roundTrip.
@Test
public void roundTrip() throws Exception {
CollectionReaderDescription reader = createReaderDescription(ConllUReader.class, ConllUReader.PARAM_SOURCE_LOCATION, "src/test/resources/conll/u", ConllUReader.PARAM_PATTERNS, "conllu-en-orig.conll");
AnalysisEngineDescription writer = createEngineDescription(ConllUWriter.class, ConllUWriter.PARAM_TARGET_LOCATION, "target/test-output/ConllUReaderWriterTest-roundTrip", ConllUWriter.PARAM_FILENAME_SUFFIX, ".conll", ConllUWriter.PARAM_STRIP_EXTENSION, true);
runPipeline(reader, writer);
String reference = FileUtils.readFileToString(new File("src/test/resources/conll/u/conllu-en-ref.conll"), "UTF-8").trim();
String actual = FileUtils.readFileToString(new File("target/test-output/ConllUReaderWriterTest-roundTrip/conllu-en-orig.conll"), "UTF-8").trim();
assertTrue(IOUtils.contentEqualsIgnoreEOL(new StringReader(reference), new StringReader(actual)));
}
use of org.apache.uima.analysis_engine.AnalysisEngineDescription in project webanno by webanno.
the class TcfReaderWriterTest method testRoundtrip.
@Test
public void testRoundtrip() throws Exception {
CollectionReaderDescription reader = createReaderDescription(TcfReader.class, TcfReader.PARAM_SOURCE_LOCATION, "src/test/resources/", TcfReader.PARAM_PATTERNS, "wlfxb.xml");
AnalysisEngineDescription writer = createEngineDescription(TcfWriter.class, TcfWriter.PARAM_TARGET_LOCATION, "target/test-output/roundtrip", TcfWriter.PARAM_FILENAME_SUFFIX, ".xml", TcfWriter.PARAM_STRIP_EXTENSION, true);
runPipeline(reader, writer);
String expected = contentOf(new File("src/test/resources/wlfxb.xml"), UTF_8);
String actual = contentOf(new File("target/test-output/roundtrip/wlfxb.xml"), UTF_8);
assertThat(expected).isXmlEqualTo(actual);
}
Aggregations