org.apache.uima.UIMAFramework Java Examples
The following examples show how to use
org.apache.uima.UIMAFramework.
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: ProcessingUnit.java From uima-uimaj with Apache License 2.0 | 6 votes |
/** * Log CPM. * * @param level the level * @param msgBundleId the msg bundle id * @param args the args */ private void logCPM(Level level, String msgBundleId, Object[] args) { if (null == args) { args = zeroLengthObjectArray; } Object[] aa = new Object[args.length + 1]; aa[0] = Thread.currentThread().getName(); System.arraycopy(args, 0, aa, 1, args.length); UIMAFramework.getLogger(this.getClass()).logrb( level, thisClassName, "process", // used as the method name CPMUtils.CPM_LOG_RESOURCE_BUNDLE, msgBundleId, aa ); }
Example #2
Source File: ASB_impl.java From uima-uimaj with Apache License 2.0 | 6 votes |
/** * Initializes this ASB. * * @param aSpecifier * describes how to create this ASB. * @param aAdditionalParams * parameters which are passed along to the delegate Analysis Engines when they are * constructed * * @return true if and only if initialization completed successfully. Returns false if this * implementation cannot handle the given <code>ResourceSpecifier</code>. * * @see org.apache.uima.resource.Resource#initialize(ResourceSpecifier, Map) */ public boolean initialize(ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams) throws ResourceInitializationException { UIMAFramework.getLogger(CLASS_NAME).logrb(Level.CONFIG, CLASS_NAME.getName(), "initialize", LOG_RESOURCE_BUNDLE, "UIMA_asb_init_begin__CONFIG"); if (!(aSpecifier instanceof ResourceCreationSpecifier)) { return false; } // copy the additional parameters, since this method will modify them super.initialize(aSpecifier, aAdditionalParams = new HashMap<>(aAdditionalParams)); // save parameters for later mInitParams = aAdditionalParams; // save the sofa mappings of the aggregate AE that this AE is part of mSofaMappings = (SofaMapping[]) mInitParams.remove(Resource.PARAM_AGGREGATE_SOFA_MAPPINGS); // also remove them from the aAdditionalParams map, as they don't need to be passed // on to delegates // if (mSofaMappings != null) // mInitParams.remove(mInitParams.get(Resource.PARAM_AGGREGATE_SOFA_MAPPINGS)); UIMAFramework.getLogger(CLASS_NAME).logrb(Level.CONFIG, CLASS_NAME.getName(), "initialize", LOG_RESOURCE_BUNDLE, "UIMA_asb_init_successful__CONFIG"); return true; }
Example #3
Source File: InstallationTester.java From uima-uimaj with Apache License 2.0 | 6 votes |
/** * Checks if a given CI specifier file can be used to produce an instance of CI. Returns * <code>true</code>, if a CI can be instantiated, <code>false</code> otherwise. * * @param specifier the resource specifier * @param resource_manager a new resource_manager * @param status the place where to put the results * * @throws IOException * If an I/O exception occurred while creating <code>XMLInputSource</code>. * @throws InvalidXMLException * If the XML parser failed to parse the given input file. * @throws ResourceInitializationException * If the specified CI cannot be instantiated. */ private void testCasInitializer(ResourceSpecifier specifier, ResourceManager resource_manager, TestStatus status) throws IOException, InvalidXMLException, ResourceInitializationException { CasInitializer ci = UIMAFramework.produceCasInitializer(specifier, resource_manager, null); if (ci != null) { status.setRetCode(TestStatus.TEST_SUCCESSFUL); } else { status.setRetCode(TestStatus.TEST_NOT_SUCCESSFUL); status.setMessage(I18nUtil.localizeMessage(PEAR_MESSAGE_RESOURCE_BUNDLE, "installation_verification_ci_not_created", new Object[] { this.pkgBrowser .getInstallationDescriptor().getMainComponentId() }, null)); } }
Example #4
Source File: FlowControllerDeclaration_impl.java From uima-uimaj with Apache License 2.0 | 6 votes |
public synchronized void resolveImports(ResourceManager aResourceManager) throws InvalidXMLException { Import theImport = getImport(); if (theImport != null) { URL url = theImport.findAbsoluteUrl(aResourceManager); InputStream stream = null; try { stream = url.openStream(); XMLInputSource input = new XMLInputSource(url); ResourceSpecifier spec = UIMAFramework.getXMLParser().parseResourceSpecifier(input); setSpecifier(spec); setImport(null); } catch (IOException e) { throw new InvalidXMLException(e); } finally { try { if (stream != null) { stream.close(); } } catch (IOException e1) { UIMAFramework.getLogger(this.getClass()).log(Level.SEVERE, "", e1); } } } }
Example #5
Source File: CasIOUtilsTest.java From uima-uimaj with Apache License 2.0 | 6 votes |
protected void setUp() throws Exception { File indexesFile = JUnitExtension.getFile("ExampleCas/testIndexes.xml"); FsIndexDescription[] indexes = UIMAFramework.getXMLParser() .parseFsIndexCollection(new XMLInputSource(indexesFile)).getFsIndexes(); File typeSystemFile = JUnitExtension.getFile("ExampleCas/testTypeSystem.xml"); TypeSystemDescription typeSystem = UIMAFramework.getXMLParser().parseTypeSystemDescription( new XMLInputSource(typeSystemFile)); cas = CasCreationUtils.createCas(typeSystem, new TypePriorities_impl(), indexes); try (FileInputStream casInputStream = new FileInputStream( JUnitExtension.getFile("ExampleCas/simpleCas.xmi"))) { CasIOUtils.load(casInputStream, cas); } File typeSystemFile2 = JUnitExtension.getFile("ExampleCas/testTypeSystem_variation.xml"); TypeSystemDescription typeSystem2 = UIMAFramework.getXMLParser().parseTypeSystemDescription( new XMLInputSource(typeSystemFile2)); cas2 = CasCreationUtils.createCas(typeSystem2, new TypePriorities_impl(), indexes); }
Example #6
Source File: CasCreationUtilsTest.java From uima-uimaj with Apache License 2.0 | 6 votes |
public void testCreateCasTypeSystemDescription() throws Exception { try { //parse type system description TypeSystemDescription tsDesc = UIMAFramework.getXMLParser().parseTypeSystemDescription( new XMLInputSource(JUnitExtension.getFile("CasCreationUtilsTest/SupertypeMergeTestMaster.xml"))); // call method CAS cas = CasCreationUtils.createCas(tsDesc, null, null); //check that imports were resolved and supertype merged properly Type subType = cas.getTypeSystem().getType("uima.test.Sub"); assertNotNull(subType); Type superType = cas.getTypeSystem().getType("uima.test.Super"); assertNotNull(superType); assertTrue(cas.getTypeSystem().subsumes(superType,subType)); } catch (Exception e) { JUnitExtension.handleException(e); } }
Example #7
Source File: AnalysisEngineFactoryTest.java From uima-uimafit with Apache License 2.0 | 6 votes |
@Test(expected = ResourceInitializationException.class) public void testAAEMultipleDeploymentPolicyProblem() throws Exception { { AnalysisEngineDescription desc1 = AnalysisEngineFactory.createEngineDescription( PristineAnnotatorClass.class, (Object[]) null); assertTrue( "Multiple deployment should be allowed on " + desc1.getAnnotatorImplementationName(), desc1.getAnalysisEngineMetaData().getOperationalProperties() .isMultipleDeploymentAllowed()); AnalysisEngineDescription desc2 = AnalysisEngineFactory.createEngineDescription( UnannotatedAnnotatorClass.class, (Object[]) null); assertFalse( "Multiple deployment should be prohibited on " + desc2.getAnnotatorImplementationName(), desc2.getAnalysisEngineMetaData() .getOperationalProperties().isMultipleDeploymentAllowed()); AnalysisEngineDescription aae = AnalysisEngineFactory .createEngineDescription(desc1, desc2); aae.getAnalysisEngineMetaData().getOperationalProperties().setMultipleDeploymentAllowed(true); UIMAFramework.produceAnalysisEngine(aae); } }
Example #8
Source File: CasObjectNetworkCasProcessorImpl.java From uima-uimaj with Apache License 2.0 | 6 votes |
/** * Returns {@link ProcessingResourceMetaData} object returned from the remote CasProcessor. * * @return the processing resource meta data */ @Override public ProcessingResourceMetaData getProcessingResourceMetaData() { if (socket == null) { return metadata; } try { ProcessingResourceMetaData serviceMetaData = transport.getProcessingResourceMetaData(socket); if (serviceMetaData == null) { return metadata; } return serviceMetaData; } catch (Exception e) { if (UIMAFramework.getLogger().isLoggable(Level.SEVERE)) { UIMAFramework.getLogger().log(Level.SEVERE, e.getMessage(), e); } } return null; }
Example #9
Source File: JCasPool.java From uima-uimaj with Apache License 2.0 | 6 votes |
/** * Checks in a JCas to the pool. This automatically calls the {@link JCas#reset()} method, to * ensure that when the JCas is later retrieved from the pool it will be ready to use. Also * notifies other Threads that may be waiting for an instance to become available. * * @param aJCas * the JCas to release */ public synchronized void releaseJCas(JCas aJCas) { // make sure this CAS actually belongs to this pool and is checked out if (!mAllInstances.contains(aJCas) || mFreeInstances.contains(aJCas)) { UIMAFramework.getLogger(CLASS_NAME).logrb(Level.WARNING, CLASS_NAME.getName(), "releaseJCas", LOG_RESOURCE_BUNDLE, "UIMA_return_jcas_to_pool__WARNING"); } else { // reset CAS aJCas.reset(); // Add the CAS to the end of the free instances List mFreeInstances.add(aJCas); } // Notify any threads waiting on this object notifyAll(); }
Example #10
Source File: IndexSection.java From uima-uimaj with Apache License 2.0 | 6 votes |
/** * Adds the or edit index key. * * @param dialog the dialog * @param key the key * @return the fs index key description */ public FsIndexKeyDescription addOrEditIndexKey(AddIndexKeyDialog dialog, FsIndexKeyDescription key) { if (dialog.open() == Window.CANCEL) { return null; } if (null == key) key = UIMAFramework.getResourceSpecifierFactory().createFsIndexKeyDescription(); if (dialog.typePriority) { key.setTypePriority(setValueChangedBoolean(true, key.isTypePriority())); key.setFeatureName(null); } else { key.setFeatureName(setValueChanged(dialog.featureName, key.getFeatureName())); key.setComparator(setValueChangedInt(dialog.direction, key.getComparator())); key.setTypePriority(false); } return key; }
Example #11
Source File: XMLUtils.java From uima-uimaj with Apache License 2.0 | 6 votes |
public static DocumentBuilderFactory createDocumentBuilderFactory() { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); try { if ( ! IS_XML_ENABLE_DOCTYPE_DECL) { // https://issues.apache.org/jira/browse/UIMA-6064 documentBuilderFactory.setFeature(DISALLOW_DOCTYPE_DECL, true); } } catch (ParserConfigurationException e1) { UIMAFramework.getLogger().log(Level.WARNING, "DocumentBuilderFactory didn't recognize setting feature " + DISALLOW_DOCTYPE_DECL); } try { documentBuilderFactory.setFeature(LOAD_EXTERNAL_DTD, false); } catch (ParserConfigurationException e) { UIMAFramework.getLogger().log(Level.WARNING, "DocumentBuilderFactory doesn't support feature " + LOAD_EXTERNAL_DTD); } documentBuilderFactory.setXIncludeAware(false); documentBuilderFactory.setExpandEntityReferences(false); return documentBuilderFactory; }
Example #12
Source File: InstallationTester.java From uima-uimaj with Apache License 2.0 | 6 votes |
/** * Checks if a given CPE specifier file can be used to produce an instance of CPE. Returns * <code>true</code>, if a CPE can be instantiated, <code>false</code> otherwise. * * @param specifier the resource specifier * @param resource_manager a new resource_manager * @param status the place where to put the results * * @throws IOException * If an I/O exception occurred while creating <code>XMLInputSource</code>. * @throws InvalidXMLException * If the XML parser failed to parse the given input file. * @throws ResourceInitializationException * If the specified CPE cannot be instantiated. */ private void testCpeCongifuration(ResourceSpecifier specifier, ResourceManager resource_manager, TestStatus status) throws IOException, InvalidXMLException, ResourceInitializationException { CollectionProcessingEngine cpe = UIMAFramework.produceCollectionProcessingEngine( (CpeDescription) specifier, resource_manager, null); if (cpe != null) { status.setRetCode(TestStatus.TEST_SUCCESSFUL); } else { status.setRetCode(TestStatus.TEST_NOT_SUCCESSFUL); status.setMessage(I18nUtil.localizeMessage(PEAR_MESSAGE_RESOURCE_BUNDLE, "installation_verification_cpe_not_created", new Object[] { this.pkgBrowser .getInstallationDescriptor().getMainComponentId() }, null)); } }
Example #13
Source File: ExternalResourceFactoryTest.java From uima-uimafit with Apache License 2.0 | 6 votes |
/** * This is a test for a regression introduced in the UIMA SDK 2.6.0 RC 1 and which worked in UIMA SDK 2.5.0. * <ul> * <li>Add a full delegate description to an AAE.</li> * <li>Serialize to XML: delegate description is serialized.</li> * <li>Call resolveImports()</li> * <li>Serialize to XML: delegate description is no longer serialized.</li> * </ul> * * @see <a href="https://issues.apache.org/jira/browse/UIMA-3776">UIMA-3776</a> */ @Test public void testNoDelegatesToResolve() throws Exception { ResourceSpecifierFactory f = UIMAFramework.getResourceSpecifierFactory(); AnalysisEngineDescription outer = f.createAnalysisEngineDescription(); AnalysisEngineDescription inner = f.createAnalysisEngineDescription(); outer.getDelegateAnalysisEngineSpecifiersWithImports().put("inner", inner); StringWriter outerXml = new StringWriter(); outer.toXML(outerXml); // Resolving the imports removes the inner AE description outer.resolveImports(ResourceManagerFactory.newResourceManager()); StringWriter outerXml2 = new StringWriter(); outer.toXML(outerXml2); Assert.assertEquals(outerXml.toString(), outerXml2.toString()); }
Example #14
Source File: Jg.java From uima-uimaj with Apache License 2.0 | 6 votes |
/** * Creates the resource manager. * * @return the resource manager */ public ResourceManager createResourceManager() { ResourceManager resourceManager = UIMAFramework.newDefaultResourceManager(); if (classPath != null && classPath.trim().length() > 0) { try { resourceManager.setExtensionClassPath(this.getClass().getClassLoader(), classPath, true); } catch (MalformedURLException e1) { error.newError(IError.ERROR, getString("Internal Error", null), e1); } } else { resourceManager.setExtensionClassLoader(this.getClass().getClassLoader(), true); } return resourceManager; }
Example #15
Source File: AggregateWithReaderTest.java From uima-uimafit with Apache License 2.0 | 5 votes |
/** * Demo of running a collection reader as part of an aggregate engine. This allows to run a * pipeline an access the output CASes directly - no need to write the data to files. */ @Test public void demoAggregateWithReader() throws UIMAException { ResourceSpecifierFactory factory = UIMAFramework.getResourceSpecifierFactory(); CollectionReaderDescription reader = factory.createCollectionReaderDescription(); reader.getMetaData().setName("reader"); reader.setImplementationName(SimpleReader.class.getName()); AnalysisEngineDescription analyzer = factory.createAnalysisEngineDescription(); analyzer.getMetaData().setName("analyzer"); analyzer.setPrimitive(true); analyzer.setImplementationName(SimpleAnalyzer.class.getName()); FixedFlow flow = factory.createFixedFlow(); flow.setFixedFlow(new String[] { "reader", "analyzer" }); AnalysisEngineDescription aggregate = factory.createAnalysisEngineDescription(); aggregate.getMetaData().setName("aggregate"); aggregate.getAnalysisEngineMetaData().setFlowConstraints(flow); aggregate.getAnalysisEngineMetaData().getOperationalProperties().setOutputsNewCASes(true); aggregate.getAnalysisEngineMetaData().getOperationalProperties() .setMultipleDeploymentAllowed(false); aggregate.setPrimitive(false); aggregate.getDelegateAnalysisEngineSpecifiersWithImports().put("reader", reader); aggregate.getDelegateAnalysisEngineSpecifiersWithImports().put("analyzer", analyzer); AnalysisEngine pipeline = UIMAFramework.produceAnalysisEngine(aggregate); CasIterator iterator = pipeline.processAndOutputNewCASes(pipeline.newCAS()); while (iterator.hasNext()) { CAS cas = iterator.next(); System.out.printf("[%s] is [%s]%n", cas.getDocumentText(), cas.getDocumentLanguage()); } }
Example #16
Source File: KnowNER.java From ambiverse-nlu with Apache License 2.0 | 5 votes |
private AnalysisEngine initializeClassifier(String language) throws ResourceInitializationException, SQLException { logger.debug("Initializing KnowNER for '" + language + "'."); long start = System.currentTimeMillis(); List<AnalysisEngineDescription> descriptions = new ArrayList<>(); if (model.equals("NED")) { descriptions.add(AnalysisEngineFactory.createEngineDescription(BmeowTypeAnnotator.class, BmeowTypeAnnotator.GOLD, false)); descriptions.add(AnalysisEngineFactory.createEngineDescription(RemoveNamedEntityAnnotator.class)); } descriptions.add(AnalysisEngineFactory.createEngineDescription(DictionaryMatchAnnotator.class, DictionaryMatchAnnotator.PARAM_LANGUAGE, language)); descriptions.add(AnalysisEngineFactory.createEngineDescription(DictionaryFeaturesAnnotator.class, DictionaryFeaturesAnnotator.PARAM_LANGUAGE, language)); descriptions.add(createEngineDescription(LocalFeaturesTcAnnotator.class, TcAnnotator.PARAM_TC_MODEL_LOCATION, KnowNERSettings.getModelPath(language, model).toFile(), LocalFeaturesTcAnnotator.PARAM_LANGUAGE, language, TcAnnotator.PARAM_NAME_SEQUENCE_ANNOTATION, Sentence.class.getName(), TcAnnotator.PARAM_NAME_UNIT_ANNOTATION, Token.class.getName())); descriptions.add(createEngineDescription(KnowNERNamedEntityPostClassificationBMEOWAnnotator.class)); AnalysisEngineDescription[] analysisEngineDescriptions = new AnalysisEngineDescription[descriptions.size()]; for (int i = 0; i < descriptions.size(); i++) { analysisEngineDescriptions[i] = descriptions.get(i); } ResourceManager mgr = ((UimaContextAdmin) getContext()).getResourceManager(); AnalysisEngine ae = UIMAFramework.produceAnalysisEngine( createEngineDescription(analysisEngineDescriptions), mgr, null); long dur = System.currentTimeMillis() - start; logger.info("Initialized KnowNER-" + language + " in " + dur/1000 + "s."); return ae; }
Example #17
Source File: AnalysisEngine_implTest.java From uima-uimaj with Apache License 2.0 | 5 votes |
public void testManyDelegates() throws Exception { // test with and without validation - UIMA-2453 UIMAFramework.getXMLParser().enableSchemaValidation(true); try { manyDelegatesCommon(); } finally { UIMAFramework.getXMLParser().enableSchemaValidation(false); } manyDelegatesCommon(); }
Example #18
Source File: TypeSystemReinitTest.java From uima-uimaj with Apache License 2.0 | 5 votes |
public void testReinitCASCompleteSerializer() throws Exception { try { AnalysisEngineDescription aed = UIMAFramework.getXMLParser().parseAnalysisEngineDescription( new XMLInputSource(JUnitExtension .getFile("TextAnalysisEngineImplTest/TestPrimitiveTae1.xml"))); TypeSystemDescription tsd = UIMAFramework.getXMLParser().parseTypeSystemDescription( new XMLInputSource(getClass().getResource("/org/apache/uima/examples/SourceDocumentInformation.xml"))); List<MetaDataObject> l = new ArrayList<>(); l.add(aed); l.add(tsd); CAS cas1 = CasCreationUtils.createCas(l); cas1.setDocumentText("foo"); CASCompleteSerializer ser = Serialization.serializeCASComplete((CASMgr) cas1); CAS tcas2 = CasCreationUtils.createCas(new TypeSystemDescription_impl(), null, null); CASImpl cas2 = ((CASImpl) tcas2).getBaseCAS(); tcas2.setDocumentText("bar"); // reinit // This uses cas2 which only has a base type system to start, // and loads it from a complete serialization which has other new types cas2.getBinaryCasSerDes().reinit(ser); CAS tcas3 = cas2.getCurrentView(); assertTrue(tcas2 == tcas3); assertNotNull(cas1.getTypeSystem().getType("NamedEntity")); assertNotNull(tcas3.getTypeSystem().getType("NamedEntity")); FeatureStructure fs = tcas3.createFS(tcas3.getTypeSystem().getType("NamedEntity")); tcas3.getIndexRepository().addFS(fs); } catch (Exception e) { JUnitExtension.handleException(e); } }
Example #19
Source File: AnalysisEngine_implTest.java From uima-uimaj with Apache License 2.0 | 5 votes |
public void testCollectionProcessComplete() throws Exception { try { // test simple primitive TextAnalysisEngine (using TestAnnotator class) AnalysisEngineDescription primitiveDesc = new AnalysisEngineDescription_impl(); primitiveDesc.setPrimitive(true); primitiveDesc .setAnnotatorImplementationName("org.apache.uima.analysis_engine.impl.TestAnnotator"); primitiveDesc.getMetaData().setName("Test Primitive TAE"); PrimitiveAnalysisEngine_impl ae = new PrimitiveAnalysisEngine_impl(); ae.initialize(primitiveDesc, null); ae.collectionProcessComplete(new ProcessTrace_impl()); // test simple aggregate TextAnalysisEngine (again using TestAnnotator class) AnalysisEngineDescription aggDesc = new AnalysisEngineDescription_impl(); aggDesc.setPrimitive(false); aggDesc.getMetaData().setName("Test Aggregate TAE"); aggDesc.getDelegateAnalysisEngineSpecifiersWithImports().put("Test", primitiveDesc); FixedFlow_impl flow = new FixedFlow_impl(); aggDesc.getAnalysisEngineMetaData().setFlowConstraints(flow); AggregateAnalysisEngine_impl aggAe = new AggregateAnalysisEngine_impl(); aggAe.initialize(aggDesc, null); aggAe.collectionProcessComplete(new ProcessTrace_impl()); //test that fixedFlow order is used File descFile = JUnitExtension.getFile("TextAnalysisEngineImplTest/AggregateForCollectionProcessCompleteTest.xml"); AnalysisEngineDescription cpcTestDesc = UIMAFramework.getXMLParser().parseAnalysisEngineDescription(new XMLInputSource(descFile)); AnalysisEngine cpcTestAe = UIMAFramework.produceAnalysisEngine(cpcTestDesc); cpcTestAe.collectionProcessComplete(); assertEquals("One", AnnotatorForCollectionProcessCompleteTest.lastValue); } catch (Exception e) { JUnitExtension.handleException(e); } }
Example #20
Source File: StatusCallbackListenerImpl.java From uima-uimaj with Apache License 2.0 | 5 votes |
/** * Called when the initialization is completed. * * @see org.apache.uima.collection.processing.StatusCallbackListener#initializationComplete() */ public void initializationComplete() { if (UIMAFramework.getLogger().isLoggable(Level.CONFIG)) { UIMAFramework.getLogger(this.getClass()).logrb(Level.CONFIG, this.getClass().getName(), "process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE, "UIMA_CPM_cpm_init_complete__CONFIG", new Object[] { Thread.currentThread().getName() }); } }
Example #21
Source File: FunctionErrorStore.java From uima-uimaj with Apache License 2.0 | 5 votes |
protected FunctionErrorStore(String exception, int functionCount, String functionName) { functionCounter = functionCount; functionError = exception; this.functionName = functionName; logger = UIMAFramework.getLogger(this.getClass()); // logger = Logger_impl.getInstance(); }
Example #22
Source File: AnalysisEngineFactoryExternalResourceTest.java From uima-uimafit with Apache License 2.0 | 5 votes |
AnalysisEngineDescription saveLoad(AnalysisEngineDescription aDesc) throws InvalidXMLException, SAXException, IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); aDesc.toXML(bos); return UIMAFramework.getXMLParser().parseAnalysisEngineDescription( new XMLInputSource(new ByteArrayInputStream(bos.toByteArray()), null)); }
Example #23
Source File: CasCreationUtilsTest.java From uima-uimaj with Apache License 2.0 | 5 votes |
private TypeSystemDescription checkMergeTypeSystem(TypeSystemDescription ts1desc, String typeFile, String msgKey) throws Exception { TypeSystemDescription mergedTS = null; try { TypeSystemDescription ts2desc = UIMAFramework .getXMLParser() .parseTypeSystemDescription( new XMLInputSource( JUnitExtension .getFile("CasCreationUtilsTest/" + typeFile))); List<TypeSystemDescription> tsList = new ArrayList<>(); tsList.add(ts1desc); tsList.add(ts2desc); boolean rightExceptionThrown = (null != msgKey) ? false : true; try { mergedTS = CasCreationUtils.mergeTypeSystems( tsList, UIMAFramework.newDefaultResourceManager(), new HashMap()); } catch (ResourceInitializationException rie) { rightExceptionThrown = (null != msgKey) && rie.hasMessageKey(msgKey); } assertTrue(rightExceptionThrown); } catch (Exception e) { JUnitExtension.handleException(e); } return mergedTS; }
Example #24
Source File: AggregateWithReaderTest.java From uima-uimafit with Apache License 2.0 | 5 votes |
/** * Demo of disguising a reader as a CAS multiplier. This works because internally, UIMA wraps the * reader in a CollectionReaderAdapter. This nice thing about this is, that in principle it would * be possible to define sofa mappings. However, UIMA-2419 prevents this. */ @Test public void demoAggregateWithDisguisedReader() throws UIMAException { ResourceSpecifierFactory factory = UIMAFramework.getResourceSpecifierFactory(); AnalysisEngineDescription reader = factory.createAnalysisEngineDescription(); reader.getMetaData().setName("reader"); reader.setPrimitive(true); reader.setImplementationName(SimpleReader.class.getName()); reader.getAnalysisEngineMetaData().getOperationalProperties().setOutputsNewCASes(true); AnalysisEngineDescription analyzer = factory.createAnalysisEngineDescription(); analyzer.getMetaData().setName("analyzer"); analyzer.setPrimitive(true); analyzer.setImplementationName(SimpleAnalyzer.class.getName()); FixedFlow flow = factory.createFixedFlow(); flow.setFixedFlow(new String[] { "reader", "analyzer" }); AnalysisEngineDescription aggregate = factory.createAnalysisEngineDescription(); aggregate.getMetaData().setName("aggregate"); aggregate.setPrimitive(false); aggregate.getAnalysisEngineMetaData().setFlowConstraints(flow); aggregate.getAnalysisEngineMetaData().getOperationalProperties().setOutputsNewCASes(true); aggregate.getAnalysisEngineMetaData().getOperationalProperties() .setMultipleDeploymentAllowed(false); aggregate.getDelegateAnalysisEngineSpecifiersWithImports().put("reader", reader); aggregate.getDelegateAnalysisEngineSpecifiersWithImports().put("analyzer", analyzer); AnalysisEngine pipeline = UIMAFramework.produceAnalysisEngine(aggregate); CasIterator iterator = pipeline.processAndOutputNewCASes(pipeline.newCAS()); while (iterator.hasNext()) { CAS cas = iterator.next(); System.out.printf("[%s] is [%s]%n", cas.getDocumentText(), cas.getDocumentLanguage()); } }
Example #25
Source File: Capability_impl.java From uima-uimaj with Apache License 2.0 | 5 votes |
/** * @see org.apache.uima.resource.metadata.Capability#addOutputType(java.lang.String, * boolean) */ public void addOutputType(String aTypeName, boolean aAllAnnotatorFeatures) { TypeOrFeature type = UIMAFramework.getResourceSpecifierFactory().createTypeOrFeature(); type.setType(true); type.setName(aTypeName); type.setAllAnnotatorFeatures(aAllAnnotatorFeatures); TypeOrFeature[] oldArr = getOutputs(); TypeOrFeature[] newArr = new TypeOrFeature[oldArr.length + 1]; System.arraycopy(oldArr, 0, newArr, 0, oldArr.length); newArr[newArr.length - 1] = type; setOutputs(newArr); }
Example #26
Source File: Settings_impl.java From uima-uimaj with Apache License 2.0 | 5 votes |
/** * Load properties from an input stream. * Existing properties are not changed and a warning is logged if the new value is different. * May be called multiple times, so effective search is in load order. * Arrays are enclosed in [] and the elements may be separated by <code>,</code> or new-line, so * can span multiple lines without using a final \ * * @param in - Stream holding properties * @throws IOException if name characters illegal */ public void load(InputStream in) throws IOException { // Process each logical line (after blanks & comments removed and continuations extended) rdr = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8)); String line; final String legalPunc = "./-~_"; // Acceptable punctuation characters while ((line = getLine()) != null) { // Remove surrounding white-space and split on first '=' or ':' or white-space String[] parts = line.split("\\s*[:=\\s]\\s*", 2); String name = parts[0]; // Restrict names to alphanumeric plus "joining" punctuation: ./-~_ boolean validName = name.length() > 0; for (int i = 0; i < name.length() && validName; ++i) { validName = Character.isLetterOrDigit(name.charAt(i)) || legalPunc.indexOf(name.charAt(i))>=0; } if (!validName) { throw new IOException("Invalid name '" + name + "' --- characters must be alphanumeric or " + legalPunc); } String value; // When RHS is empty get a split only for the := separators if (parts.length == 1) { value = ""; } else { value = parts[1]; if (value.length() > 0 && value.charAt(0) == '[') { value = getArray(value); } } if (!map.containsKey(name)) { map.put(name, value); } else { if (!value.equals(map.get(name))) { // Key {0} already in use ... ignoring value "{1}" UIMAFramework.getLogger(this.getClass()).logrb(Level.CONFIG, this.getClass().getName(), "load", LOG_RESOURCE_BUNDLE, "UIMA_external_override_ignored__CONFIG", new Object[] { name, value }); } } } }
Example #27
Source File: ExternalResourceFactoryTest.java From uima-uimafit with Apache License 2.0 | 5 votes |
@Test public void testScanBind() throws Exception { // Create analysis enginge description AnalysisEngineDescription desc = createEngineDescription(DummyAE.class); // Bind external resources bindResources(desc); // Test with the default resource manager implementation AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(desc); assertNotNull(ae); }
Example #28
Source File: SofaTest.java From uima-uimaj with Apache License 2.0 | 5 votes |
public void testGetViewIterator() throws Exception { this.cas.reset(); CAS view1 = this.cas.createView("View1"); CAS view2 = this.cas.createView("View2"); checkViewsExist(this.cas.getViewIterator(), cas, view1, view2); CAS viewE1 = this.cas.createView("EnglishDocument"); CAS viewE2 = this.cas.createView("EnglishDocument.2"); checkViewsExist(this.cas.getViewIterator("EnglishDocument"), viewE1, viewE2); //try with Sofa mappings UimaContextAdmin rootCtxt = UIMAFramework.newUimaContext( UIMAFramework.getLogger(), UIMAFramework.newDefaultResourceManager(), UIMAFramework.newConfigurationManager()); Map<String, String> sofamap = new HashMap<>(); sofamap.put("SourceDocument","EnglishDocument"); UimaContextAdmin childCtxt = rootCtxt.createChild("test", sofamap); cas.setCurrentComponentInfo(childCtxt.getComponentInfo()); checkViewsExist(this.cas.getViewIterator("SourceDocument"), viewE1, viewE2); this.cas.setCurrentComponentInfo(null); //repeat with JCas this.cas.reset(); JCas jcas = this.cas.getJCas(); JCas jview1 = jcas.createView("View1"); JCas jview2 = jcas.createView("View2"); checkViewsExist(jcas.getViewIterator(), jcas, jview1, jview2); JCas jviewE1 = jcas.createView("EnglishDocument"); JCas jviewE2 = jcas.createView("EnglishDocument.2"); checkViewsExist(jcas.getViewIterator("EnglishDocument"), jviewE1, jviewE2); //try with Sofa mappings cas.setCurrentComponentInfo(childCtxt.getComponentInfo()); checkViewsExist(jcas.getViewIterator("SourceDocument"), jviewE1, jviewE2); }
Example #29
Source File: FsIterator_aggregation_common.java From uima-uimaj with Apache License 2.0 | 5 votes |
/** * MoveTo for this kind of iterator * Happens for set or sorted indexes being operated without rattling, or for other kinds of aggregation. * * The meaning for set is to go to the position if it exists of the 1 element equal (using the index's comparator) the arg. * But since the set is unordered, there's no point in doing this. * * The meaning for unordered other kinds: They're not really unordered, just the aggregate is unordered. * A use would be to partially restart iteration from some point. * But since this is unordered, there's not much point in doing this * */ public void moveToNoReinit(FeatureStructure fs) { Misc.decreasingWithTrace(moveTo_error_msg_count, "MoveTo operations on unsorted iterators are likely mistakes." , UIMAFramework.getLogger()); // Type typeCompare = fs.getType(); int i = -1; int validNonMatch = -1; for (LowLevelIterator<T> it : nonEmptyIterators) { i++; // Type itType = (TypeImpl) it.getType(); // if ( ! typeCompare.subsumes(itType) ) { // continue; // } it.moveToNoReinit(fs); if (it.isValid() && 0 == it.ll_getIndex().compare(fs, it.getNvc())) { current_it_idx = i; return; // perfect match } if (validNonMatch == -1 && it.isValid()) { validNonMatch = i; // capture first valid non-Match } } // nothing matched using iterator compare if (validNonMatch >= 0) { current_it_idx = validNonMatch; return; } // mark iterator invalid otherwise current_it_idx = -1; }
Example #30
Source File: AnnotatorTester.java From uima-uimaj with Apache License 2.0 | 5 votes |
/** * does configuration parameter test. * * @param configDescFilePath the config desc file path * @return AnalysisEngine * @throws Exception passthru */ public static AnalysisEngine doConfigurationTest(String configDescFilePath) throws Exception { try { AnalysisEngine ae = null; // Create an XML input source from the specifier file. XMLInputSource in = new XMLInputSource(configDescFilePath); // Parse the specifier. ResourceSpecifier specifier = UIMAFramework.getXMLParser() .parseResourceSpecifier(in); // Create the Text Analysis Engine. ae = UIMAFramework.produceAnalysisEngine(specifier, null, null); // Create a new CAS. CAS cas = ae.newCAS(); // Set the document text on the CAS. cas .setDocumentText("This is a simple text to check if the configuration works"); cas.setDocumentLanguage("en"); // Process the sample document. ae.process(cas); return ae; } catch (Exception ex) { JUnitExtension.handleException(ex); } return null; }