org.apache.uima.resource.metadata.ResourceMetaData Java Examples

The following examples show how to use org.apache.uima.resource.metadata.ResourceMetaData. 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: InitializerEngine.java    From biomedicus with Apache License 2.0 6 votes vote down vote up
@Override
public boolean initialize(ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams)
    throws ResourceInitializationException {
  if (!(aSpecifier instanceof ResourceCreationSpecifier)) {
    throw new ResourceInitializationException();
  }

  ResourceMetaData metaData = ((ResourceCreationSpecifier) aSpecifier).getMetaData();

  if (!(metaData instanceof AnalysisEngineMetaData)) {
    throw new ResourceInitializationException();
  }

  AnalysisEngineMetaData aeMetaData = (AnalysisEngineMetaData) metaData;

  TypeSystemDescription typeSystem = aeMetaData.getTypeSystem();

  return super.initialize(aSpecifier, aAdditionalParams);
}
 
Example #2
Source File: AnalysisEngineImplBase.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
@Override
//*****************************************************************************************
// NOTICE: This method is logically not needed it would seem, because the superclass of the superclass of this 
// implements it.
// However, there is an obscure issue here involving the precise definition of "protected". 
// If it is not included in this class and this class is not in the same package as the class needing
// this, then a class (e.g. PearAnalysisEngineWrapper) which does 
//        ((AnalysisEngineImplBase)ae).setMetaData(...) fails with a compile error saying that
// the method setMetaData in the Resource_ImplBase is not visible (even though it is "protected")
// This makes that problem go away.
// Details of this issue are explained in section 6.6.2.1, Access to a protected member,
//   in The Java Language Specification (pg 139).
//   
//*****************************************************************************************

protected void setMetaData(ResourceMetaData aMetaData) {
  super.setMetaData(aMetaData);
}
 
Example #3
Source File: ResourceServiceAdapter_implTest.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
public void testGetMetaData() throws Exception {
  try {
    ResourceMetaData md = new ResourceMetaData_impl();
    md.setName("Test");
    md.setDescription("This is a test");
    ConfigurationParameter p1 = new ConfigurationParameter_impl();
    p1.setName("IntegerArrayParam");
    p1.setDescription("multi-valued parameter with Integer data type");
    p1.setType(ConfigurationParameter.TYPE_INTEGER);
    p1.setMultiValued(true);
    md.getConfigurationParameterDeclarations().setConfigurationParameters(
            new ConfigurationParameter[] { p1 });

    mServiceStub.getMetaDataReturnValue = md;
    ResourceMetaData result = mAdapter.getMetaData();
    Assert.assertEquals("callGetMetaData", mServiceStub.lastMethodName);
    Assert.assertEquals(md, result);
  } catch (Exception e) {
    JUnitExtension.handleException(e);
  }
}
 
Example #4
Source File: CPMEngine.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Parses Cas Processor descriptor and checks if it is parallelizable.
 * 
 * @param aDescPath -
 *          fully qualified path to a CP descriptor
 * @param aCpName -
 *          name of the CP
 * @param isConsumer -
 *          true if the CP is a Cas Consumer, false otherwise
 * @return - true if CP is parallelizable, false otherwise
 * 
 * @throws Exception -
 */
private boolean isMultipleDeploymentAllowed(String aDescPath, String aCpName, boolean isConsumer)
        throws Exception {
  OperationalProperties op = null;
  // Parse the descriptor to access Operational Properties
  ResourceSpecifier resourceSpecifier = cpeFactory.getSpecifier(new File(aDescPath).toURL());
  if (resourceSpecifier != null && resourceSpecifier instanceof ResourceCreationSpecifier) {
    ResourceMetaData md = ((ResourceCreationSpecifier) resourceSpecifier).getMetaData();
    if (md instanceof ProcessingResourceMetaData) {
      op = ((ProcessingResourceMetaData) md).getOperationalProperties();
      if (op == null) {
        // Operational Properties not defined, so use defaults
        if (isConsumer) {
          return false; // the default for CasConsumer
        }
        return true; // default for AEs
      }
      return op.isMultipleDeploymentAllowed();
    }
  }
  throw new ResourceConfigurationException(ResourceInitializationException.NOT_A_CAS_PROCESSOR,
          new Object[] { aCpName, "<unknown>", aDescPath });

}
 
Example #5
Source File: MultiPageEditor.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Convert to ae meta data.
 *
 * @param r the r
 * @return the analysis engine meta data
 */
private AnalysisEngineMetaData convertToAeMetaData(ResourceMetaData r) {
  ProcessingResourceMetaData p = (ProcessingResourceMetaData) r;
  AnalysisEngineMetaData d = UIMAFramework.getResourceSpecifierFactory()
          .createAnalysisEngineMetaData();
  d.setCapabilities(p.getCapabilities());
  d.setConfigurationParameterDeclarations(p.getConfigurationParameterDeclarations());
  d.setConfigurationParameterSettings(p.getConfigurationParameterSettings());
  d.setCopyright(p.getCopyright());
  d.setDescription(p.getDescription());
  d.setFsIndexCollection(p.getFsIndexCollection());
  d.setName(p.getName());
  d.setTypePriorities(p.getTypePriorities());
  d.setTypeSystem(p.getTypeSystem());
  d.setVendor(p.getVendor());
  d.setVersion(p.getVersion());
  d.setOperationalProperties(p.getOperationalProperties());
  ((AnalysisEngineMetaData_impl)d).setInfoset(((MetaDataObject_impl)r).getInfoset());
  return d;
}
 
Example #6
Source File: AbstractSection.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Get the metadata for a local or remote descriptor. If the descriptor is remote, but cannot be
 * currently connected to, return null. Note that this make take some time to determine.
 * 
 * @param o
 *          is the AnalysisEngineDescription or the URISpecifier for remotes.
 * @return AnalysisEngineMetaData or null
 */
public ResourceMetaData getMetaDataFromDescription(ResourceSpecifier o) {
  if (o instanceof ResourceCreationSpecifier) {
    return ((ResourceCreationSpecifier) o).getMetaData();
  }
  if (o instanceof URISpecifier) {
    URISpecifier uriSpec = ((URISpecifier) o);
    AnalysisEngine ae = null;
    try {
      setVnsHostAndPort(o);
      ae = UIMAFramework.produceAnalysisEngine(uriSpec);
    } catch (ResourceInitializationException e) {
      return null;
    }
    AnalysisEngineMetaData aemd = ae.getAnalysisEngineMetaData();
    ae.destroy();
    return aemd;
  }
  
  throw new InternalErrorCDE("invalid call");
}
 
Example #7
Source File: ResourceCreationSpecifierFactory.java    From uima-uimafit with Apache License 2.0 6 votes vote down vote up
/**
 * This method sets the configuration parameters of a resource. The length of
 * configurationParameters and configurationValues should be equal
 * 
 * @param metaData
 *          The ResourceMetaData whose parameters are to be set.
 * @param configurationParameters
 *          an array of configuration parameters
 * @param configurationValues
 *          an array of configuration parameter values
 */
public static void setConfigurationParameters(ResourceMetaData metaData,
        ConfigurationParameter[] configurationParameters, Object[] configurationValues) {
  ConfigurationParameterDeclarations paramDecls = metaData
          .getConfigurationParameterDeclarations();
  ConfigurationParameterSettings paramSettings = metaData.getConfigurationParameterSettings();
  for (int i = 0; i < configurationParameters.length; i++) {
    ConfigurationParameter decl = paramDecls.getConfigurationParameter(null,
            configurationParameters[i].getName());
    if (paramDecls != null && decl == null) {
      paramDecls.addConfigurationParameter(configurationParameters[i]);
      decl = configurationParameters[i];
    }

    // Upgrade single-value to multi-value if necessary
    Object value = configurationValues[i];
    if ((value != null) && decl.isMultiValued() && !isMultiValue(value)) {
      value = Array.newInstance(value.getClass(), 1);
      Array.set(value, 0, configurationValues[i]);
    }

    paramSettings.setParameterValue(configurationParameters[i].getName(), value);
  }
}
 
Example #8
Source File: ResourceMetaDataFactory.java    From uima-uimafit with Apache License 2.0 6 votes vote down vote up
/**
 * Adds meta data from a {@link org.apache.uima.fit.descriptor.ResourceMetaData} annotation to the
 * given meta data object if such an annotation is present on the component class. If no
 * annotation is present, default values are be added.
 * 
 * @param aMetaData
 *          the meta data object to configure.
 * @param aComponentClass
 *          the class that may carry the {@link org.apache.uima.fit.descriptor.ResourceMetaData}
 *          annotation
 */
public static void configureResourceMetaData(ResourceMetaData aMetaData, Class<?> aComponentClass) {
  org.apache.uima.fit.descriptor.ResourceMetaData componentAnno = ReflectionUtil
          .getInheritableAnnotation(org.apache.uima.fit.descriptor.ResourceMetaData.class,
                  aComponentClass);

  if (componentAnno == null) {
    // Default handling if no annotation is present.
    aMetaData.setCopyright(getDefaultCopyright(aComponentClass));
    aMetaData.setDescription(getDefaultDescription(aComponentClass));
    aMetaData.setName(getDefaultName(aComponentClass));
    aMetaData.setVendor(getDefaultVendor(aComponentClass));
    aMetaData.setVersion(getDefaultVersion(aComponentClass));
  } else {
    // If annotation is present, use it
    // Annotation values cannot be null, but we want to avoid empty strings in the meta data,
    // thus we set to null when the value is empty.
    aMetaData.setCopyright(emptyAsNull(componentAnno.copyright()));
    aMetaData.setDescription(emptyAsNull(componentAnno.description()));
    aMetaData.setName(emptyAsNull(componentAnno.name()));
    aMetaData.setVendor(emptyAsNull(componentAnno.vendor()));
    aMetaData.setVersion(emptyAsNull(componentAnno.version()));
  }
}
 
Example #9
Source File: Pipeline.java    From bluima with Apache License 2.0 6 votes vote down vote up
private PipelineBuilder build(PipelineBuilder builder)
        throws InvalidXMLException, IOException, SAXException,
        CpeDescriptorException {

    Set<String> cpeNames = newHashSet();

    for (AnalysisEngineDescription aed : this.aeds) {

        // workaround to use multiple cpe with the same name
        String name = aed.getMetaData().getName();
        if (cpeNames.contains(name)) {
            ResourceMetaData metaData = aed.getMetaData();
            String newName = name + System.currentTimeMillis();
            metaData.setName(newName);
            aed.setMetaData(metaData);
            cpeNames.add(newName);
        } else {
            cpeNames.add(name);
        }
        builder.add(aed);
    }
    return builder;
}
 
Example #10
Source File: AggregateCollectionReader.java    From bluima with Apache License 2.0 6 votes vote down vote up
public AggregateCollectionReader(List<CollectionReader> readers,
    TypeSystemDescription tsd) {
try {
    CollectionReaderDescription crd = CollectionReaderFactory
	    .createReaderDescription(AggregateCollectionReader.class, tsd);
    ResourceMetaData metaData = crd.getMetaData();
    ConfigurationParameterSettings paramSettings = metaData
	    .getConfigurationParameterSettings();
    Map<String, Object> additionalParameters = new HashMap<String, Object>();
    additionalParameters
	    .put(CollectionReader.PARAM_CONFIG_PARAM_SETTINGS,
		    paramSettings);
    initialize(crd, additionalParameters);

    this.readers = readers;
    this.readerIterator = this.readers.iterator();
    currentReader = this.readerIterator.next();
} catch (ResourceInitializationException rie) {
    throw new RuntimeException(rie);
}
   }
 
Example #11
Source File: ResourceService_implTest.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
public void testGetMetaData() throws Exception {
  try {
    ResourceMetaData md = service.getMetaData();
    Assert.assertNotNull(md);
    Assert.assertEquals("Test Annotator", md.getName());
    Assert.assertNotNull(md.getUUID());
  } catch (Exception e) {
    JUnitExtension.handleException(e);
  }
}
 
Example #12
Source File: XMLParser_impl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Parses a ResourceMetaData object from an XML input stream. XML schema validation will be done
 * against the {@link #RESOURCE_SPECIFIER_SCHEMA_NAME} if it can be found in the classpath.
 * 
 * @param aInput
 *          the input source from which to read the XML document
 * 
 * @return a <code>ResourceMetaData</code> object constructed from the XML document
 * 
 * @throws InvalidXMLException
 *           if the input XML is not valid or does not specify a valid ResourceSpecifier
 */
public ResourceMetaData parseResourceMetaData(XMLInputSource aInput, ParsingOptions aOptions)
        throws InvalidXMLException {
  // attempt to locate resource specifier schema
  XMLizable object = parse(aInput, RESOURCE_SPECIFIER_NAMESPACE, SCHEMA_URL, aOptions);

  if (object instanceof ResourceMetaData) {
    return (ResourceMetaData) object;
  } else {
    throw new InvalidXMLException(InvalidXMLException.INVALID_CLASS, new Object[] {
        ResourceMetaData.class.getName(), object.getClass().getName() });
  }
}
 
Example #13
Source File: AnalysisEngineServiceAdapter.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * @see org.apache.uima.resource.Resource#getMetaData()
 */
public ResourceMetaData getMetaData() {
  try {
    if (mCachedMetaData == null && getStub() != null) {
      mCachedMetaData = getStub().callGetMetaData();
    }
    return mCachedMetaData;
  } catch (ResourceServiceException e) {
    throw new UIMARuntimeException(e);
  }
}
 
Example #14
Source File: ResourceServiceAdapter.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * @see org.apache.uima.resource.Resource#getMetaData()
 */
public ResourceMetaData getMetaData() {
  try {
    if (mCachedMetaData == null) {
      mCachedMetaData = getStub().callGetMetaData();
    }
    return mCachedMetaData;
  } catch (ResourceServiceException e) {
    throw new UIMARuntimeException(e);
  }
}
 
Example #15
Source File: ResourcePoolTest.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
public void testGetMetaData() throws Exception {
  try {
    ResourceMetaData descMetaData = mDesc.getMetaData();
    ResourceMetaData poolMetaData = pool1.getMetaData();
    // only UUID should be different
    descMetaData.setUUID(poolMetaData.getUUID());
    Assert.assertEquals(descMetaData, poolMetaData);
  } catch (Exception e) {
    JUnitExtension.handleException(e);
  }
}
 
Example #16
Source File: AbstractSection.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the description for descriptor.
 *
 * @param fileRef the file ref
 * @param rs the rs
 * @return the description for descriptor
 */
protected String getDescriptionForDescriptor(String fileRef, ResourceSpecifier rs) {
  if (null == fileRef || "".equals(fileRef) || null == rs)
    return "";
  String sDesc;
  long lCurrentTimeInMillis = System.currentTimeMillis();
  if (rs == lastResourceForDescription
          && ((lCurrentTimeInMillis - lastTimeDescriptionRequested) < TABLE_HOVER_REQUERY_TIME)) {
    return lastDescriptionFromDescriptor;
  } else {
    sDesc = fileRef + ":\n";
    if (rs instanceof PearSpecifier) {
      sDesc += " (Pear descriptor)";
    } else {
      ResourceMetaData resourceMetaData = getMetaDataFromDescription(rs);
      if (null == resourceMetaData) {
        sDesc += "(Remote service is not responding)";
      } else {
        String description = resourceMetaData.getDescription();
        if (null != description && !description.equals("")) {
          sDesc += parseToFitInToolTips(description);
        } else
          sDesc += "(No Description)";
      }
    }
    lastResourceForDescription = rs;
    lastTimeDescriptionRequested = System.currentTimeMillis();
    lastDescriptionFromDescriptor = sDesc;
  }
  return sDesc;
}
 
Example #17
Source File: ConfigurableDataResource_implTest.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
public void testInitialize() throws Exception {
  try {
    // create a ConfigurableDataResourceSpecifier
    ConfigurableDataResourceSpecifier_impl cspec = new ConfigurableDataResourceSpecifier_impl();
    cspec.setUrl("jdbc:db2:MyDatabase");
    ResourceMetaData md = new ResourceMetaData_impl();
    cspec.setMetaData(md);
    md.setName("foo");
    ConfigurationParameterDeclarations decls = new ConfigurationParameterDeclarations_impl();
    ConfigurationParameter param = new ConfigurationParameter_impl();
    param.setName("param");
    param.setType("String");
    decls.addConfigurationParameter(param);
    md.setConfigurationParameterDeclarations(decls);

    // initialize a DataResource
    ConfigurableDataResource_impl cdr = new ConfigurableDataResource_impl();
    cdr.initialize(cspec, Collections.EMPTY_MAP);
    assertEquals(new URI("jdbc:db2:MyDatabase"), cdr.getUri());
    assertEquals("foo", cdr.getMetaData().getName());
    ConfigurationParameter param0 = cdr.getMetaData().getConfigurationParameterDeclarations()
            .getConfigurationParameters()[0];
    assertEquals("param", param0.getName());
    assertEquals("String", param0.getType());

  } catch (Exception e) {
    JUnitExtension.handleException(e);
  }
}
 
Example #18
Source File: ConfigurableDataResourceSpecifier_implTest.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
public void testXmlization() throws Exception {
  try {
    // create a ConfigurableDataResourceSpecifier
    ConfigurableDataResourceSpecifier_impl cspec = new ConfigurableDataResourceSpecifier_impl();
    cspec.setUrl("jdbc:db2:MyDatabase");
    ResourceMetaData md = new ResourceMetaData_impl();
    cspec.setMetaData(md);
    md.setName("foo");
    ConfigurationParameterDeclarations decls = new ConfigurationParameterDeclarations_impl();
    ConfigurationParameter param = new ConfigurationParameter_impl();
    param.setName("param");
    param.setType("String");
    decls.addConfigurationParameter(param);
    md.setConfigurationParameterDeclarations(decls);
    ConfigurationParameterSettings settings = new ConfigurationParameterSettings_impl();
    NameValuePair nvp = new NameValuePair_impl();
    nvp.setName("param");
    nvp.setValue("bar");
    settings.setParameterSettings(new NameValuePair[] { nvp });
    md.setConfigurationParameterSettings(settings);

    // wrtie to XML
    StringWriter sw = new StringWriter();
    cspec.toXML(sw);
    String xmlStr = sw.getBuffer().toString();

    // parse back
    ByteArrayInputStream inStream = new ByteArrayInputStream(xmlStr.getBytes(StandardCharsets.UTF_8));
    XMLInputSource in = new XMLInputSource(inStream, null);
    ConfigurableDataResourceSpecifier_impl parsedSpec = (ConfigurableDataResourceSpecifier_impl) UIMAFramework
            .getXMLParser().parse(in);

    assertEquals(cspec, parsedSpec);

  } catch (Exception e) {
    JUnitExtension.handleException(e);
  }
}
 
Example #19
Source File: FlowControllerFactory.java    From uima-uimafit with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new FlowControllerDescription for a given class and configuration parameters with
 * values
 * 
 * @param flowControllerClass
 *          the flow controller class
 * @param configurationParameters
 *          the configuration parameters
 * @param configurationValues
 *          the configuration parameter values
 * @param externalResources
 *          the external resources
 * @return a flow controller description
 * @throws ResourceInitializationException
 *           if the description could not be created
 */
public static FlowControllerDescription createFlowControllerDescription(
        Class<? extends FlowController> flowControllerClass,
        ConfigurationParameter[] configurationParameters, Object[] configurationValues,
        Map<String, ExternalResourceDescription> externalResources)
        throws ResourceInitializationException {
  FlowControllerDescription desc = new FlowControllerDescription_impl();
  desc.setFrameworkImplementation(Constants.JAVA_FRAMEWORK_NAME);
  desc.setImplementationName(flowControllerClass.getName());

  // set parameters
  setParameters(desc, flowControllerClass, configurationParameters, configurationValues);

  // Configure resource meta data
  ResourceMetaData meta = desc.getMetaData();
  ResourceMetaDataFactory.configureResourceMetaData(meta, flowControllerClass);

  // Extract external resource dependencies
  desc.setExternalResourceDependencies(createResourceDependencies(flowControllerClass));

  // Bind External Resources
  if (externalResources != null) {
    for (Entry<String, ExternalResourceDescription> e : externalResources.entrySet()) {
      bindResourceOnce(desc, e.getKey(), e.getValue());
    }
  }

  return desc;
}
 
Example #20
Source File: PearAnalysisEngineWrapper.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
@Override
public ResourceMetaData getMetaData() {
    return this.ae.getMetaData();
 }
 
Example #21
Source File: ConfigurableDataResourceSpecifier_impl.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
public ResourceMetaData getMetaData() {
  return mMetaData;
}
 
Example #22
Source File: ConfigurableDataResourceSpecifier_impl.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
public void setMetaData(ResourceMetaData aMetaData) {
  mMetaData = aMetaData;
}
 
Example #23
Source File: ResourceCreationSpecifier_impl.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
/**
 * @see ResourceCreationSpecifier#getMetaData()
 */
public ResourceMetaData getMetaData() {
  return mMetaData;
}
 
Example #24
Source File: CasCreationUtils.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
MetaDataCacheEntry(ResourceMetaData resourceMetaData) {
  processingResourceMetaData = (resourceMetaData instanceof ProcessingResourceMetaData) ? (ProcessingResourceMetaData) resourceMetaData : null;
  creationTime = System.currentTimeMillis(); 
  if (null == cleanupTimer) {
    if (cacheDebug) {
      System.err.format("GetMetaDataCache: Scheduling new cleanup task%n");
    }

    cleanupTimer = new Timer("metaDataCacheCleanup", true);  // run as daemon
    // create a new instance of the timer task, because a previous one may 
    // still be running
    TimerTask metaDataCacheCleanupTask = new TimerTask() {   
      @Override
      public void run() {
        synchronized (metaDataCache) {
          long now = System.currentTimeMillis();
          if (cacheDebug) {
            System.err.format("GetMetaDataCache: cleanup task running%n");
          }
          for (Iterator<Entry<MetaDataCacheKey, MetaDataCacheEntry>> it = metaDataCache.entrySet().iterator(); it.hasNext();) {
            Entry<MetaDataCacheKey, MetaDataCacheEntry> e = it.next();
            if (e.getValue().creationTime + HOLD_TIME < now) {
              if (cacheDebug) {
                System.err.format("GetMetaDataCache: cleanup task removing entry %s%n", e.getKey().toString() );
              }
              it.remove();
            }
          }
          if (metaDataCache.size() == 0) {
            if (cacheDebug) {
              System.err.format("GetMetaDataCache: cleanup task terminating, cache empty%n");
            }
            cancel();
            cleanupTimer.cancel();  // probably not needed, but for safety ...
            cleanupTimer = null;
          }
          if (cacheDebug) {
            System.err.format("GetMetaDataCache: cleanup task finished a cycle%n");
          }
        }
      }
    };
    cleanupTimer.schedule(metaDataCacheCleanupTask, HOLD_TIME, HOLD_TIME);
  }
}
 
Example #25
Source File: ConfigurationManagerImplBase.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
public synchronized void createContext(String aContextName, ResourceMetaData aResourceMetaData, Settings externalOverrides)
        throws ResourceConfigurationException {
  if (mContextNameToParamDeclsMap.containsKey(aContextName)) {
    return;
  }
  // first internally validate settings in the ResourceMetaData (catches data type problems,
  // settings for undefined parameters, etc.)
  aResourceMetaData.validateConfigurationParameterSettings();

  // Iterate through all declared parameters, calling abstract method to allow
  // concrete ConfigurationManager implementations to set up data structures to
  // provide access to the parameter values
  ConfigurationParameterDeclarations paramDecls = aResourceMetaData
          .getConfigurationParameterDeclarations();
  ConfigurationParameterSettings settings = aResourceMetaData.getConfigurationParameterSettings();

  // parameters in no group
  ConfigurationParameter[] paramsInNoGroup = paramDecls.getConfigurationParameters();
  if (paramsInNoGroup.length > 0) // group-less parameters
  {
    declareParameters(null, paramsInNoGroup, settings, aContextName, externalOverrides);
  }

  // parameter groups
  ConfigurationGroup[] groups = paramDecls.getConfigurationGroups();
  if (groups != null) {
    for (int i = 0; i < groups.length; i++) {
      String[] names = groups[i].getNames();
      {
        for (int j = 0; j < names.length; j++) {
          // common params
          ConfigurationParameter[] commonParams = paramDecls.getCommonParameters();
          if (commonParams != null) {
            declareParameters(names[j], commonParams, settings, aContextName, externalOverrides);
          }
          // params in group
          ConfigurationParameter[] params = groups[i].getConfigurationParameters();
          if (params != null) {
            declareParameters(names[j], params, settings, aContextName, externalOverrides);
          }
        }
      }
    }
  }

  // store parameter declarations in map for later access
  mContextNameToParamDeclsMap.put(aContextName, paramDecls);

  // validate
  validateConfigurationParameterSettings(aContextName);
}
 
Example #26
Source File: ResourceSpecifierFactory_impl.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
public ResourceMetaData createResourceMetaData() {
  return (ResourceMetaData) createObject(ResourceMetaData.class);
}
 
Example #27
Source File: PrimitiveAnalysisEngine_impl.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
/**
 * @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() });
  }
}
 
Example #28
Source File: FakeContentExtractor.java    From baleen with Apache License 2.0 4 votes vote down vote up
@Override
public ResourceMetaData getMetaData() {
  return null;
}
 
Example #29
Source File: PearAnalysisEngineWrapper.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
@Override
protected void setMetaData(ResourceMetaData aMetaData) {
  ((AnalysisEngineImplBase) ae).setMetaData(aMetaData);
}
 
Example #30
Source File: TestResourceServiceStub.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
/**
 * @see org.apache.uima.resource.service.ResourceService#getMetaData()
 */
public ResourceMetaData callGetMetaData() throws ResourceServiceException {
  lastMethodName = "callGetMetaData";
  lastMethodArgs = new Object[] {};
  return getMetaDataReturnValue;
}