Java Code Examples for org.apache.uima.resource.ResourceCreationSpecifier#getFrameworkImplementation()
The following examples show how to use
org.apache.uima.resource.ResourceCreationSpecifier#getFrameworkImplementation() .
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: AnalysisEngineFactory_impl.java From uima-uimaj with Apache License 2.0 | 4 votes |
/** * @see org.apache.uima.ResourceFactory#produceResource(java.lang.Class, * org.apache.uima.resource.ResourceSpecifier, java.util.Map) */ public Resource produceResource(Class<? extends Resource> aResourceClass, ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams) throws ResourceInitializationException { // It is important to know whether we need a Multiprocessing-capable // Analysis Engine implementation - this is determined by whether there // is a value for the PARAM_NUM_SIMULTANEOUS_REQUESTS parameter. boolean multiprocessing = (aAdditionalParams != null) && aAdditionalParams.containsKey(AnalysisEngine.PARAM_NUM_SIMULTANEOUS_REQUESTS); Resource resource = null; if (aSpecifier instanceof ResourceCreationSpecifier && aResourceClass.isAssignableFrom(TextAnalysisEngine.class)) // NOTE: for backwards-compatibility, we have to check TextAnalysisEngine, // not AnalysisEngine. Otherwise produceTAE would fail becasue // TextAnalysisEngien.class.isAssignableFrom(AnalysisEngine.class) is false. { ResourceCreationSpecifier spec = (ResourceCreationSpecifier) aSpecifier; if (multiprocessing) { resource = new MultiprocessingAnalysisEngine_impl(); } else { String frameworkImpl = spec.getFrameworkImplementation(); if (frameworkImpl == null || frameworkImpl.length() == 0) { throw new ResourceInitializationException( ResourceInitializationException.MISSING_FRAMEWORK_IMPLEMENTATION, new Object[] { aSpecifier.getSourceUrlString() }); } if (frameworkImpl.startsWith(Constants.CPP_FRAMEWORK_NAME)) { resource = new UimacppAnalysisEngineImpl(); } else if (frameworkImpl.startsWith(Constants.JAVA_FRAMEWORK_NAME)) { if (spec instanceof AnalysisEngineDescription && !((AnalysisEngineDescription) spec).isPrimitive()) { resource = new AggregateAnalysisEngine_impl(); } else { resource = new PrimitiveAnalysisEngine_impl(); } } else { throw new ResourceInitializationException( ResourceInitializationException.UNSUPPORTED_FRAMEWORK_IMPLEMENTATION, new Object[] { spec.getFrameworkImplementation(), aSpecifier.getSourceUrlString() }); } } } if (resource != null && resource.initialize(aSpecifier, aAdditionalParams)) { return resource; } else { return null; } }
Example 2
Source File: FlowControllerContainer.java From uima-uimaj with Apache License 2.0 | 4 votes |
public boolean initialize(ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams) throws ResourceInitializationException { UimaContext prevContext = setContextHolder(); // Get this early so the restore in correct try { // specifier must be a FlowControllerDescription. (Eventually, we // might support remote specifiers, but not yet) if (!(aSpecifier instanceof FlowControllerDescription)) { throw new ResourceInitializationException( ResourceInitializationException.NOT_A_FLOW_CONTROLLER_DESCRIPTOR, new Object[] { aSpecifier.getSourceUrlString(), aSpecifier.getClass().getName() }); } ResourceCreationSpecifier desc = (ResourceCreationSpecifier) aSpecifier; // also framework implementation must start with org.apache.uima.java final String fwImpl = desc.getFrameworkImplementation(); if (fwImpl == null || !fwImpl.equalsIgnoreCase(Constants.JAVA_FRAMEWORK_NAME)) { throw new ResourceInitializationException( ResourceInitializationException.UNSUPPORTED_FRAMEWORK_IMPLEMENTATION, new Object[] { fwImpl, aSpecifier.getSourceUrlString() }); } super.initialize(aSpecifier, aAdditionalParams); // validate the descriptor desc.validate(getResourceManager()); // instantiate FlowController mFlowController = instantiateFlowController(desc); // record metadata setMetaData(desc.getMetaData()); // add our metadata to the CasManager, so that it will pick up our // type system, priorities, and indexes getCasManager().addMetaData(getProcessingResourceMetaData()); // determine if this component is Sofa-aware (based on whether it // declares any input or output sofas in its capabilities) mSofaAware = getProcessingResourceMetaData().isSofaAware(); // Set Logger, to enable component-specific logging configuration UimaContextAdmin uimaContext = getUimaContextAdmin(); Logger logger = UIMAFramework.getLogger(mFlowController.getClass()); logger.setResourceManager(this.getResourceManager()); uimaContext.setLogger(logger); Logger classLogger = getLogger(); classLogger.logrb(Level.CONFIG, this.getClass().getName(), "initialize", LOG_RESOURCE_BUNDLE, "UIMA_flow_controller_init_begin__CONFIG", getMetaData().getName()); // initialize FlowController mFlowController.initialize(getFlowControllerContext()); mMBeanServer = null; String mbeanNamePrefix = null; if (aAdditionalParams != null) { mMBeanServer = aAdditionalParams.get(AnalysisEngine.PARAM_MBEAN_SERVER); mbeanNamePrefix = (String)aAdditionalParams.get(AnalysisEngine.PARAM_MBEAN_NAME_PREFIX); } // update MBean with the name taken from metadata getMBean().setName(getMetaData().getName(), getUimaContextAdmin(), mbeanNamePrefix); // register MBean with MBeanServer. If no MBeanServer specified in the // additionalParams map, this will use the platform MBean Server // (Java 1.5 only) JmxMBeanAgent.registerMBean(getMBean(), mMBeanServer); classLogger.logrb(Level.CONFIG, this.getClass().getName(), "initialize", LOG_RESOURCE_BUNDLE, "UIMA_flow_controller_init_successful__CONFIG", getMetaData().getName()); initialized = true; return true; } catch (ResourceConfigurationException e) { throw new ResourceInitializationException(e); } finally { UimaContextHolder.setContext(prevContext); } }
Example 3
Source File: UimacppAnalysisEngineImpl.java From uima-uimaj with Apache License 2.0 | 4 votes |
/** * @throws ResourceInitializationException or * wraps invalid xml exception when processing imports * @see org.apache.uima.resource.Resource#initialize(ResourceSpecifier, Map) */ public boolean initialize(ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams) throws ResourceInitializationException { // AnalysisEngine can be build from any ResourceCreationSpecifier- // CasConsumer descriptors as well as AnalysisEngine descriptors. if (!(aSpecifier instanceof ResourceCreationSpecifier)) { return false; } // aSpecifier must be a AnalysisEngineDescription or a CasConsumerDescription if (!(aSpecifier instanceof AnalysisEngineDescription) && !(aSpecifier instanceof CasConsumerDescription) ) { return false; } mDescription = (ResourceCreationSpecifier) aSpecifier; // also framework implementation must start with org.apache.uima.cpp final String fwImpl = mDescription.getFrameworkImplementation(); if (!fwImpl.startsWith(Constants.CPP_FRAMEWORK_NAME)) { return false; } // Aggregate TAF AEs mostly act like primitives (because the flow // control is all handled // in TAF). But, we do need to make sure that this AE's type system, // type priorities, // and fs indexes are formed by merging everything declared in the // individual // components' descriptors if (mDescription instanceof AnalysisEngineDescription && (! ((AnalysisEngineDescription)mDescription).isPrimitive())) { // resolve deep type system imports try { mDescription.validate(getResourceManager()); } catch (ResourceConfigurationException e) { throw new ResourceInitializationException(e); } mergeDelegateAnalysisEngineMetaData(); } ProcessingResourceMetaData md = (ProcessingResourceMetaData) mDescription.getMetaData(); // resolve imports for primitives if (mDescription instanceof AnalysisEngineDescription && ((AnalysisEngineDescription)mDescription).isPrimitive()) { try { md.resolveImports(); } catch (InvalidXMLException e1) { throw new ResourceInitializationException(e1); } } super.initialize(aSpecifier, aAdditionalParams); getLogger().logrb(Level.CONFIG, CLASS_NAME.getName(), "initialize", LOG_RESOURCE_BUNDLE, "UIMA_analysis_engine_init_begin__CONFIG", md.getName()); // Normalize language codes. Need to do this since a wide variety of // spellings are acceptable according to ISO. normalizeIsoLangCodes(md); // clone this metadata and assign a UUID if not already present AnalysisEngineMetaData mdCopy = (AnalysisEngineMetaData) md.clone(); if (mdCopy.getUUID() == null) { mdCopy.setUUID(UUIDGenerator.generate()); } setMetaData(mdCopy); // Read parameters from the aAdditionalParams map. if (aAdditionalParams == null) { aAdditionalParams = Collections.emptyMap(); } // determine if verification mode is on mVerificationMode = aAdditionalParams.containsKey(PARAM_VERIFICATION_MODE); // determine if this component is Sofa-aware (based on whether it // declares any input or output sofas in its capabilities) mSofaAware = getAnalysisEngineMetaData().isSofaAware(); initializeAnalysisComponent(); resetResultSpecificationToDefault(); getLogger().logrb(Level.CONFIG, CLASS_NAME.getName(), "initialize", LOG_RESOURCE_BUNDLE, "UIMA_analysis_engine_init_successful__CONFIG", md.getName()); return true; }
Example 4
Source File: PrimitiveAnalysisEngine_impl.java From uima-uimaj with Apache License 2.0 | 4 votes |
/** * @see org.apache.uima.resource.Resource#initialize(ResourceSpecifier, Map) */ public boolean initialize(ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams) throws ResourceInitializationException { try { // Primitive AnalysisEngine can be build from any ResourceCreationSpecifier- // this includes CollectionReader, and CasConsumer descriptors // as well as AnalysisEngine descriptors. if (!(aSpecifier instanceof ResourceCreationSpecifier)) { return false; } // BUT, for AnalysisEngineDescriptions, must not be an aggregate if (aSpecifier instanceof AnalysisEngineDescription && !((AnalysisEngineDescription) aSpecifier).isPrimitive()) { return false; } mDescription = (ResourceCreationSpecifier) aSpecifier; // also framework implementation must start with org.apache.uima.java final String fwImpl = mDescription.getFrameworkImplementation(); if (!fwImpl.startsWith(Constants.JAVA_FRAMEWORK_NAME)) { return false; } super.initialize(aSpecifier, aAdditionalParams); ProcessingResourceMetaData md = (ProcessingResourceMetaData) mDescription.getMetaData(); if (null == md) { md = UIMAFramework.getResourceSpecifierFactory().createProcessingResourceMetaData(); md.setName("(null)"); } // Get logger for this class Logger logger = getLogger(); logger.logrb(Level.CONFIG, CLASS_NAME.getName(), "initialize", LOG_RESOURCE_BUNDLE, "UIMA_analysis_engine_init_begin__CONFIG", md.getName()); // Normalize language codes. Need to do this since a wide variety of // spellings are acceptable according to ISO. normalizeIsoLangCodes(md); // clone this metadata and assign a UUID if not already present ResourceMetaData mdCopy = (ResourceMetaData) md.clone(); if (mdCopy.getUUID() == null) { mdCopy.setUUID(UUIDGenerator.generate()); } setMetaData(mdCopy); // validate the AnalysisEngineDescription and throw a // ResourceInitializationException if there is a problem mDescription.validate(getResourceManager()); // Read parameters from the aAdditionalParams map. if (aAdditionalParams == null) { aAdditionalParams = Collections.emptyMap(); } // determine if verification mode is on mVerificationMode = aAdditionalParams.containsKey(PARAM_VERIFICATION_MODE); // determine if this component is Sofa-aware (based on whether it // declares any input or output sofas in its capabilities) mSofaAware = getAnalysisEngineMetaData().isSofaAware(); initializeAnalysisComponent(aAdditionalParams); // Initialize ResultSpec based on output capabilities // TODO: should only do this for outermost AE resetResultSpecificationToDefault(); logger.logrb(Level.CONFIG, CLASS_NAME.getName(), "initialize", LOG_RESOURCE_BUNDLE, "UIMA_analysis_engine_init_successful__CONFIG", md.getName()); return true; } catch (ResourceConfigurationException e) { throw new ResourceInitializationException( ResourceInitializationException.ERROR_INITIALIZING_FROM_DESCRIPTOR, new Object[] { getMetaData().getName(), aSpecifier.getSourceUrlString() }); } }