org.apache.uima.resource.ResourceManager Java Examples
The following examples show how to use
org.apache.uima.resource.ResourceManager.
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: MultiPageEditor.java From uima-uimaj with Apache License 2.0 | 6 votes |
/** * Sets the merged type system description. * * @throws ResourceInitializationException the resource initialization exception */ public void setMergedTypeSystemDescription() throws ResourceInitializationException { mergedTypesAddingFeatures.clear(); if (isAggregate()) mergedTypeSystemDescription = mergeDelegateAnalysisEngineTypeSystems( (AnalysisEngineDescription) aeDescription.clone(), createResourceManager(), mergedTypesAddingFeatures); else { if (null == typeSystemDescription) { mergedTypeSystemDescription = null; } else { ResourceManager resourceManager = createResourceManager(); Collection tsdc = new ArrayList(1); tsdc.add(typeSystemDescription.clone()); // System.out.println("mergingTypeSystem 2"); //$NON-NLS-1$ // long time = System.currentTimeMillis(); mergedTypeSystemDescription = CasCreationUtils.mergeTypeSystems(tsdc, resourceManager, mergedTypesAddingFeatures); // System.out.println("Finished mergingTypeSystem 2; time= " + //$NON-NLS-1$ // (System.currentTimeMillis() - time)); setImportedTypeSystemDescription(); } } }
Example #2
Source File: ExternalResourceInitializer.java From uima-uimafit with Apache License 2.0 | 6 votes |
/** * Get all resources declared in the context. */ private static Collection<?> getResources(UimaContext aContext) throws ResourceInitializationException { if (!(aContext instanceof UimaContextAdmin)) { return Collections.emptyList(); } ResourceManager resMgr = ((UimaContextAdmin) aContext).getResourceManager(); if (!(resMgr instanceof ResourceManager_impl)) { // Unfortunately there is not official way to access the list of resources. Thus we // have to rely on the UIMA implementation details and access the internal resource // map via reflection. If the resource manager is not derived from the default // UIMA resource manager, then we cannot really do anything here. throw new IllegalStateException("Unsupported resource manager implementation [" + resMgr.getClass() + "]"); } return resMgr.getExternalResources(); }
Example #3
Source File: InstallationTester.java From uima-uimaj with Apache License 2.0 | 6 votes |
/** * Checks if a given analysis engine specifier file can be used to produce an instance of analysis * engine. Returns <code>true</code>, if an analysis engine 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 AE cannot be instantiated. */ private void testAnalysisEngine(ResourceSpecifier specifier, ResourceManager resource_manager, TestStatus status) throws IOException, InvalidXMLException, ResourceInitializationException { AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(specifier, resource_manager, null); //create CAS from the analysis engine CAS cas = null; if (ae != null) { cas = ae.newCAS(); } //check test result if (ae != null && cas != null) { status.setRetCode(TestStatus.TEST_SUCCESSFUL); } else { status.setRetCode(TestStatus.TEST_NOT_SUCCESSFUL); status.setMessage(I18nUtil.localizeMessage(PEAR_MESSAGE_RESOURCE_BUNDLE, "installation_verification_ae_not_created", new Object[] { this.pkgBrowser .getInstallationDescriptor().getMainComponentId() }, null)); } }
Example #4
Source File: CasCreationUtils.java From uima-uimaj with Apache License 2.0 | 6 votes |
/** * Merges the FS Index Collections of each component within an aggregate Analysis Engine, * producing a single combined FS Index Collection. * * @param aAggregateDescription * an aggregate Analysis Engine description * @param aResourceManager * ResourceManager instance used to resolve imports * * @return a new FsIndexCollection that is the result of merging all of the delegate AE * FsIndexCollections together * * @throws ResourceInitializationException * if an incompatibility exists or if an import could not be resolved */ public static FsIndexCollection mergeDelegateAnalysisEngineFsIndexCollections( AnalysisEngineDescription aAggregateDescription, ResourceManager aResourceManager) throws ResourceInitializationException { // expand the aggregate AE description into the individual delegates List<AnalysisEngineDescription> l = new ArrayList<>(); l.add(aAggregateDescription); List<ProcessingResourceMetaData> mdList = getMetaDataList(l, aResourceManager); // extract FsIndexCollections and merge List<FsIndexCollection> fsIndexes = new ArrayList<>(); Iterator<ProcessingResourceMetaData> it = mdList.iterator(); while (it.hasNext()) { ProcessingResourceMetaData md = it.next(); if (md.getFsIndexCollection() != null) fsIndexes.add(md.getFsIndexCollection()); } return mergeFsIndexes(fsIndexes, aResourceManager); }
Example #5
Source File: InstallationTester.java From uima-uimaj with Apache License 2.0 | 6 votes |
/** * Checks if a given CC specifier file can be used to produce an instance of CC. Returns * <code>true</code>, if a CC 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 CC cannot be instantiated. */ private void testCasConsumer(ResourceSpecifier specifier, ResourceManager resource_manager, TestStatus status) throws IOException, InvalidXMLException, ResourceInitializationException { CasConsumer cc = UIMAFramework.produceCasConsumer(specifier, resource_manager, null); if (cc != null) { status.setRetCode(TestStatus.TEST_SUCCESSFUL); } else { status.setRetCode(TestStatus.TEST_NOT_SUCCESSFUL); status.setMessage(I18nUtil.localizeMessage(PEAR_MESSAGE_RESOURCE_BUNDLE, "installation_verification_cc_not_created", new Object[] { this.pkgBrowser .getInstallationDescriptor().getMainComponentId() }, null)); } }
Example #6
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 #7
Source File: InstallationTester.java From uima-uimaj with Apache License 2.0 | 6 votes |
/** * Checks if a given CR specifier file can be used to produce an instance of CR. Returns * <code>true</code>, if a CR 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 CR cannot be instantiated. */ private void testCollectionReader(ResourceSpecifier specifier, ResourceManager resource_manager, TestStatus status) throws IOException, InvalidXMLException, ResourceInitializationException { CollectionReader cr = UIMAFramework.produceCollectionReader(specifier, resource_manager, null); if (cr != null) { status.setRetCode(TestStatus.TEST_SUCCESSFUL); } else { status.setRetCode(TestStatus.TEST_NOT_SUCCESSFUL); status.setMessage(I18nUtil.localizeMessage(PEAR_MESSAGE_RESOURCE_BUNDLE, "installation_verification_cr_not_created", new Object[] { this.pkgBrowser .getInstallationDescriptor().getMainComponentId() }, null)); } }
Example #8
Source File: UIMAClassLoaderTest.java From uima-uimaj with Apache License 2.0 | 6 votes |
public void testSimpleRsrcMgrCLassLoaderCreation() throws Exception { ResourceManager rsrcMgr = UIMAFramework.newDefaultResourceManager(); assertNull(rsrcMgr.getExtensionClassLoader()); rsrcMgr.setExtensionClassPath("../this/is/a/simple/test.jar", false); ClassLoader cl = rsrcMgr.getExtensionClassLoader(); assertNotNull(cl); //assertTrue(cl != cl.getClassLoadingLock("Aclass")); Class classOfLoader = cl.getClass().getSuperclass(); while (!(classOfLoader.getName().equals("java.lang.ClassLoader"))) { classOfLoader = classOfLoader.getSuperclass(); } if (!Misc.isJava9ea) { // skip for java 9 Method m = classOfLoader.getDeclaredMethod("getClassLoadingLock", String.class); m.setAccessible(true); Object o = m.invoke(cl, "someString"); Object o2 = m.invoke(cl, "s2"); assertTrue(o != o2); assertTrue(cl != o); } }
Example #9
Source File: UIMAFramework.java From uima-uimaj with Apache License 2.0 | 6 votes |
/** * Gets a new instance of a {@link UimaContext}. Applications do not generally need to call this * method. * * @param aLogger * the logger that will be returned by this UimaContext's {@link #getLogger()} method. * @param aResourceManager * the ResourceManager that will be used by this UimaContext to locate and access * external resource. * @param aConfigManager * the ConfigurationManager that will be used by this UimaContext to manage Configuration * Parameter settings. * * @return a new UIMA Context to be used by the application. */ public static UimaContextAdmin newUimaContext(Logger aLogger, ResourceManager aResourceManager, ConfigurationManager aConfigManager) { // We use an ugly trick to make the 3 values available to the new UIMA context during its initialization - // we put them in threadlocals for this class (UIMAFramework). UimaContextAdmin context; try { newContextResourceManager.set(aResourceManager); newContextConfigManager.set(aConfigManager); context = getInstance()._newUimaContext(); } finally { newContextResourceManager.set(null); newContextConfigManager.set(null); } context.initializeRoot(aLogger, aResourceManager, aConfigManager); return context; }
Example #10
Source File: CollectionProcessingEngine_implTest.java From uima-uimaj with Apache License 2.0 | 6 votes |
public void testExternalResoures() throws Exception { try { ResourceManager rm = UIMAFramework.newDefaultResourceManager(); rm.setDataPath(TEST_DATAPATH); CpeDescription cpeDesc = UIMAFramework.getXMLParser().parseCpeDescription( new XMLInputSource(JUnitExtension .getFile("CollectionProcessingEngineImplTest/externalResourceTestCpe.xml"))); CollectionProcessingEngine cpe = UIMAFramework.produceCollectionProcessingEngine(cpeDesc, rm, null); CollectionReader colRdr = (CollectionReader) cpe.getCollectionReader(); assertNotNull(colRdr.getUimaContext().getResourceObject("TestFileResource")); CasInitializer casIni = colRdr.getCasInitializer(); assertNotNull(casIni.getUimaContext().getResourceObject("TestFileLanguageResource", new String[] { "en" })); AnalysisEngine ae = (AnalysisEngine) cpe.getCasProcessors()[0]; assertNotNull(ae.getUimaContext().getResourceObject("TestResourceObject")); assertNotNull(ae.getUimaContext().getResourceObject("TestLanguageResourceObject", new String[] { "en" })); } catch (Exception e) { JUnitExtension.handleException(e); } }
Example #11
Source File: FlowControllerDescription_impl.java From uima-uimaj with Apache License 2.0 | 6 votes |
public void doFullValidation(ResourceManager aResourceManager) throws ResourceInitializationException { // check that user class was specified if (getImplementationName() == null || getImplementationName().length() == 0) { throw new ResourceInitializationException( ResourceInitializationException.MISSING_IMPLEMENTATION_CLASS_NAME, new Object[] { getSourceUrlString() }); } // try to load user class // use UIMA extension ClassLoader if available Class<?> implClass; try { implClass = Class_TCCL.forName(getImplementationName(), aResourceManager); } catch (ClassNotFoundException e) { throw new ResourceInitializationException(ResourceInitializationException.CLASS_NOT_FOUND, new Object[] { getImplementationName(), getSourceUrlString() }, e); } // verify the user class implements FlowController if (!FlowController.class.isAssignableFrom(implClass)) { throw new ResourceInitializationException( ResourceInitializationException.RESOURCE_DOES_NOT_IMPLEMENT_INTERFACE, new Object[] { getImplementationName(), FlowController.class.getName(), getSourceUrlString() }); } }
Example #12
Source File: CasCreationUtils.java From uima-uimaj with Apache License 2.0 | 6 votes |
/** * Merges a List of TypePriorities into a single TypePriorities object. * * @param aTypePriorities * list of TypePriorities objects * @param aResourceManager * ResourceManager instance to use to resolve imports * * @return a merged TypePriorities object * @throws ResourceInitializationException * if an import could not be resolved */ public static TypePriorities mergeTypePriorities(List<? extends TypePriorities> aTypePriorities, ResourceManager aResourceManager) throws ResourceInitializationException { TypePriorities aggTypePriorities = UIMAFramework.getResourceSpecifierFactory() .createTypePriorities(); Iterator<? extends TypePriorities> it = aTypePriorities.iterator(); while (it.hasNext()) { TypePriorities tp = it.next(); try { tp.resolveImports(aResourceManager); } catch (InvalidXMLException e) { throw new ResourceInitializationException(e); } TypePriorityList[] pls = tp.getPriorityLists(); if (pls != null) { for (int i = 0; i < pls.length; i++) { aggTypePriorities.addPriorityList(pls[i]); } } } return aggTypePriorities; }
Example #13
Source File: CasCreationUtilsTest.java From uima-uimaj with Apache License 2.0 | 5 votes |
public void testCreateCasCollectionPropertiesResourceManager() throws Exception { try { // parse an AE descriptor File taeDescriptorWithImport = JUnitExtension .getFile("CasCreationUtilsTest/TaeWithImports.xml"); AnalysisEngineDescription desc = UIMAFramework.getXMLParser().parseAnalysisEngineDescription( new XMLInputSource(taeDescriptorWithImport)); // create Resource Manager & set data path - necessary to resolve imports ResourceManager resMgr = UIMAFramework.newDefaultResourceManager(); String pathSep = System.getProperty("path.separator"); resMgr.setDataPath(JUnitExtension.getFile("TypeSystemDescriptionImplTest/dataPathDir") .getAbsolutePath() + pathSep + JUnitExtension.getFile("TypePrioritiesImplTest/dataPathDir").getAbsolutePath() + pathSep + JUnitExtension.getFile("FsIndexCollectionImplTest/dataPathDir").getAbsolutePath()); // call method ArrayList<AnalysisEngineDescription> descList = new ArrayList<>(); descList.add(desc); CAS cas = CasCreationUtils.createCas(descList, UIMAFramework .getDefaultPerformanceTuningProperties(), resMgr); // check that imports were resolved correctly assertNotNull(cas.getTypeSystem().getType("DocumentStructure")); assertNotNull(cas.getTypeSystem().getType("NamedEntity")); assertNotNull(cas.getTypeSystem().getType("TestType3")); assertNotNull(cas.getIndexRepository().getIndex("TestIndex")); assertNotNull(cas.getIndexRepository().getIndex("ReverseAnnotationIndex")); assertNotNull(cas.getIndexRepository().getIndex("DocumentStructureIndex")); // check of type priority AnnotationFS fs1 = cas.createAnnotation(cas.getTypeSystem().getType("Paragraph"), 0, 1); AnnotationFS fs2 = cas.createAnnotation(cas.getTypeSystem().getType("Sentence"), 0, 1); assertTrue(cas.getAnnotationIndex().compare(fs1, fs2) < 0); } catch (Exception e) { JUnitExtension.handleException(e); } }
Example #14
Source File: CollectionReaderDescription_impl.java From uima-uimaj with Apache License 2.0 | 5 votes |
public void doFullValidation(ResourceManager aResourceManager) throws ResourceInitializationException { // check that user class was specified if (getImplementationName() == null || getImplementationName().length() == 0) { throw new ResourceInitializationException( ResourceInitializationException.MISSING_IMPLEMENTATION_CLASS_NAME, new Object[] { getSourceUrlString() }); } // try to load user class // use UIMA extension ClassLoader if available Class<?> implClass; try { implClass = Class_TCCL.forName(getImplementationName(), aResourceManager); } catch (ClassNotFoundException e) { throw new ResourceInitializationException(ResourceInitializationException.CLASS_NOT_FOUND, new Object[] { getImplementationName(), getSourceUrlString() }, e); } // verify the user class implements CollectionReader if (!CollectionReader.class.isAssignableFrom(implClass)) { throw new ResourceInitializationException( ResourceInitializationException.RESOURCE_DOES_NOT_IMPLEMENT_INTERFACE, new Object[] { getImplementationName(), CollectionReader.class.getName(), getSourceUrlString() }); } // try to create a CAS ArrayList<ProcessingResourceMetaData> metadata = new ArrayList<>(); metadata.add(getCollectionReaderMetaData()); CasCreationUtils.createCas(metadata, UIMAFramework.getDefaultPerformanceTuningProperties(), aResourceManager); }
Example #15
Source File: AnalysisEngineDescription_impl.java From uima-uimaj with Apache License 2.0 | 5 votes |
public void doFullValidation(ResourceManager aResourceManager) throws ResourceInitializationException { // attempt to instantiate AE in "verification mode" Map<String, Object> m = new HashMap<>(); m.put(AnalysisEngineImplBase.PARAM_VERIFICATION_MODE, Boolean.TRUE); AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(this, aResourceManager, m); validateSofaMappings(); ae.newCAS(); }
Example #16
Source File: CasCreationUtils.java From uima-uimaj with Apache License 2.0 | 5 votes |
/** * Creates a new CAS instance for a collection of CAS Processors, which. reuses an existing type * system. Using this method allows several CASes to all share the exact same type system object. * This method correctly handles aggregate as well as primitive analysis engines. * <p> * If you pass this method objects of type {@link AnalysisEngineDescription}, * {@link CollectionReaderDescription}, {@link CasInitializerDescription}, or * {@link CasConsumerDescription}, it will not instantiate the components. It will just extract * the type system information from the descriptor. For any other kind of * {@link ResourceSpecifier}, it will call * {@link UIMAFramework#produceResource(org.apache.uima.resource.ResourceSpecifier, Map)}. For * example, if a {@link URISpecifier} is passed, a remote connection will be established and the * service will be queries for its metadata. An exception will be thrown if the connection can not * be opened. * * @param aComponentDescriptionsOrMetaData * a collection of {@link ResourceSpecifier}, {@link ProcessingResourceMetaData}, * {@link TypeSystemDescription}, {@link FsIndexCollection}, or * {@link TypePriorities} objects. * @param aTypeSystem * type system to install in the CAS, null if none * @param aPerformanceTuningSettings * Properties object containing framework performance tuning settings using key * names defined on {@link UIMAFramework} interface * @param aResourceManager * the resource manager to use to resolve import declarations within the metadata, * and also to set the JCas ClassLoader for the new CAS * * @return a new CAS instance * * @throws ResourceInitializationException * if CAS creation fails */ public static CAS createCas(Collection<? extends MetaDataObject> aComponentDescriptionsOrMetaData, TypeSystem aTypeSystem, Properties aPerformanceTuningSettings, ResourceManager aResourceManager) throws ResourceInitializationException { // build a list of metadata objects List<ProcessingResourceMetaData> mdList = getMetaDataList(aComponentDescriptionsOrMetaData, aResourceManager); // extract TypeSystems, TypePriorities, and FsIndexes from metadata List<TypeSystemDescription> typeSystems = new ArrayList<>(); List<TypePriorities> typePriorities = new ArrayList<>(); List<FsIndexCollection> fsIndexes = new ArrayList<>(); Iterator<ProcessingResourceMetaData> it = mdList.iterator(); while (it.hasNext()) { ProcessingResourceMetaData md = it.next(); if (md.getTypeSystem() != null) typeSystems.add(md.getTypeSystem()); if (md.getTypePriorities() != null) typePriorities.add(md.getTypePriorities()); if (md.getFsIndexCollection() != null) fsIndexes.add(md.getFsIndexCollection()); } // merge TypePriorities and FsIndexes TypePriorities aggTypePriorities = mergeTypePriorities(typePriorities, aResourceManager); FsIndexCollection aggIndexColl = mergeFsIndexes(fsIndexes, aResourceManager); if (aTypeSystem != null) // existing type system object was specified; use that { return doCreateCas(aTypeSystem, null, aggTypePriorities, aggIndexColl.getFsIndexes(), aPerformanceTuningSettings, aResourceManager); } else { // no type system object specified; merge type system descriptions in metadata TypeSystemDescription aggTypeDesc = mergeTypeSystems(typeSystems); return doCreateCas(null, aggTypeDesc, aggTypePriorities, aggIndexColl.getFsIndexes(), aPerformanceTuningSettings, aResourceManager); } }
Example #17
Source File: RootUimaContext_impl.java From uima-uimaj with Apache License 2.0 | 5 votes |
@Override public void initializeRoot(Logger aLogger, ResourceManager aResourceManager, ConfigurationManager aConfigurationManager) { mLogger = aLogger; // mResourceManager = aResourceManager; // mConfigurationManager = aConfigurationManager; mSession = new Session_impl(); }
Example #18
Source File: PipelineBuilder.java From baleen with Apache License 2.0 | 5 votes |
/** Create a new analysis engine */ private AnalysisEngine createEngine( Class<? extends AnalysisComponent> componentClass, ResourceManager resourceManager, Object... configurationData) throws ResourceInitializationException { return UIMAFramework.produceAnalysisEngine( AnalysisEngineFactory.createEngineDescription(componentClass, configurationData), resourceManager, null); }
Example #19
Source File: ResourceManager_impl.java From uima-uimaj with Apache License 2.0 | 5 votes |
public static Class<?> loadUserClassOrThrow(String name, ResourceManager rm, ResourceSpecifier aSpecifier) throws ResourceInitializationException { try { return Class_TCCL.forName(name, rm, true); } catch (ClassNotFoundException e) { throw new ResourceInitializationException( ResourceInitializationException.CLASS_NOT_FOUND, new Object[] { name, aSpecifier.getSourceUrlString() }, e); } }
Example #20
Source File: JCasIterableTest.java From uima-uimafit with Apache License 2.0 | 5 votes |
@Test public void thatSharedResourceManagerIsNotDestroyed() throws Exception { ResourceManager resMgr = spy(newResourceManager()); consume(new JCasIterable(resMgr, createReaderDescription(ThreeDocsReader.class), createEngineDescription(GetTextAE.class))); verify(resMgr, never()).destroy(); }
Example #21
Source File: JCasIterableTest.java From uima-uimafit with Apache License 2.0 | 5 votes |
/** * Mind that returning a singleton resource manager from {@link ResourceManagerFactory} is * generally a bad idea exactly because it gets destroyed on a regular basis. For this * reason, it is called {@link ResourceManagerFactory#newResourceManager()} and not * {@code getResourceManager()}. */ @Test public void thatInternallyCreatedResourceManagerIsDestroyed() throws Exception { ResourceManager resMgr = spy(newResourceManager()); setResourceManagerCreator(() -> resMgr); consume(new JCasIterable( createReaderDescription(ThreeDocsReader.class), createEngineDescription(GetTextAE.class))); verify(resMgr, times(1)).destroy(); }
Example #22
Source File: AbstractSection.java From uima-uimaj with Apache License 2.0 | 5 votes |
/** * Creates the by name import. * * @param fileName the file name * @return the import */ public Import createByNameImport(String fileName) { if (fileName.endsWith(".xml")) fileName = fileName.substring(0, fileName.length() - 4); fileName = fileName.replace('\\', '/'); fileName = fileName.replace('/', '.'); int i = fileName.indexOf(":"); if (i >= 0) fileName = fileName.substring(i + 1); if (fileName.charAt(0) == '.') fileName = fileName.substring(1); int partStart = 0; Import imp = UIMAFramework.getResourceSpecifierFactory().createImport(); ResourceManager rm = editor.createResourceManager(); for (;;) { imp.setName(fileName.substring(partStart)); try { imp.findAbsoluteUrl(rm); } catch (InvalidXMLException e) { partStart = fileName.indexOf('.', partStart) + 1; if (0 == partStart) return imp; // not found -outer code will catch error later continue; } return imp; } }
Example #23
Source File: MultiPageEditor.java From uima-uimaj with Apache License 2.0 | 5 votes |
/** * Creates the cas. * * @param aAeDescription the a ae description * @param aPerformanceTuningSettings the a performance tuning settings * @param aResourceManager the a resource manager * @return the cas * @throws ResourceInitializationException the resource initialization exception */ public CAS createCas(AnalysisEngineDescription aAeDescription, Properties aPerformanceTuningSettings, ResourceManager aResourceManager) throws ResourceInitializationException { getMergeInput(aAeDescription, aResourceManager); // merge TypeSystemDescription aggTypeDesc = CasCreationUtils.mergeTypeSystems(typeSystemsToMerge, aResourceManager); TypePriorities aggTypePriorities = CasCreationUtils.mergeTypePriorities(typePrioritiesToMerge, aResourceManager); FsIndexCollection aggIndexColl = CasCreationUtils.mergeFsIndexes(fsIndexesToMerge, aResourceManager); return CasCreationUtils.createCas(aggTypeDesc, aggTypePriorities, aggIndexColl.getFsIndexes(), aPerformanceTuningSettings, aResourceManager); }
Example #24
Source File: MultiPageEditor.java From uima-uimaj with Apache License 2.0 | 5 votes |
/** * Gets the merge input. * * @param aAggregateDescription the a aggregate description * @param aResourceManager the a resource manager * @return the merge input * @throws ResourceInitializationException the resource initialization exception */ private void getMergeInput ( AnalysisEngineDescription aAggregateDescription, ResourceManager aResourceManager) throws ResourceInitializationException { // expand the aggregate AE description into the individual delegates ArrayList l = new ArrayList(); l.add(aAggregateDescription); List mdList = CasCreationUtils.getMetaDataList(l, aResourceManager, failedRemotes); maybeShowRemoteFailure(); // extract type systems and merge typeSystemsToMerge = new ArrayList(); typePrioritiesToMerge = new ArrayList(); fsIndexesToMerge = new ArrayList(); Iterator it = mdList.iterator(); while (it.hasNext()) { ProcessingResourceMetaData md = (ProcessingResourceMetaData) it.next(); if (md.getTypeSystem() != null) typeSystemsToMerge.add(md.getTypeSystem()); if (md.getTypePriorities() != null) typePrioritiesToMerge.add(md.getTypePriorities()); if (md.getFsIndexCollection() != null) fsIndexesToMerge.add(md.getFsIndexCollection()); } }
Example #25
Source File: CollectionProcessingEngine_impl.java From uima-uimaj with Apache License 2.0 | 5 votes |
public void initialize(CpeDescription aCpeDescription, Map aAdditionalParams) throws ResourceInitializationException { if (mCPM != null) // repeat initialization - not allowed { throw new UIMA_IllegalStateException(UIMA_IllegalStateException.RESOURCE_ALREADY_INITIALIZED, new Object[] { getClass().getName() }); } // get the ResourceManager (if any) supplied in the aAdditionalParams map ResourceManager resMgr = aAdditionalParams == null ? null : (ResourceManager) aAdditionalParams .get(Resource.PARAM_RESOURCE_MANAGER); // get performance tuning settings (if any) supplied in the aAdditionalParams map Properties perfSettings = aAdditionalParams == null ? null : (Properties) aAdditionalParams .get(Resource.PARAM_PERFORMANCE_TUNING_SETTINGS); // get ProcessControllerAdapter responsible for launching fenced services ProcessControllerAdapter pca = aAdditionalParams == null ? null : (ProcessControllerAdapter) aAdditionalParams.get("ProcessControllerAdapter"); // instantiate CPM from Descriptor try { mCPM = new BaseCPMImpl(aCpeDescription, resMgr, false, perfSettings); if (perfSettings != null) { mCPM.setPerformanceTuningSettings(perfSettings); } if (pca != null) { mCPM.setProcessControllerAdapter(pca); } } catch (Exception e) { throw new ResourceInitializationException(e); } }
Example #26
Source File: BaseCPMImpl.java From uima-uimaj with Apache License 2.0 | 5 votes |
/** * Parses CPE descriptor. * * @param mode - * indicates if the CPM should use a static descriptor or one provided * @param aDescriptor - * provided descriptor path * @param aResourceManager ResourceManager to be used by CPM * @throws Exception - */ public BaseCPMImpl(Boolean mode, String aDescriptor, ResourceManager aResourceManager) throws Exception { cpmThreadGroup = new CPMThreadGroup("CPM Thread Group"); cpeFactory = new CPEFactory(aResourceManager); if (mode == null) { defaultProcessTrace = true; cpeFactory.parse(); } else { defaultProcessTrace = mode; cpeFactory.parse(aDescriptor); } init(mode == null, UIMAFramework.getDefaultPerformanceTuningProperties()); }
Example #27
Source File: Class_TCCL.java From uima-uimaj with Apache License 2.0 | 5 votes |
static public <T> Class<T> forName(String className, Map<String, Object> additionalParams) throws ClassNotFoundException { ResourceManager rm = (additionalParams != null) ? (ResourceManager) additionalParams.get(Resource.PARAM_RESOURCE_MANAGER) : null; return forName(className, rm); }
Example #28
Source File: ResourceManagerConfiguration_impl.java From uima-uimaj with Apache License 2.0 | 4 votes |
public synchronized void resolveImports(Collection<String> aAlreadyImportedURLs, ResourceManager aResourceManager) throws InvalidXMLException { List<ExternalResourceDescription> importedResources = null; List<ExternalResourceBinding> importedBindings = null; if (getImports().length != 0) { // add our own URL, if known, to the collection of already imported URLs if (getSourceUrl() != null) { aAlreadyImportedURLs.add(getSourceUrl().toString()); } importedResources = new ArrayList<>(); importedBindings = new ArrayList<>(); Import[] imports = getImports(); for (int i = 0; i < imports.length; i++) { // make sure Import's relative path base is set, to allow for users who create // new import objects if (imports[i] instanceof Import_impl) { ((Import_impl) imports[i]).setSourceUrlIfNull(this.getSourceUrl()); } URL url = imports[i].findAbsoluteUrl(aResourceManager); if (!aAlreadyImportedURLs.contains(url.toString())) { aAlreadyImportedURLs.add(url.toString()); try { resolveImport(url, aAlreadyImportedURLs, importedResources, importedBindings, aResourceManager); } catch (IOException e) { throw new InvalidXMLException(InvalidXMLException.IMPORT_FAILED_COULD_NOT_READ_FROM_URL, new Object[] { url, imports[i].getSourceUrlString() }, e); } } } } // update this object ExternalResourceDescription[] existingResources = this.getExternalResources(); if (existingResources == null) { this.setExternalResources(existingResources = ExternalResourceDescription.EMPTY_EXTERNAL_RESORUCE_DESCRIPTIONS); } if (importedResources != null) { ExternalResourceDescription[] newResources = new ExternalResourceDescription[existingResources.length + importedResources.size()]; System.arraycopy(existingResources, 0, newResources, 0, existingResources.length); for (int i = 0; i < importedResources.size(); i++) { newResources[existingResources.length + i] = importedResources .get(i); } this.setExternalResources(newResources); } ExternalResourceBinding[] existingBindings = this.getExternalResourceBindings(); if (existingBindings == null) { this.setExternalResourceBindings(existingBindings = ExternalResourceBinding.EMPTY_RESOURCE_BINDINGS); } if (null != importedBindings) { ExternalResourceBinding[] newBindings = new ExternalResourceBinding[existingBindings.length + importedBindings.size()]; System.arraycopy(existingBindings, 0, newBindings, 0, existingBindings.length); for (int i = 0; i < importedBindings.size(); i++) { newBindings[existingBindings.length + i] = importedBindings.get(i); } this.setExternalResourceBindings(newBindings); } // clear imports this.setImports(Import.EMPTY_IMPORTS); }
Example #29
Source File: ResourceMetaData_impl.java From uima-uimaj with Apache License 2.0 | 4 votes |
/** * @see ResourceMetaData#resolveImports(ResourceManager) */ public void resolveImports(ResourceManager aResourceManager) throws InvalidXMLException { // does nothing by default; may be overriden in subclasses }
Example #30
Source File: MultiprocessingAnalysisEngine_impl.java From uima-uimaj with Apache License 2.0 | 4 votes |
/** * @see org.apache.uima.resource.Resource#initialize(org.apache.uima.resource.ResourceSpecifier, * java.util.Map) */ public boolean initialize(ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams) throws ResourceInitializationException { // Read parameters from the aAdditionalParams map. // (First copy it so we can modify it and send the parameters on to // each Analysis Engine in the pool.) if (aAdditionalParams == null) { aAdditionalParams = new HashMap<>(); } else { aAdditionalParams = new HashMap<>(aAdditionalParams); } // get or create ResourceManager // This ResourceManager is shared among all the AEs in the pool, and also used by // this MultiprocessingAE instance // https://issues.apache.org/jira/browse/UIMA-2078 ResourceManager resMgr = (ResourceManager) aAdditionalParams.get(Resource.PARAM_RESOURCE_MANAGER); if (resMgr == null) { resMgr = UIMAFramework.newDefaultResourceManager(); aAdditionalParams.put(Resource.PARAM_RESOURCE_MANAGER, resMgr); } // Share the configMgr so that (re)configure actions affect all instances ConfigurationManager configMgr = (ConfigurationManager) aAdditionalParams.get(Resource.PARAM_CONFIG_MANAGER); if (configMgr == null) { configMgr = UIMAFramework.newConfigurationManager(); aAdditionalParams.put(Resource.PARAM_CONFIG_MANAGER, configMgr); } super.initialize(aSpecifier, aAdditionalParams); // determine size of Analysis Engine pool and timeout period Integer poolSizeInteger = (Integer) aAdditionalParams.get(PARAM_NUM_SIMULTANEOUS_REQUESTS); int poolSize = (poolSizeInteger != null) ? poolSizeInteger : DEFAULT_NUM_SIMULTANEOUS_REQUESTS; Integer timeoutInteger = (Integer) aAdditionalParams.get(PARAM_TIMEOUT_PERIOD); mTimeout = (timeoutInteger != null) ? timeoutInteger : DEFAULT_TIMEOUT_PERIOD; // Share resource manager, but don't share uima-context // // add UimaContext to params map so that all AEs in pool will share it // aAdditionalParams.put(PARAM_UIMA_CONTEXT, getUimaContextAdmin()); // create pool (REMOVE pool size parameter from map so we don't try to // fill pool with other MultiprocessingAnalysisEngines!) aAdditionalParams.remove(PARAM_NUM_SIMULTANEOUS_REQUESTS); mPool = new AnalysisEnginePool("", poolSize, aSpecifier, aAdditionalParams); // update metadata from pool (this gets the merged type system for aggregates) this.setMetaData(mPool.getMetaData()); return true; }