org.apache.uima.collection.metadata.CpeDescriptorException Java Examples

The following examples show how to use org.apache.uima.collection.metadata.CpeDescriptorException. 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: CPEFactory.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Checks uniqueness of a given name. This name is compared against all Cas Processors already
 * defined. Cas Processor names must be unique.
 *
 * @param aName -
 *          name to check
 * @return - true if name is unique, false otherwise
 * @throws CpeDescriptorException the cpe descriptor exception
 */
private boolean isUniqueName(String aName) throws CpeDescriptorException {
  int index = 0;
  if (getCpeDescriptor().getCpeCasProcessors() != null
          && getCpeDescriptor().getCpeCasProcessors().getAllCpeCasProcessors() != null) {
    index = getCpeDescriptor().getCpeCasProcessors().getAllCpeCasProcessors().length;
  }
  for (int i = 0; i < index; i++) {
    CpeCasProcessor processor = getCpeDescriptor().getCpeCasProcessors().getCpeCasProcessor(i);
    String name = processor.getName();
    if (name != null && name.equalsIgnoreCase(aName)) {
      return false;
    }
  }
  return true;
}
 
Example #2
Source File: CpeBuilder.java    From uima-uimafit with Apache License 2.0 6 votes vote down vote up
private static CpeIntegratedCasProcessor createProcessor(String key,
        AnalysisEngineDescription aDesc) throws IOException, SAXException, CpeDescriptorException {
  URL descUrl = materializeDescriptor(aDesc).toURI().toURL();

  CpeInclude cpeInclude = getResourceSpecifierFactory().createInclude();
  cpeInclude.set(descUrl.toString());

  CpeComponentDescriptor ccd = getResourceSpecifierFactory().createDescriptor();
  ccd.setInclude(cpeInclude);

  CpeIntegratedCasProcessor proc = produceCasProcessor(key);
  proc.setCpeComponentDescriptor(ccd);
  proc.setAttributeValue(CpeDefaultValues.PROCESSING_UNIT_THREAD_COUNT, 1);
  proc.setActionOnMaxError(ACTION_ON_MAX_ERROR);
  proc.setMaxErrorCount(0);

  return proc;
}
 
Example #3
Source File: CasProcessorCpeObject.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Adds a given deployment param to the param list. If a param with a given name exists in the
 * list its value will be over-written.
 * 
 * @param aParamName -
 *          name of the new parameter
 * @param aParamValue -
 *          value of the new parameter
 * 
 * @throws CpeDescriptorException tbd
 */
@Override
public void addDeployParam(String aParamName, String aParamValue) throws CpeDescriptorException {
  boolean found = false;

  CasProcessorDeploymentParam[] params = deploymentParameters.getAll();
  for (int i = 0; params != null && i < params.length; i++) {
    if (aParamName.equals(params[i].getParameterName())) {
      params[i].setParameterValue(aParamValue);
      found = true;
      break;
    }
  }
  if (!found) {
    deploymentParameters.add(new CasProcessorDeploymentParamImpl(aParamName, aParamValue,
            "string"));
  }
}
 
Example #4
Source File: CpeBuilder.java    From bluima with Apache License 2.0 6 votes vote down vote up
@Override
public Boolean process() throws ResourceInitializationException,
        CpeDescriptorException {
    StatusCallbackListenerSlf4J listener = new StatusCallbackListenerSlf4J();
    CollectionProcessingEngine cpe = createCpe(listener);
    listener.setCpe(cpe);// workaround to get performanceReports

    cpe.process();
    StatusCallbackListenerSlf4J callback = (StatusCallbackListenerSlf4J) listener;
    while (!callback.isCollectionProcessComplete()) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            throw new RuntimeException("should not happen, though...");
        }
    }
    StopwatchUtils.closeAndPrint(); // close all stopwatches (for profiling)
    return true;
}
 
Example #5
Source File: CpeBuilder.java    From bluima with Apache License 2.0 6 votes vote down vote up
private static CpeIntegratedCasProcessor createProcessor(String key,
        AnalysisEngineDescription aDesc) throws IOException, SAXException,
        CpeDescriptorException {
    URL descUrl = materializeDescriptor(aDesc).toURI().toURL();

    CpeInclude cpeInclude = UIMAFramework.getResourceSpecifierFactory()
            .createInclude();
    cpeInclude.set(descUrl.toString());

    CpeComponentDescriptor ccd = UIMAFramework
            .getResourceSpecifierFactory().createDescriptor();
    ccd.setInclude(cpeInclude);

    CpeIntegratedCasProcessor proc = CpeDescriptorFactory
            .produceCasProcessor(key);
    proc.setCpeComponentDescriptor(ccd);
    proc.setAttributeValue(CpeDefaultValues.PROCESSING_UNIT_THREAD_COUNT, 1);
    proc.setActionOnMaxError(ACTION_ON_MAX_ERROR);
    proc.setMaxErrorCount(0);

    return proc;
}
 
Example #6
Source File: CpmPanel.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Called by createCpeDescription to add configuration parameter overrides to the CpeDescription
 * being constructed, based on the user's changes in the GUI.
 *
 * @param aSettings          the CasProcessorConfigurationParameterSettings element that will be modified
 * @param aPanel          the GUI panel representing settings for the CAS Processor
 * @throws CpeDescriptorException the cpe descriptor exception
 */
private void createParameterOverrides(CasProcessorConfigurationParameterSettings aSettings,
        MetaDataPanel aPanel) throws CpeDescriptorException {
  List values = aPanel.getValues();
  Iterator iterator = values.iterator();
  while (iterator.hasNext()) {
    ConfigField configField = (ConfigField) iterator.next();
    if (configField.isModified()) {
      String name = configField.getParameterName();
      Object value = configField.getFieldValue();

      if (value != null) {
        aSettings.setParameterValue(name, value);
      }
    }
  }
}
 
Example #7
Source File: CpmPanel.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Creates the empty cpe description.
 *
 * @return the cpe description
 */
private CpeDescription createEmptyCpeDescription() {
  CpeDescription cpeDesc = CpeDescriptorFactory.produceDescriptor();
  // We use CAS pool size default of 3
  try {
    CpeCasProcessors cpeCasProcs = CpeDescriptorFactory.produceCasProcessors();
    cpeDesc.setCpeCasProcessors(cpeCasProcs);
    cpeCasProcs.setPoolSize(3);
  } catch (CpeDescriptorException e) {
    e.printStackTrace(); // this should never happen
  }
  return cpeDesc;
}
 
Example #8
Source File: CpeLocalCasProcessorImpl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
@Override
public void setExecutable(String aCasProcessorExecutable) throws CpeDescriptorException {
  CasProcessorRunInSeperateProcess rip = getRunInSeparateProcess();
  if (rip != null) {
    CasProcessorExecutable exe = rip.getExecutable();
    if (exe != null) {
      exe.setExecutable(aCasProcessorExecutable);
    }
  }
}
 
Example #9
Source File: CpeLocalCasProcessorImpl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a new env key to the list of env keys. If a kay with a given key name exists the new key
 * value replaces the old.
 *
 * @param aEnvKeyName the a env key name
 * @param aEnvKeyValue the a env key value
 * @throws CpeDescriptorException the cpe descriptor exception
 */
@Override
public void addExecEnv(String aEnvKeyName, String aEnvKeyValue) throws CpeDescriptorException {
  CasProcessorRunInSeperateProcess rip = getRunInSeparateProcess();
  if (rip != null) {
    CasProcessorExecutable exe = rip.getExecutable();
    if (exe != null) {
      ArrayList envs = exe.getEnvs();
      NameValuePair nvp;
      boolean replacedExisiting = false;

      for (int i = 0; envs != null && i < envs.size(); i++) {
        nvp = (NameValuePair) envs.get(i);
        if (nvp.getName().equals(aEnvKeyName)) {
          nvp.setValue(aEnvKeyValue);
          replacedExisiting = true;
          break; // done
        }
      }
      if (envs != null && !replacedExisiting) {
        nvp = new NameValuePairImpl(aEnvKeyName, aEnvKeyValue);
        envs.add(nvp);
      }
    }
  }

  // }
}
 
Example #10
Source File: CpmPanel.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
@Override
public void tabClosed(JTabbedPaneWithCloseIcons source, int tabPos) {
  try {
    if (source == consumerTabbedPane) {
      currentCpeDesc.getCpeCasProcessors().removeCpeCasProcessor(aeSpecifiers.size() + tabPos);
      consumerSpecifiers.remove(tabPos);
    } else if (source == aeTabbedPane) {
      currentCpeDesc.getCpeCasProcessors().removeCpeCasProcessor(tabPos);
      aeSpecifiers.remove(tabPos);
    }
    selectedComponentsChanged = true;
  } catch (CpeDescriptorException e) {
    displayError(e);
  }
}
 
Example #11
Source File: CasProcessorCpeObject.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Deletes a given param from a param list if it exists. Returns a position in the current Param
 * List for a given 'aParamName'.
 *
 * @param aParamName -
 *          name of the param to find.
 * @return - position in the list as int, -1 if not found
 * @throws CpeDescriptorException the cpe descriptor exception
 */
private int deleteParam(String aParamName) throws CpeDescriptorException {
  CasProcessorDeploymentParams depParams = getDeploymentParameters();
  if (depParams != null) {
    CasProcessorDeploymentParam[] paramArray = depParams.getAll();
    for (int i = 0; paramArray != null && i < paramArray.length; i++) {
      if (aParamName.equals(paramArray[i].getParameterName())) {
        depParams.remove(paramArray[i]);
        return i;
      }
    }
  }
  return -1;
}
 
Example #12
Source File: CpeCasProcessorsImpl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * New API 01/06/2006.
 *
 * @param aPosition the a position
 * @param flag the flag
 * @return the cpe cas processor[]
 * @throws CpeDescriptorException the cpe descriptor exception
 */
public CpeCasProcessor[] removeCpeCasProcessor(int aPosition, boolean flag)
        throws CpeDescriptorException {
  if (aPosition <= casProcessors.size()) {
    casProcessors.remove(aPosition);
    return getAllCpeCasProcessors();
  }
  else {
    throw new CpeDescriptorException(CpmLocalizedMessage.getLocalizedMessage(
            CPMUtils.CPM_LOG_RESOURCE_BUNDLE, "UIMA_CPM_EXP_invalid_array_index__WARNING",
            new Object[] { Thread.currentThread().getName() }));
  }
}
 
Example #13
Source File: CpeLocalCasProcessorImpl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
@Override
public String getExecutable() throws CpeDescriptorException {
  CasProcessorRunInSeperateProcess rip = getRunInSeparateProcess();
  if (rip != null) {
    CasProcessorExecutable exe = rip.getExecutable();
    if (exe != null) {
      return exe.getExecutable();
    }
  }
  return null;
}
 
Example #14
Source File: CpeLocalCasProcessorImpl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isJava() throws CpeDescriptorException {
  CasProcessorRunInSeperateProcess rip = getRunInSeparateProcess();
  if (rip != null) {
    CasProcessorExecutable exe = rip.getExecutable();
    if (exe != null) {
      return (exe.getExecutable().equalsIgnoreCase("java"));
    }
  }
  return false;
}
 
Example #15
Source File: CpeDescriptionImpl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
@Override
public void setProcessingUnitThreadCount(int aSize) throws CpeDescriptorException {
  if (casProcessors == null) {
    casProcessors = CpeDescriptorFactory.produceCasProcessors();
  }
  casProcessors.setConcurrentPUCount(aSize);
}
 
Example #16
Source File: CpeDescriptionImpl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
@Override
public void addCasProcessor(int index, CpeCasProcessor aCasProcessor)
        throws CpeDescriptorException {

  if (casProcessors == null) {
    casProcessors = CpeDescriptorFactory.produceCasProcessors();
  }
  casProcessors.addCpeCasProcessor(aCasProcessor, index);

}
 
Example #17
Source File: CpeDescriptorFactory.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Produce resource manager configuration.
 *
 * @param aResourceMgrConfigurationPath the a resource mgr configuration path
 * @param aDescriptor the a descriptor
 * @return the cpe resource manager configuration
 * @throws CpeDescriptorException the cpe descriptor exception
 */
public static CpeResourceManagerConfiguration produceResourceManagerConfiguration(
        String aResourceMgrConfigurationPath, CpeDescription aDescriptor)
        throws CpeDescriptorException {
  if (aDescriptor == null) {
    aDescriptor = produceDescriptor();
  }
  CpeResourceManagerConfiguration resMgr = produceResourceManagerConfiguration(aResourceMgrConfigurationPath);
  aDescriptor.setCpeResourceManagerConfiguration(resMgr);
  return resMgr;
}
 
Example #18
Source File: CasProcessorCpeObject.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
   * Sets the sofa.
   *
   * @param aSoFa the new sofa
   * @throws CpeDescriptorException tbd
   * @deprecated 
   */
  @Override
  @Deprecated
public void setSOFA(String aSoFa) throws CpeDescriptorException {
    // if (casProcessor != null )
    // {
    // casProcessor.setContentTag(aSoFa);
    // }
  }
 
Example #19
Source File: CpeDescriptionImpl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
@Override
public void addCasProcessor(CpeCasProcessor aCasProcessor) throws CpeDescriptorException {
  if (casProcessors == null) {
    casProcessors = CpeDescriptorFactory.produceCasProcessors();
  }
  casProcessors.addCpeCasProcessor(aCasProcessor);
}
 
Example #20
Source File: CpeCasProcessorsImpl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
@Override
public void removeCpeCasProcessor(int aPosition) throws CpeDescriptorException {
  if (aPosition <= casProcessors.size()) {
    casProcessors.remove(aPosition);
  }
  else {
    throw new CpeDescriptorException(CpmLocalizedMessage.getLocalizedMessage(
            CPMUtils.CPM_LOG_RESOURCE_BUNDLE, "UIMA_CPM_EXP_invalid_array_index__WARNING",
            new Object[] { Thread.currentThread().getName() }));
  }
}
 
Example #21
Source File: CpeDescriptionImpl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
@Override
public CpeCollectionReader[] getAllCollectionCollectionReaders() throws CpeDescriptorException {
  if (collectionReader == null) {
    return new CpeCollectionReader[0];
  }
  CpeCollectionReader[] readers = new CpeCollectionReader[1];
  readers[0] = collectionReader;
  return readers;
}
 
Example #22
Source File: CpeDescriptorFactory.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Produce cas processors.
 *
 * @param aDescriptor to use to produce the CPE CAS Processors
 * @return Cpe CAS Processors
 * @throws CpeDescriptorException if an error occurs
 */
public static CpeCasProcessors produceCasProcessors(CpeDescription aDescriptor)
        throws CpeDescriptorException {
  if (aDescriptor == null) {
    aDescriptor = produceDescriptor();
  }
  CpeCasProcessors processors = new CpeCasProcessorsImpl();
  aDescriptor.setCpeCasProcessors(processors);
  return processors;
}
 
Example #23
Source File: CpeLocalCasProcessorImpl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
@Override
protected void addDefaults() throws CpeDescriptorException {
  if (getRunInSeperateProcess() == null) {
    CasProcessorRunInSeperateProcess sepProcess = CpeDescriptorFactory
            .produceRunInSeperateProcess();
    CasProcessorExecutable exe = CpeDescriptorFactory.produceCasProcessorExecutable();
    exe.setExecutable("default");

    sepProcess.setExecutable(exe);
    setRunInSeperateProcess(sepProcess);
  }
  if (getDeploymentParams() == null) {
    CasProcessorDeploymentParams deployParams = CpeDescriptorFactory.produceDeployParams();
    CasProcessorDeploymentParam param = CpeDescriptorFactory.produceDeployParam();
    param.setParameterName("vnsHost");
    param.setParameterType("String");
    param.setParameterValue("127.0.0.1");
    deployParams.add(param);
    param = CpeDescriptorFactory.produceDeployParam();
    param.setParameterName("vnsPort");
    param.setParameterType("String");
    param.setParameterValue("9904");
    deployParams.add(param);
    this.setDeploymentParams(deployParams);
  }

  super.addDefaults();

}
 
Example #24
Source File: CpeLocalCasProcessorImpl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Instantiates a new cpe local cas processor impl.
 *
 * @param aName the a name
 * @param aSoFa the a so fa
 * @throws CpeDescriptorException the cpe descriptor exception
 */
protected CpeLocalCasProcessorImpl(String aName, String aSoFa) throws CpeDescriptorException {
  super();
  try {
    super.setName(aName);
    // super.setContentTag(aSoFa);
    super.setDeployment("local");
    addDefaults();
  } catch (Exception e) {
    e.printStackTrace();
    throw new CpeDescriptorException(e.getMessage());
  }
}
 
Example #25
Source File: CpmPanel.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Adds the consumer.
 *
 * @param consumerSpecifierFile the consumer specifier file
 * @throws CpeDescriptorException the cpe descriptor exception
 * @throws InvalidXMLException the invalid XML exception
 * @throws IOException Signals that an I/O exception has occurred.
 * @throws ResourceConfigurationException the resource configuration exception
 */
private void addConsumer(String consumerSpecifierFile) throws CpeDescriptorException,
        InvalidXMLException, IOException, ResourceConfigurationException {
  String tempName = new File(consumerSpecifierFile).getName(); // overriden later
  CpeCasProcessor casProc = CpeDescriptorFactory.produceCasProcessor(tempName);
  casProc.setDescriptor(consumerSpecifierFile);
  casProc.setBatchSize(10000);
  casProc.getErrorHandling().getErrorRateThreshold().setMaxErrorCount(0);

  // add to pipeline as last CAS Processor
  currentCpeDesc.addCasProcessor(casProc);
  // update GUI
  addConsumer(casProc);
}
 
Example #26
Source File: CpeLocalCasProcessorImpl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the exec env.
 *
 * @return the exec env
 * @throws CpeDescriptorException the cpe descriptor exception
 */
public List getExecEnv() throws CpeDescriptorException {
  CasProcessorRunInSeperateProcess rip = getRunInSeparateProcess();
  if (rip != null) {
    CasProcessorExecutable exe = rip.getExecutable();
    if (exe != null) {
      return exe.getEnvs();
    }
  }
  return new ArrayList(); // empty list
}
 
Example #27
Source File: CasProcessorCpeObject.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Adds default configuration shared by CasProcessors.
 *
 * @throws CpeDescriptorException tbd
 */
protected void addDefaults() throws CpeDescriptorException {
  if (getCasProcessorFilter() == null) {
    CasProcessorFilter filter = CpeDescriptorFactory.produceCasProcessorFilter("");
    setCasProcessorFilter(filter);
  }
  if (getErrorHandling() == null) {
    CasProcessorErrorHandling errorHandling = CpeDescriptorFactory
            .produceCasProcessorErrorHandling();
    CasProcessorMaxRestarts maxRestart = CpeDescriptorFactory.produceCasProcessorMaxRestarts();
    maxRestart.setRestartCount(30);
    maxRestart.setAction("terminate");
    errorHandling.setMaxConsecutiveRestarts(maxRestart);
    CasProcessorTimeout timeout = CpeDescriptorFactory.produceCasProcessorTimeout();
    timeout.set(100000);
    errorHandling.setTimeout(timeout);
    CasProcessorErrorRateThreshold errorThreshold = CpeDescriptorFactory
            .produceCasProcessorErrorRateThreshold();
    errorThreshold.setMaxErrorCount(100);
    errorThreshold.setMaxErrorSampleSize(1000);
    errorThreshold.setAction("terminate");
    errorHandling.setErrorRateThreshold(errorThreshold);
    setErrorHandling(errorHandling);
  }
  if (getCheckpoint() == null) {
    CpeCheckpoint checkpoint = CpeDescriptorFactory.produceCpeCheckpoint();
    checkpoint.setBatchSize(1);
    checkpoint.setFilePath(CpeDefaultValues.PROCESSOR_CHECKPOINT_FILE);
    checkpoint.setFrequency(1000, true);
    setCheckpoint(checkpoint);
  }
}
 
Example #28
Source File: CasProcessorCpeObject.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the error handling.
 *
 * @param aErrorHandling the new error handling
 * @throws CpeDescriptorException the cpe descriptor exception
 */
/*
 * (non-Javadoc)
 * 
 * @see org.apache.uima.collection.metadata.CpeCasProcessor#setErrorHandling(org.apache.uima.collection.metadata.CasProcessorErrorHandling)
 */
public void setErrorHandling(CasProcessorErrorHandling aErrorHandling)
        throws CpeDescriptorException {
  errorHandling = aErrorHandling;
}
 
Example #29
Source File: CasProcessorDeploymentParamsImpl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
@Override
public CasProcessorDeploymentParam get(String aParamName) throws CpeDescriptorException {
  for (int i = 0; params != null && i < params.size(); i++) {
    if (aParamName.equals(((CasProcessorDeploymentParam) params.get(i)).getParameterName())) {
      return (CasProcessorDeploymentParam) params.get(i);
    }
  }
  return null;
}
 
Example #30
Source File: CpeDescriptionImpl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
@Override
public void setAllCollectionCollectionReaders(CpeCollectionReader[] areaders)
        throws CpeDescriptorException {
  if (areaders == null || areaders.length == 0) {
    collectionReader = null;
  }
  else {
    collectionReader = areaders[0];
  }
}