Java Code Examples for org.apache.uima.fit.factory.AnalysisEngineFactory#createEngineDescription()
The following examples show how to use
org.apache.uima.fit.factory.AnalysisEngineFactory#createEngineDescription() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TypeCapabilityTest.java From uima-uimafit with Apache License 2.0 | 6 votes |
@Test public void testTC() throws ResourceInitializationException { AnalysisEngineDescription aed = AnalysisEngineFactory.createEngineDescription( Annotator4.class, typeSystemDescription); Capability[] capabilities = aed.getAnalysisEngineMetaData().getCapabilities(); assertEquals(1, capabilities.length); Capability capability = capabilities[0]; TypeOrFeature[] inputs = capability.getInputs(); assertEquals(1, inputs.length); assertEquals("org.apache.uima.fit.type.Token", inputs[0].getName()); assertTrue(inputs[0].isType()); TypeOrFeature[] outputs = capability.getOutputs(); assertEquals(1, outputs.length); assertEquals("org.apache.uima.fit.type.Token:pos", outputs[0].getName()); assertFalse(outputs[0].isType()); }
Example 2
Source File: SimplePipelineTest.java From uima-uimafit with Apache License 2.0 | 6 votes |
@Test public void test1() throws UIMAException, IOException { // Creating a CAS locally here to work around UIMA-5097 - otherwise this test may fail if // run in Eclipse or in other unit test setups where the same JVM is re-used for multiple tests. TypeSystemDescription tsd = TypeSystemDescriptionFactory.createTypeSystemDescription(); TypePriorities tp = TypePrioritiesFactory.createTypePriorities(new String[] { "org.apache.uima.fit.type.Sentence", "org.apache.uima.fit.type.AnalyzedText", "org.apache.uima.fit.type.Token" }); JCas jcas = CasCreationUtils.createCas(tsd, tp, null).getJCas(); CasIOUtil.readJCas(jcas, new File("src/test/resources/data/docs/test.xmi")); AnalysisEngineDescription aed1 = AnalysisEngineFactory.createEngineDescription( Annotator1.class, typeSystemDescription); AnalysisEngineDescription aed2 = AnalysisEngineFactory.createEngineDescription( Annotator2.class, typeSystemDescription); AnalysisEngineDescription aed3 = AnalysisEngineFactory.createEngineDescription( Annotator3.class, typeSystemDescription); SimplePipeline.runPipeline(jcas, aed1, aed2, aed3); }
Example 3
Source File: CustomResourceTermSuiteAEFactory.java From termsuite-core with Apache License 2.0 | 6 votes |
/** * Spots fixed expressions in the CAS an creates {@link FixedExpression} * annotation whenever one is found. * * @return */ public static AnalysisEngineDescription createFixedExpressionSpotterAEDesc(ResourceConfig resourceConfig, Lang lang) { try { AnalysisEngineDescription ae = AnalysisEngineFactory.createEngineDescription( FixedExpressionSpotter.class, FixedExpressionSpotter.FIXED_EXPRESSION_MAX_SIZE, 5, FixedExpressionSpotter.REMOVE_WORD_ANNOTATIONS_FROM_CAS, false, FixedExpressionSpotter.REMOVE_TERM_OCC_ANNOTATIONS_FROM_CAS, true ); ExternalResourceDescription fixedExprRes = ExternalResourceFactory.createExternalResourceDescription( FixedExpressionResource.class, getResourceURL(resourceConfig, ResourceType.FIXED_EXPRESSIONS, lang)); ExternalResourceFactory.bindResource( ae, FixedExpressionResource.FIXED_EXPRESSION_RESOURCE, fixedExprRes ); return ae; } catch (Exception e) { throw new PreparationPipelineException(e); } }
Example 4
Source File: ConfigurationParameterInitializerTest.java From uima-uimafit with Apache License 2.0 | 6 votes |
/** * Check that an Analysis Engine created from a descriptor declaring optional parameters but not * setting them actually uses the default values declared in the Java annotation */ @Test public void testUnsetOptionalParameter() throws Exception { AnalysisEngineDescription aed = AnalysisEngineFactory.createEngineDescription( DefaultValueAE1.class, (Object[]) null); // Remove the settings from the descriptor, but leave the declarations. // The settings are already filled with default values by createPrimitiveDescription, // but here we want to simulate loading a descriptor without settings from a file. // The file of course would declare the parameters optional and thus the settings // for the optional parameters would be empty. We expect that a default value from the // annotation is used in this case. aed.getMetaData().setConfigurationParameterSettings(new ConfigurationParameterSettings_impl()); AnalysisEngine template = UIMAFramework.produceAnalysisEngine(aed); DefaultValueAE1 ae = new DefaultValueAE1(); ae.initialize(template.getUimaContext()); assertEquals("green", ae.color); }
Example 5
Source File: CustomResourceTermSuiteAEFactory.java From termsuite-core with Apache License 2.0 | 6 votes |
private static AnalysisEngineDescription createSubNormalizerAEDesc(String target, URL mappingFile) { try { AnalysisEngineDescription ae = AnalysisEngineFactory.createEngineDescription( Mapper.class, Mapper.PARAM_SOURCE, "fr.univnantes.termsuite.types.WordAnnotation:tag", Mapper.PARAM_TARGET, target, Mapper.PARAM_UPDATE, true ); ExternalResourceDescription mappingRes = ExternalResourceFactory.createExternalResourceDescription( MappingResource.class, mappingFile ); ExternalResourceFactory.bindResource( ae, Mapping.KEY_MAPPING, mappingRes ); return ae; } catch (Exception e) { throw new PreparationPipelineException(e); } }
Example 6
Source File: OpenNLPTest.java From baleen with Apache License 2.0 | 5 votes |
@Test public void testMissing() throws Exception { AnalysisEngineDescription desc = AnalysisEngineFactory.createEngineDescription( OpenNLP.class, TYPE, PERSON, MODEL, "missing.bin"); try { AnalysisEngineFactory.createEngine(desc); fail("Did not throw expected exception"); } catch (ResourceInitializationException e) { // Expected exception } }
Example 7
Source File: CustomResourceTermSuiteAEFactory.java From termsuite-core with Apache License 2.0 | 5 votes |
public static AnalysisEngineDescription createMateAEDesc(ResourceConfig resourceConfig, Lang lang, Path mateModelPath) { try { AnalysisEngineDescription mateTaggerAE = AnalysisEngineFactory.createEngineDescription( MateLemmatizerTagger.class ); String lemmatizerModel = mateModelPath.resolve("mate-lemma-"+lang.getCode()+".model").toString(); String taggerModel = mateModelPath.resolve("mate-pos-"+lang.getCode()+".model").toString(); Preconditions.checkArgument(Files.exists(Paths.get(lemmatizerModel)), "Lemmatizer model does not exist: %s", lemmatizerModel); Preconditions.checkArgument(Files.exists(Paths.get(taggerModel)), "Tagger model does not exist: %s", taggerModel); ExternalResourceFactory.createDependencyAndBind( mateTaggerAE, MateLemmatizerTagger.LEMMATIZER, MateLemmatizerModel.class, lemmatizerModel); ExternalResourceFactory.createDependencyAndBind( mateTaggerAE, MateLemmatizerTagger.TAGGER, MateTaggerModel.class, taggerModel); AnalysisEngineDescription lemmaFixerAE = AnalysisEngineFactory.createEngineDescription( MateLemmaFixer.class, MateLemmaFixer.LANGUAGE, lang.getCode() ); AnalysisEngineDescription normalizerAE = createNormalizerAE(resourceConfig, lang, Tagger.MATE); return AnalysisEngineFactory.createEngineDescription( mateTaggerAE, lemmaFixerAE, normalizerAE); } catch (Exception e) { throw new TermSuiteException(e); } }
Example 8
Source File: NPAtCoordinateTest.java From baleen with Apache License 2.0 | 5 votes |
@Before public void before() throws UIMAException { ExternalResourceDescription tokensDesc = ExternalResourceFactory.createNamedResourceDescription("tokens", SharedOpenNLPModel.class); ExternalResourceDescription sentencesDesc = ExternalResourceFactory.createNamedResourceDescription( "sentences", SharedOpenNLPModel.class); ExternalResourceDescription posDesc = ExternalResourceFactory.createNamedResourceDescription("posTags", SharedOpenNLPModel.class); ExternalResourceDescription chunksDesc = ExternalResourceFactory.createNamedResourceDescription( "phraseChunks", SharedOpenNLPModel.class); AnalysisEngineDescription desc = AnalysisEngineFactory.createEngineDescription( OpenNLP.class, "tokens", tokensDesc, "sentences", sentencesDesc, "posTags", posDesc, "phraseChunks", chunksDesc); languageAE = AnalysisEngineFactory.createEngine(desc); }
Example 9
Source File: NPElementTest.java From baleen with Apache License 2.0 | 5 votes |
@Before public void before() throws UIMAException { ExternalResourceDescription tokensDesc = ExternalResourceFactory.createNamedResourceDescription("tokens", SharedOpenNLPModel.class); ExternalResourceDescription sentencesDesc = ExternalResourceFactory.createNamedResourceDescription( "sentences", SharedOpenNLPModel.class); ExternalResourceDescription posDesc = ExternalResourceFactory.createNamedResourceDescription("posTags", SharedOpenNLPModel.class); ExternalResourceDescription chunksDesc = ExternalResourceFactory.createNamedResourceDescription( "phraseChunks", SharedOpenNLPModel.class); AnalysisEngineDescription desc = AnalysisEngineFactory.createEngineDescription( OpenNLP.class, "tokens", tokensDesc, "sentences", sentencesDesc, "posTags", posDesc, "phraseChunks", chunksDesc); languageAE = AnalysisEngineFactory.createEngine(desc); }
Example 10
Source File: QuantityNPEntityTest.java From baleen with Apache License 2.0 | 5 votes |
@Before public void before() throws UIMAException { jCas.setDocumentText("The bag contained 4kg of blue powder."); ExternalResourceDescription tokensDesc = ExternalResourceFactory.createNamedResourceDescription("tokens", SharedOpenNLPModel.class); ExternalResourceDescription sentencesDesc = ExternalResourceFactory.createNamedResourceDescription( "sentences", SharedOpenNLPModel.class); ExternalResourceDescription posDesc = ExternalResourceFactory.createNamedResourceDescription("posTags", SharedOpenNLPModel.class); ExternalResourceDescription chunksDesc = ExternalResourceFactory.createNamedResourceDescription( "phraseChunks", SharedOpenNLPModel.class); AnalysisEngineDescription desc = AnalysisEngineFactory.createEngineDescription( OpenNLP.class, TypeSystemSingleton.getTypeSystemDescriptionInstance(), "tokens", tokensDesc, "sentences", sentencesDesc, "posTags", posDesc, "phraseChunks", chunksDesc); AnalysisEngine languageAE = AnalysisEngineFactory.createEngine(desc); languageAE.process(jCas); }
Example 11
Source File: MongoTest.java From baleen with Apache License 2.0 | 5 votes |
@Before public void setUp() throws ResourceInitializationException, ResourceAccessException { // Create a description of an external resource - a fongo instance, in the same way we would // have created a shared mongo resource ExternalResourceDescription erd = ExternalResourceFactory.createNamedResourceDescription( MONGO, SharedFongoResource.class, "fongo.collection", "test", "fongo.data", "[]"); ExternalResourceDescription historyErd = ExternalResourceFactory.createNamedResourceDescription( PipelineBuilder.BALEEN_HISTORY, InMemoryBaleenHistory.class); history = Mockito.mock(BaleenHistory.class); // Create the analysis engine AnalysisEngineDescription aed = AnalysisEngineFactory.createEngineDescription( Mongo.class, MONGO, erd, "collection", "test", PipelineBuilder.BALEEN_HISTORY, historyErd, "outputHistory", Boolean.TRUE); ae = AnalysisEngineFactory.createEngine(aed); ae.initialize(new CustomResourceSpecifier_impl(), Collections.emptyMap()); SharedFongoResource sfr = (SharedFongoResource) ae.getUimaContext().getResourceObject(MONGO); history = (BaleenHistory) ae.getUimaContext().getResourceObject(PipelineBuilder.BALEEN_HISTORY); entities = sfr.getDB().getCollection("entities"); documents = sfr.getDB().getCollection("documents"); relations = sfr.getDB().getCollection("relations"); // Ensure we start with no data! assertEquals(0L, documents.count()); assertEquals(0L, entities.count()); assertEquals(0L, relations.count()); }
Example 12
Source File: AbstractRegexNPAnnotatorTest.java From baleen with Apache License 2.0 | 5 votes |
@Test public void testChunks() throws Exception { ExternalResourceDescription tokensDesc = ExternalResourceFactory.createNamedResourceDescription("tokens", SharedOpenNLPModel.class); ExternalResourceDescription sentencesDesc = ExternalResourceFactory.createNamedResourceDescription( "sentences", SharedOpenNLPModel.class); ExternalResourceDescription posDesc = ExternalResourceFactory.createNamedResourceDescription("posTags", SharedOpenNLPModel.class); ExternalResourceDescription chunksDesc = ExternalResourceFactory.createNamedResourceDescription( "phraseChunks", SharedOpenNLPModel.class); AnalysisEngineDescription descNLP = AnalysisEngineFactory.createEngineDescription( OpenNLP.class, "tokens", tokensDesc, "sentences", sentencesDesc, "posTags", posDesc, "phraseChunks", chunksDesc); AnalysisEngine aeNLP = AnalysisEngineFactory.createEngine(descNLP); AnalysisEngine ae = AnalysisEngineFactory.createEngine(TestAnnotator.class); jCas.setDocumentText("PERSON JOHN SMITH WAS SEEN ENTERING THE WAREHOUSE"); aeNLP.process(jCas); ae.process(jCas); assertEquals(1, JCasUtil.select(jCas, Person.class).size()); assertEquals("JOHN SMITH", JCasUtil.selectByIndex(jCas, Person.class, 0).getValue()); }
Example 13
Source File: OpenNLPTest.java From baleen with Apache License 2.0 | 5 votes |
@Override public void beforeTest() throws UIMAException { super.beforeTest(); ExternalResourceDescription tokensDesc = ExternalResourceFactory.createNamedResourceDescription("tokens", SharedOpenNLPModel.class); ExternalResourceDescription sentencesDesc = ExternalResourceFactory.createNamedResourceDescription( "sentences", SharedOpenNLPModel.class); ExternalResourceDescription posDesc = ExternalResourceFactory.createNamedResourceDescription("posTags", SharedOpenNLPModel.class); ExternalResourceDescription chunksDesc = ExternalResourceFactory.createNamedResourceDescription( "phraseChunks", SharedOpenNLPModel.class); AnalysisEngineDescription desc = AnalysisEngineFactory.createEngineDescription( OpenNLP.class, "tokens", tokensDesc, "sentences", sentencesDesc, "posTags", posDesc, "phraseChunks", chunksDesc); ae = AnalysisEngineFactory.createEngine(desc); }
Example 14
Source File: ListTest.java From baleen with Apache License 2.0 | 5 votes |
@Test public void testWhitespaceExact() throws Exception { // This test demonstrates the case where whitespace is preserved in gazetteer matching. AnalysisEngineDescription aed = AnalysisEngineFactory.createEngineDescription( List.class, List.PARAM_TERMS, terms, List.PARAM_TYPE, LOCATION, List.PARAM_EXACT_WHITESPACE, true); AnalysisEngine ae = AnalysisEngineFactory.createEngine(aed); // words in term to search for separated by multiple spaces, tabs or newline... jCas.setDocumentText( "This text mentions New York, and New York again, and New York again, and New \nYork yet again"); ae.process(jCas); // only one mention of "New York" has the two words separated by a single space (as in the // gazetteer) assertEquals(1, JCasUtil.select(jCas, Location.class).size()); Location l = JCasUtil.selectByIndex(jCas, Location.class, 0); assertEquals(NEW_YORK, l.getValue()); ae.destroy(); }
Example 15
Source File: MongoTest.java From baleen with Apache License 2.0 | 5 votes |
@Before public void setUp() throws ResourceInitializationException, ResourceAccessException { // Create a description of an external resource - a fongo instance, in the same way we would // have created a shared mongo resource final ExternalResourceDescription erd = ExternalResourceFactory.createNamedResourceDescription( MONGO, SharedFongoResource.class, PARAM_FONGO_COLLECTION, "test", PARAM_FONGO_DATA, "[]"); final ExternalResourceDescription idErd = ExternalResourceFactory.createNamedResourceDescription( SharedIdGenerator.RESOURCE_KEY, SharedIdGenerator.class); // Create the analysis engine final AnalysisEngineDescription aed = AnalysisEngineFactory.createEngineDescription( Mongo.class, MONGO, erd, SharedIdGenerator.RESOURCE_KEY, idErd); ae = AnalysisEngineFactory.createEngine(aed); ae.initialize(new CustomResourceSpecifier_impl(), Collections.emptyMap()); final SharedFongoResource sfr = (SharedFongoResource) ae.getUimaContext().getResourceObject(MONGO); final MongoDatabase db = sfr.getDB(); documentCollection = db.getCollection(Mongo.DEFAULT_DOCUMENTS_COLLECTION); entityCollection = db.getCollection(Mongo.DEFAULT_ENTITY_COLLECTION); mentionCollection = db.getCollection(Mongo.DEFAULT_MENTION_COLLECTION); relationCollection = db.getCollection(Mongo.DEFAULT_REALTION_COLLECTION); assertEquals(0, documentCollection.count()); assertEquals(0, entityCollection.count()); assertEquals(0, relationCollection.count()); assertEquals(0, mentionCollection.count()); }
Example 16
Source File: FileTest.java From baleen with Apache License 2.0 | 5 votes |
@Test public void testmultipleHits() throws Exception { ExternalResourceDescription erd = ExternalResourceFactory.createNamedResourceDescription( FILE_GAZETTEER, SharedFileResource.class); AnalysisEngineDescription aed = AnalysisEngineFactory.createEngineDescription( File.class, FILE_GAZETTEER, erd, FILE_NAME, getClass().getResource(GAZETTEER_TXT).getPath(), TYPE, LOCATION); AnalysisEngine ae = AnalysisEngineFactory.createEngine(aed); // the same search term appears multiple times in text... jCas.setDocumentText("Hello world, and hello world again."); ae.process(jCas); assertEquals(2, JCasUtil.select(jCas, Location.class).size()); Location l = JCasUtil.selectByIndex(jCas, Location.class, 0); assertEquals(WORLD, l.getValue()); assertEquals(WORLD, l.getCoveredText()); ae.destroy(); }
Example 17
Source File: MongoRegexTest.java From baleen with Apache License 2.0 | 5 votes |
@Test public void testProperty() throws Exception { ExternalResourceDescription erd = ExternalResourceFactory.createNamedResourceDescription( MONGO, SharedFongoResource.class, FONGO_COLLECTION, MONGO_COLL, FONGO_DATA, objectMapper.writeValueAsString(GAZ_DATA)); AnalysisEngineDescription aed = AnalysisEngineFactory.createEngineDescription( MongoRegex.class, MONGO, erd, COLLECTION, MONGO_COLL, TYPE, LOCATION, REGEX, LONDON_REGEX); AnalysisEngine ae = AnalysisEngineFactory.createEngine(aed); jCas.setDocumentText(TEXT); ae.process(jCas); assertEquals(1, JCasUtil.select(jCas, Location.class).size()); Location l = JCasUtil.selectByIndex(jCas, Location.class, 0); assertEquals("London", l.getValue()); assertEquals("London", l.getCoveredText()); assertEquals("Property_Test", l.getGeoJson()); ae.destroy(); }
Example 18
Source File: ListTest.java From baleen with Apache License 2.0 | 5 votes |
@Test public void testPlurals() throws Exception { // This test demonstrates pluralisation in the gazetteer AnalysisEngineDescription aed = AnalysisEngineFactory.createEngineDescription( List.class, List.PARAM_TERMS, terms, List.PARAM_TYPE, LOCATION, List.PARAM_PLURALS, true); AnalysisEngine ae = AnalysisEngineFactory.createEngine(aed); jCas.setDocumentText( "There may be many New Yorks and many Parises, but there's only one London."); ae.process(jCas); assertEquals(3, JCasUtil.select(jCas, Location.class).size()); Location l1 = JCasUtil.selectByIndex(jCas, Location.class, 0); Location l2 = JCasUtil.selectByIndex(jCas, Location.class, 1); Location l3 = JCasUtil.selectByIndex(jCas, Location.class, 2); assertEquals("New Yorks", l1.getValue()); assertEquals("Parises", l2.getValue()); assertEquals("London", l3.getValue()); ae.destroy(); }
Example 19
Source File: ShannonEntropyAnnotatorTest.java From baleen with Apache License 2.0 | 5 votes |
@Override protected AnalysisEngine[] createAnalysisEngines() throws ResourceInitializationException { ExternalResourceDescription tokensDesc = ExternalResourceFactory.createNamedResourceDescription("tokens", SharedOpenNLPModel.class); ExternalResourceDescription sentencesDesc = ExternalResourceFactory.createNamedResourceDescription( "sentences", SharedOpenNLPModel.class); ExternalResourceDescription posDesc = ExternalResourceFactory.createNamedResourceDescription("posTags", SharedOpenNLPModel.class); ExternalResourceDescription chunksDesc = ExternalResourceFactory.createNamedResourceDescription( "phraseChunks", SharedOpenNLPModel.class); AnalysisEngineDescription openNlpAnalysisEngineDescription = AnalysisEngineFactory.createEngineDescription( OpenNLP.class, "tokens", tokensDesc, "sentences", sentencesDesc, "posTags", posDesc, "phraseChunks", chunksDesc); AnalysisEngineDescription shannonEntropyAnalysisEngineDescription = AnalysisEngineFactory.createEngineDescription(ShannonEntropyAnnotator.class); AnalysisEngine openNlpAnalysisEngine = AnalysisEngineFactory.createEngine(openNlpAnalysisEngineDescription); AnalysisEngine shannonEntropyAnalysisEngine = AnalysisEngineFactory.createEngine(shannonEntropyAnalysisEngineDescription); return new AnalysisEngine[] {openNlpAnalysisEngine, shannonEntropyAnalysisEngine}; }
Example 20
Source File: MeasureRegexAnnotators.java From bluima with Apache License 2.0 | 4 votes |
public static AnalysisEngineDescription getAllAED() throws ResourceInitializationException { return AnalysisEngineFactory.createEngineDescription( RegExAnnotator.class, REGEX_CONCEPTS_FILES, new String[] { CONCEPTS_CONCENTRATION, CONCEPTS_MEASURE }); }