private JCas createJas() throws ResourceInitializationException { try { return JCasFactory.createJCas(TypeSystemSingleton.getTypeSystemDescriptionInstance()); } catch (UIMAException e) { throw new ResourceInitializationException(e); } }
private AnalysisEngine createAnalysisEngine(Object... args) throws ResourceInitializationException { return AnalysisEngineFactory.createEngine( MemoryTransportSender.class, TypeSystemSingleton.getTypeSystemDescriptionInstance(), args); } }
/** * Get an analysis engine for the * * @return * @throws ResourceInitializationException */ protected AnalysisEngine getAnalysisEngine() throws ResourceInitializationException { return AnalysisEngineFactory.createEngine( annotatorClass, TypeSystemSingleton.getTypeSystemDescriptionInstance()); }
/** * Get an analysis engine for the * * @param args name-value pairs * @return * @throws ResourceInitializationException */ protected AnalysisEngine getAnalysisEngine(Object... args) throws ResourceInitializationException { return AnalysisEngineFactory.createEngine( annotatorClass, TypeSystemSingleton.getTypeSystemDescriptionInstance(), args); }
protected BaleenCollectionReader getCollectionReader(Object... args) throws ResourceInitializationException { Object[] argumentWithExtractor = ImmutableList.builder() .add(KEY_CONTENT_EXTRACTOR) .add(contentExtractor) .addAll(Arrays.asList(args)) .build() .toArray(); return (BaleenCollectionReader) CollectionReaderFactory.createReader( readerClass, TypeSystemSingleton.getTypeSystemDescriptionInstance(), argumentWithExtractor); } }
public static JCas getJCasInstance() throws UIMAException { if (jCas == null) { jCas = JCasFactory.createJCas(TypeSystemSingleton.getTypeSystemDescriptionInstance()); } else { jCas.reset(); } return jCas; } }
private MemoryTransportReceiver createReciever() throws ResourceInitializationException { return (MemoryTransportReceiver) CollectionReaderFactory.createReader( MemoryTransportReceiver.class, TypeSystemSingleton.getTypeSystemDescriptionInstance(), KEY_CONTENT_EXTRACTOR, ExternalResourceFactory.createExternalResourceDescription( KEY_CONTENT_EXTRACTOR, FakeBaleenContentExtractor.class), SharedMemoryQueueResource.RESOURCE_KEY, erd); }
@BeforeClass public static void setupClass() throws UIMAException { typeSystemDescription = TypeSystemSingleton.getTypeSystemDescriptionInstance(); jCas = JCasFactory.createJCas(typeSystemDescription); }
@Test public void testBadBasePath() throws Exception { File baseDir = File.createTempFile("baleen", ".foo"); try { AnalysisEngineFactory.createEngine( TestFileConsumer.class, TypeSystemSingleton.getTypeSystemDescriptionInstance(), BASE_PATH, baseDir.getPath()); fail("Didn't throw expected exception"); } catch (ResourceInitializationException rie) { // Expected exception } }
@Test public void testEntityCountOutputReadOnly() throws Exception { File output = Files.createTempFile("baleen-entitycount", ".tsv").toFile(); output.setReadOnly(); try { AnalysisEngineFactory.createEngine( EntityCount.class, TypeSystemSingleton.getTypeSystemDescriptionInstance(), OUTPUT_FILE, output.getPath()); fail("Expected exception not thrown"); } catch (Exception ex) { // Do nothing } output.delete(); }
@Test public void testEntityCountOutputCantWrite() throws Exception { File output = Files.createTempDirectory("baleen").toFile(); createDocument(); // Try writing to folder AnalysisEngine consumer = AnalysisEngineFactory.createEngine( EntityCount.class, TypeSystemSingleton.getTypeSystemDescriptionInstance(), OUTPUT_FILE, output.getPath()); consumer.process(jCas); consumer.destroy(); output.delete(); } }
@Test public void testEntityCountOutputNewFile() throws Exception { File outputFolder = Files.createTempDirectory("baleen").toFile(); File output = new File(outputFolder, "baleen-entitycount.tsv"); AnalysisEngine consumer = AnalysisEngineFactory.createEngine( EntityCount.class, TypeSystemSingleton.getTypeSystemDescriptionInstance(), OUTPUT_FILE, output.getPath()); createDocument(); consumer.process(jCas); assertEquals("test1.txt\t2", FileUtils.file2String(output).trim()); consumer.destroy(); output.delete(); outputFolder.delete(); }
@Test public void testEntityCountOutput() throws Exception { File output = Files.createTempFile("baleen-entitycount", ".tsv").toFile(); AnalysisEngine consumer = AnalysisEngineFactory.createEngine( EntityCount.class, TypeSystemSingleton.getTypeSystemDescriptionInstance(), OUTPUT_FILE, output.getPath()); createDocument(); consumer.process(jCas); assertEquals("test1.txt\t2", FileUtils.file2String(output).trim()); consumer.destroy(); output.delete(); }
@Test public void testNullBasePath() throws Exception { AnalysisEngine consumer = AnalysisEngineFactory.createEngine( TestFileConsumer.class, TypeSystemSingleton.getTypeSystemDescriptionInstance()); DocumentAnnotation da = (DocumentAnnotation) jCas.getDocumentAnnotationFs(); da.setSourceUri(FILENAME); consumer.process(jCas); File f = new File(FILENAME); assertTrue(f.exists()); f.delete(); } }
@Test public void testCreateExistingFile() throws UIMAException, IOException { AnalysisEngine consumer = AnalysisEngineFactory.createEngine( Html5.class, TypeSystemSingleton.getTypeSystemDescriptionInstance(), Html5.PARAM_OUTPUT_FOLDER, outputFolder.getPath()); jCas.setDocumentText("Hello World!"); DocumentAnnotation da = (DocumentAnnotation) jCas.getDocumentAnnotationFs(); da.setSourceUri("hello.txt"); File fExisting = new File(outputFolder, "hello.txt.html"); fExisting.createNewFile(); consumer.process(jCas); File f = new File(outputFolder, "hello.txt.1.html"); assertTrue(f.exists()); }
@Test public void testCreateOutputDir() throws UIMAException { File newFolder = new File(outputFolder, "test"); AnalysisEngine consumer = AnalysisEngineFactory.createEngine( Html5.class, TypeSystemSingleton.getTypeSystemDescriptionInstance(), Html5.PARAM_OUTPUT_FOLDER, newFolder.getPath()); jCas.setDocumentText("Hello World!"); DocumentAnnotation da = (DocumentAnnotation) jCas.getDocumentAnnotationFs(); da.setSourceUri("hello.txt"); consumer.process(jCas); File f = new File(newFolder, "hello.txt.html"); assertTrue(f.exists()); }
@Test public void testCreateFile() throws UIMAException { AnalysisEngine consumer = AnalysisEngineFactory.createEngine( Html5.class, TypeSystemSingleton.getTypeSystemDescriptionInstance(), Html5.PARAM_OUTPUT_FOLDER, outputFolder.getPath()); jCas.setDocumentText("Hello World!"); DocumentAnnotation da = (DocumentAnnotation) jCas.getDocumentAnnotationFs(); da.setSourceUri("hello.txt"); consumer.process(jCas); File f = new File(outputFolder, "hello.txt.html"); assertTrue(f.exists()); }
@Test public void testMissingBasePath() throws Exception { File baseDir = new File(Files.createTempDir(), "subdir"); AnalysisEngine consumer = AnalysisEngineFactory.createEngine( TestFileConsumer.class, TypeSystemSingleton.getTypeSystemDescriptionInstance(), BASE_PATH, baseDir.getPath()); jCas.setDocumentText(TEXT); DocumentAnnotation da = (DocumentAnnotation) jCas.getDocumentAnnotationFs(); da.setSourceUri(FILENAME); consumer.process(jCas); String s = FileUtils.file2String(new File(baseDir, FILENAME)); assertEquals(TEXT, s); }
@Test public void test() throws Exception { File baseDir = Files.createTempDir(); AnalysisEngine consumer = AnalysisEngineFactory.createEngine( TestFileConsumer.class, TypeSystemSingleton.getTypeSystemDescriptionInstance(), BASE_PATH, baseDir.getPath()); jCas.setDocumentText(TEXT); DocumentAnnotation da = (DocumentAnnotation) jCas.getDocumentAnnotationFs(); da.setSourceUri(FILENAME); consumer.process(jCas); String s = FileUtils.file2String(new File(baseDir, FILENAME)); assertEquals(TEXT, s); }
@Test public void docHash() throws Exception { JCas jcas = JCasFactory.createJCas(TypeSystemSingleton.getTypeSystemDescriptionInstance()); jcas.setDocumentText("There is the mention of some entity in this sentence."); DocumentAnnotation doc = (DocumentAnnotation) jcas.getDocumentAnnotationFs(); assertEquals("87cebccde680225b7640878d334b4cbb1c048ba1c8e66763f72cca5396a37807", doc.getHash()); } }