Java Code Examples for org.apache.uima.UIMAFramework#produceCollectionProcessingEngine()

The following examples show how to use org.apache.uima.UIMAFramework#produceCollectionProcessingEngine() . 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: CollectionProcessingEngine_implTest.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
public void testCasMultiplierTypeSystem() throws Throwable {
  CpeDescription cpeDesc = UIMAFramework.getXMLParser()
          .parseCpeDescription(new XMLInputSource(
                  JUnitExtension.getFile("CollectionProcessingEngineImplTest/cpeWithWrappedCasMultiplier.xml")));
  CollectionProcessingEngine cpe = UIMAFramework.produceCollectionProcessingEngine(cpeDesc);
  // create and register a status callback listener
  TestStatusCallbackListener listener = new TestStatusCallbackListener();
  cpe.addStatusCallbackListener(listener);

  // run CPM
  cpe.process();

  // wait until CPM has finished
  while (!listener.isFinished()) {
    Thread.sleep(5);
  }
  
  //check that there was no exception
  if (listener.getLastStatus().isException()) {
    throw (Throwable)listener.getLastStatus().getExceptions().get(0);
  }
}
 
Example 2
Source File: InstallationTester.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Checks if a given CPE specifier file can be used to produce an instance of CPE. Returns
 * <code>true</code>, if a CPE can be instantiated, <code>false</code> otherwise.
 * 
 * @param specifier the resource specifier
 * @param resource_manager a new resource_manager
 * @param status the place where to put the results
 *
 * @throws IOException
 *           If an I/O exception occurred while creating <code>XMLInputSource</code>.
 * @throws InvalidXMLException
 *           If the XML parser failed to parse the given input file.
 * @throws ResourceInitializationException
 *           If the specified CPE cannot be instantiated.
 */
private void testCpeCongifuration(ResourceSpecifier specifier, 
                                  ResourceManager resource_manager, 
                                  TestStatus status) 
                                            throws IOException, InvalidXMLException, ResourceInitializationException {
 
      CollectionProcessingEngine cpe = UIMAFramework.produceCollectionProcessingEngine(
              (CpeDescription) specifier, resource_manager, null);
  
      if (cpe != null) {
        status.setRetCode(TestStatus.TEST_SUCCESSFUL);
      } else {
        status.setRetCode(TestStatus.TEST_NOT_SUCCESSFUL);
        status.setMessage(I18nUtil.localizeMessage(PEAR_MESSAGE_RESOURCE_BUNDLE,
                "installation_verification_cpe_not_created", new Object[] { this.pkgBrowser
                        .getInstallationDescriptor().getMainComponentId() }, null));
      }
  
}
 
Example 3
Source File: SofaMixedCPE_Test.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
protected void setUp() throws Exception {
  UIMAFramework.getXMLParser().enableSchemaValidation(true);
  cpeSpecifierFile = JUnitExtension.getFile("CpeSofaTest/SofaMixedCPE.xml");
  // Use the specifier file to determine where the specifiers live.
  System.setProperty("CPM_HOME", cpeSpecifierFile.getParentFile().getParentFile().getAbsolutePath());
  cpeDesc = UIMAFramework.getXMLParser()
          .parseCpeDescription(new XMLInputSource(cpeSpecifierFile));
  // instantiate a cpe
  cpe = UIMAFramework.produceCollectionProcessingEngine(cpeDesc, null);
  // add status callback
  statCbL1 = new StatusCallbackListenerImpl1();
  cpe.addStatusCallbackListener(statCbL1);
  firstFailure = null;
}
 
Example 4
Source File: CpmAE_ErrorTest.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * <b>testcase:</b> set the errorRateThreshold to terminate and leave the default value at
 * 100/1000. Every 5th document an AnnotatorProcessException is thrown.
 * <code>&lt;errorRateThreshold action="terminate" value="100/1000"/&gt;</code><br>
 * <b>expected behaviour:</b><br>
 * The cpm should not finish. Instead, after 100 Exceptions + 1 the aborted -method is called by
 * the cpm. The cpm shut down.
 * 
 * @throws Exception -
 */
public void testAeErrorRateThresholdTerminateDefault() throws Exception {
  int documentCount = 1000; // number of documents to process
  TestStatusCallbackListener listener = new TestStatusCallbackListener();
  int exceptionSequence = 5;
  String functionName = "process";
  String exceptionName = "AnnotatorProcessException";
  ManageOutputDevice.setAllSystemOutputToNirvana();

  // setup CPM
  Object[] objs = setupConfigurableCpm(documentCount, exceptionName, exceptionSequence,
          functionName);

  CpeDescription cpeDesc = (CpeDescription) objs[0];
  cpeDesc.setProcessingUnitThreadCount(1);
  CpeIntegratedCasProcessor integratedProcessor = (CpeIntegratedCasProcessor) objs[1];
  integratedProcessor.setActionOnMaxError("terminate");
  CollectionProcessingEngine cpe = UIMAFramework.produceCollectionProcessingEngine(cpeDesc, null,
          null);

  // register a Status Callback Listener
  cpe.addStatusCallbackListener(listener);
  cpeProcessNoMsg(cpe, listener);

  ManageOutputDevice.setAllSystemOutputToDefault();
  // check the results, if everything worked as expected
  assertEquals(
          "The cpm called the listener, that the cpm has finished - which normally could not be.",
          false, listener.isFinished());
  assertEquals("The aborted-method of the listener wasn't called.", true, listener.isAborted());
  assertEquals("There are not as much exceptions as expected! ", (100 + 1), FunctionErrorStore
          .getCount());
  // that's it.
}
 
Example 5
Source File: CpmAE_ErrorTest.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
public void testAeErrorRateActionOnMaxRestarts() throws Exception {
  int exceptionSequence = 1;
  int documentCount = 10; // number of documents processed
  TestStatusCallbackListener listener = new TestStatusCallbackListener();
  String functionName = "process";
  String exceptionName = "AnnotatorProcessException";
  // disable System.out
  ManageOutputDevice.setAllSystemOutputToNirvana();
  Object[] objs = setupConfigurableCpm(documentCount, exceptionName, exceptionSequence,
          functionName);

  CpeDescription cpeDesc = (CpeDescription) objs[0];
  cpeDesc.setProcessingUnitThreadCount(1);
  CpeIntegratedCasProcessor integratedProcessor = (CpeIntegratedCasProcessor) objs[1];
  integratedProcessor.setActionOnMaxError("continue");
  integratedProcessor.setMaxErrorCount(3);
  integratedProcessor.setMaxErrorSampleSize(100);

  integratedProcessor.setActionOnMaxRestart("continue");
  integratedProcessor.setMaxRestartCount(0);
  CollectionProcessingEngine cpe = UIMAFramework.produceCollectionProcessingEngine(cpeDesc, null,
          null);

  // Create and register a Status Callback Listener
  cpe.addStatusCallbackListener(listener);
  cpeProcessNoMsg(cpe, listener);
  // enable System.out
  ManageOutputDevice.setAllSystemOutputToDefault();
  // check the results, if everything worked as expected
  assertEquals(
          "The cpm propably didn't finish correctly! The aborted method of the listener was called.",
          false, listener.isAborted());
  assertEquals("The cpm didn't finish by calling the Listener.", true, listener.isFinished());
  assertEquals("There are not as many exceptions as expected:", 40, FunctionErrorStore.getCount());
}
 
Example 6
Source File: CpeImportTest.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Test a CPE descriptor using import by name and requiring data patht o be set
 */
public void testImportsWithDataPath() throws Exception {
  CpeDescription cpeDesc = UIMAFramework.getXMLParser().parseCpeDescription(
          new XMLInputSource(JUnitExtension.getFile("CollectionProcessingEngineImplTest/CpeImportDataPathTest.xml")));
  ResourceManager resMgr = UIMAFramework.newDefaultResourceManager();
  File dataPathDir = JUnitExtension.getFile("CollectionProcessingEngineImplTest/imports");
  resMgr.setDataPath(dataPathDir.getAbsolutePath());
  CollectionProcessingEngine cpe = UIMAFramework.produceCollectionProcessingEngine(cpeDesc, resMgr, null);

  TestStatusCallbackListener listener = new TestStatusCallbackListener();
  cpe.addStatusCallbackListener(listener);

  cpe.process();

  // wait until CPE has finished
  while (!listener.isFinished()) {
    Thread.sleep(5);
  }

  // check that components were called
  final int documentCount = 1000; //this is the # of documents produced by the test CollectionReader
  Assert.assertEquals("StatusCallbackListener", documentCount, listener
          .getEntityProcessCompleteCount());
  Assert.assertEquals("CasConsumer process Count", documentCount, FunctionErrorStore
          .getCasConsumerProcessCount());
  Assert.assertEquals("Annotator process count", documentCount, FunctionErrorStore
          .getAnnotatorProcessCount());
  Assert.assertEquals("Collection reader getNext count", documentCount, FunctionErrorStore
          .getCollectionReaderGetNextCount());
}
 
Example 7
Source File: CpeImportTest.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Test a CPE descriptor that uses the import syntax.
 */
public void testImports() throws Exception {
  CpeDescription cpeDesc = UIMAFramework.getXMLParser().parseCpeDescription(
          new XMLInputSource(JUnitExtension.getFile("CollectionProcessingEngineImplTest/CpeImportTest.xml")));            
  CollectionProcessingEngine cpe = UIMAFramework.produceCollectionProcessingEngine(cpeDesc);

  TestStatusCallbackListener listener = new TestStatusCallbackListener();
  cpe.addStatusCallbackListener(listener);

  cpe.process();

  // wait until CPE has finished
  while (!listener.isFinished()) {
    Thread.sleep(5);
  }

  // check that components were called
  final int documentCount = 1000; //this is the # of documents produced by the test CollectionReader
  Assert.assertEquals("StatusCallbackListener", documentCount, listener
          .getEntityProcessCompleteCount());
  Assert.assertEquals("CasConsumer process Count", documentCount, FunctionErrorStore
          .getCasConsumerProcessCount());
  Assert.assertEquals("Annotator process count", documentCount, FunctionErrorStore
          .getAnnotatorProcessCount());
  Assert.assertEquals("Collection reader getNext count", documentCount, FunctionErrorStore
          .getCollectionReaderGetNextCount());
}
 
Example 8
Source File: CpmAE_ErrorTest.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * <b>testcase:</b> set the errorRateThreshold to action:continue and set the value to 5/15.
 * Every 2nd document an AnnotatorProcessException is thrown.
 * <code>&lt;errorRateThreshold action="continue" value="5/15"/&gt;</code><br>
 * <b>expected behaviour:</b><br>
 * The cpm should finish, because of the continue action.
 * 
 * @throws Exception -
 */
public void testAeErrorRateThresholdContinue() throws Exception {
  int exceptionSequence = 4;
  int documentCount = 20; // number of documents processed
  TestStatusCallbackListener listener = new TestStatusCallbackListener();
  String functionName = "process";
  String exceptionName = "AnnotatorProcessException";
  ManageOutputDevice.setAllSystemOutputToNirvana();

  Object[] objs = setupConfigurableCpm(documentCount, exceptionName, exceptionSequence,
          functionName);

  CpeDescription cpeDesc = (CpeDescription) objs[0];
  cpeDesc.setProcessingUnitThreadCount(1);
  CpeIntegratedCasProcessor integratedProcessor = (CpeIntegratedCasProcessor) objs[1];
  integratedProcessor.setActionOnMaxError("continue");
  integratedProcessor.setMaxErrorCount(5);
  integratedProcessor.setMaxErrorSampleSize(15);
  CollectionProcessingEngine cpe = UIMAFramework.produceCollectionProcessingEngine(cpeDesc, null,
          null);

  // Create and register a Status Callback Listener
  // listener = new CollectionReaderStatusCallbackListener(cpe);
  cpe.addStatusCallbackListener(listener);
  cpeProcessNoMsg(cpe, listener);

  ManageOutputDevice.setAllSystemOutputToDefault();
  // check the results, if everything worked as expected
  assertEquals(
          "The cpm propably didn't finish correctly! The aborted method of the listener was called.",
          false, listener.isAborted());
  assertEquals("The cpm didn't finish by calling the Listener.", true, listener.isFinished());
  // TODO: write a function which calculates the expected number of occuring errors
  // assertEquals("There are not as much exceptions as expected! ", 44,
  // FunctionErrorStore.getCount());
}
 
Example 9
Source File: CpmAE_ErrorTest.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * <b>testcase:</b> set the errorRateThreshold to action:terminate and set the value to 5/10.
 * Every 5th document an AnnotatorProcessException is thrown.
 * <code>&lt;errorRateThreshold action="terminate" value="5/10"/&gt;</code><br>
 * <b>expected behaviour:</b><br>
 * The cpm should finish, because this failure-rate is in the accepted range.
 * 
 * @throws Exception -
 */
public void testAeErrorRateThresholdTerminateModified2() throws Exception {
  int exceptionSequence = 5;
  int documentCount = 100; // number of documents processed
  TestStatusCallbackListener listener = new TestStatusCallbackListener();
  String functionName = "process";
  String exceptionName = "AnnotatorProcessException";
  ManageOutputDevice.setAllSystemOutputToNirvana();

  // setup CPM
  Object[] objs = setupConfigurableCpm(documentCount, exceptionName, exceptionSequence,
          functionName);

  CpeDescription cpeDesc = (CpeDescription) objs[0];
  cpeDesc.setProcessingUnitThreadCount(1);
  CpeIntegratedCasProcessor integratedProcessor = (CpeIntegratedCasProcessor) objs[1];
  integratedProcessor.setActionOnMaxError("terminate");
  integratedProcessor.setMaxErrorCount(5);
  integratedProcessor.setMaxErrorSampleSize(10);
  CollectionProcessingEngine cpe = UIMAFramework.produceCollectionProcessingEngine(cpeDesc, null,
          null);

  // Create and register a Status Callback Listener
  // listener = new CollectionReaderStatusCallbackListener(cpe);
  cpe.addStatusCallbackListener(listener);
  cpeProcessNoMsg(cpe, listener);

  ManageOutputDevice.setAllSystemOutputToDefault();
  // check the results, if everything worked as expected
  assertEquals(
          "The cpm is still working or the collectionProcessComplete-method of the listener was not called.",
          true, listener.isFinished());
  assertEquals("The cpm didn't finish correctly! Abort in the listener was called.", false,
          listener.isAborted());
  assertEquals("There are not as much exceptions as expected! ", countExceptions(documentCount,
          exceptionSequence), FunctionErrorStore.getCount());
  // that's it.
}
 
Example 10
Source File: SofaCPE_Test.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
protected void setUp() throws Exception {
  UIMAFramework.getXMLParser().enableSchemaValidation(true);
  cpeSpecifierFile = JUnitExtension.getFile("CpeSofaTest/SofaCPE.xml");
  // Use the specifier file to determine where the specifiers live.
  System.setProperty("CPM_HOME", cpeSpecifierFile.getParentFile().getParentFile().getAbsolutePath());
  cpeDesc = UIMAFramework.getXMLParser()
          .parseCpeDescription(new XMLInputSource(cpeSpecifierFile));
  // instantiate a cpe
  cpe = UIMAFramework.produceCollectionProcessingEngine(cpeDesc, null);
  // add status callback
  statCbL1 = new StatusCallbackListenerImpl1();
  cpe.addStatusCallbackListener(statCbL1);
  firstFailure = null;
}
 
Example 11
Source File: CpmPanel.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Start processing.
 */
private void startProcessing() {
  // Check that Collection Reader is selected
  if (collectionReaderDesc == null) {
    JOptionPane.showMessageDialog(CpmPanel.this, "No Collection Reader has been selected",
            "Error", JOptionPane.ERROR_MESSAGE);
    transportControlPanel.reset();
    resetScreen();
    return;
  }

  try {
    // update the parameter overrides according to GUI settings
    updateCpeDescriptionParameterOverrides();

    // intantiate CPE
    mCPE = null;  // to allow GC of previous ae's that may
                  // hold onto lots of memory e.g. OpenNLP
    mCPE = UIMAFramework.produceCollectionProcessingEngine(currentCpeDesc);

    // attach callback listener
    StatusCallbackListenerImpl statCbL = new StatusCallbackListenerImpl();
    mCPE.addStatusCallbackListener(statCbL);

    // start processing
    mCPE.process();
  } catch (Exception ex) {
    resetScreen();
    displayError(ex);
  }

}
 
Example 12
Source File: CpmAE_ErrorTest.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * <b>testcase:</b> limit the process count of documents to a specific number
 * <code>&lt;numToProcess&gt;20&lt;/numToProcess&gt;</code><br>
 * <b>expected behaviour:</b><br>
 * After havening successfully processed the given number of documents the process should finish.
 * 
 * @throws Exception -
 */
public void testNumToProcess() throws Exception {
  int exceptionSequence = 25;
  int documentCount = 50; // number of documents processed
  TestStatusCallbackListener listener = new TestStatusCallbackListener();
  String functionName = "process";
  String exceptionName = "AnnotatorProcessException";
  ManageOutputDevice.setAllSystemOutputToNirvana();

  // setup CPM
  Object[] objs = setupConfigurableCpm(documentCount, exceptionName, exceptionSequence,
          functionName);

  CpeDescription cpeDesc = (CpeDescription) objs[0];
  cpeDesc.setProcessingUnitThreadCount(1);
  cpeDesc.setNumToProcess(20);
  CpeIntegratedCasProcessor integratedProcessor = (CpeIntegratedCasProcessor) objs[1];
  integratedProcessor.setActionOnMaxError("terminate");
  CollectionProcessingEngine cpe = UIMAFramework.produceCollectionProcessingEngine(cpeDesc, null,
          null);

  // Create and register a Status Callback Listener
  // listener = new CollectionReaderStatusCallbackListener(cpe);
  cpe.addStatusCallbackListener(listener);
  cpeProcessNoMsg(cpe, listener);

  ManageOutputDevice.setAllSystemOutputToDefault();
  // check the results, if everything worked as expected
  assertEquals(
          "The cpm propably didn't finish correctly! The aborted method of the listener was called.",
          false, listener.isAborted());
  assertEquals("The cpm didn't finish by calling the Listener.", true, listener.isFinished());
  assertEquals("There are not as much exceptions as expected! ", 0, FunctionErrorStore.getCount());
  assertEquals("There is a difference between the expected and the processed document number. ",
          20, FunctionErrorStore.getAnnotatorProcessCount());
}
 
Example 13
Source File: CpeBuilder.java    From bluima with Apache License 2.0 5 votes vote down vote up
public CollectionProcessingEngine createCpe(StatusCallbackListener aListener)
        throws ResourceInitializationException, CpeDescriptorException {
    ResourceManager resMgr = UIMAFramework.newDefaultResourceManager();

    // max errors
    if (maxErrors != 0) {
        for (CpeCasProcessor cpeCasProcessor : cpeDesc
                .getCpeCasProcessors().getAllCpeCasProcessors()) {
            if (maxErrors == -1) // infinite nr errors ok
                cpeCasProcessor.setActionOnMaxError("continue");
            else if (maxErrors > 0)
                cpeCasProcessor.setMaxErrorCount(maxErrors);
        }
    }

    // thread cnt
    if (maxProcessingUnitThreatCount == 0) {
        cpeDesc.getCpeCasProcessors().setPoolSize(3);
    } else {
        cpeDesc.getCpeCasProcessors().setPoolSize(
                maxProcessingUnitThreatCount + 2);
        cpeDesc.setProcessingUnitThreadCount(maxProcessingUnitThreatCount);
    }

    CollectionProcessingEngine cpe = UIMAFramework
            .produceCollectionProcessingEngine(cpeDesc, resMgr, null);
    cpe.addStatusCallbackListener(aListener);
    return cpe;
}
 
Example 14
Source File: SimpleRunCPE.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor for the class.
 *
 * @param args          command line arguments into the program - see class description
 * @throws Exception the exception
 */
public SimpleRunCPE(String args[]) throws Exception {
  mStartTime = System.currentTimeMillis();

  // check command line args
  if (args.length < 1) {
    printUsageMessage();
    System.exit(1);
  }

  // parse CPE descriptor
  System.out.println("Parsing CPE Descriptor");
  CpeDescription cpeDesc = UIMAFramework.getXMLParser().parseCpeDescription(
          new XMLInputSource(args[0]));
  // instantiate CPE
  System.out.println("Instantiating CPE");
  mCPE = UIMAFramework.produceCollectionProcessingEngine(cpeDesc);

  // Create and register a Status Callback Listener
  mCPE.addStatusCallbackListener(new StatusCallbackListenerImpl());

  // Start Processing
  System.out.println("Running CPE");
  mCPE.process();

  // Allow user to abort by pressing Enter
  System.out.println("To abort processing, type \"abort\" and press enter.");
  while (true) {
    String line = new BufferedReader(new InputStreamReader(System.in)).readLine();
    if ("abort".equals(line) && mCPE.isProcessing()) {
      System.out.println("Aborting...");
      mCPE.stop();
      break;
    }
  }
}
 
Example 15
Source File: CpmInitTest.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
/**
 * setup the CPM with base functionality.
 * 
 * @param documentCount
 *          how many documents should be processed
 * @param threadCount
 *          how many threads are used by the cpm
 * 
 * @return CollectionProcessingEngine - initialized cpe
 */
private CollectionProcessingEngine setupCpm(int documentCount, int threadCount,
        boolean useSlowAnnotator, boolean singleThreaded) throws Exception {
  CpeDescription cpeDesc = null;
  CollectionProcessingEngine cpe = null;

  try {
    String colReaderBase = JUnitExtension.getFile("CpmTests" + separator
            + "ErrorTestCollectionReader.xml").getAbsolutePath();
    String taeBase = JUnitExtension.getFile("CpmTests" + separator + "ErrorTestAnnotator.xml").getAbsolutePath();
    String casConsumerBase = JUnitExtension.getFile("CpmTests" + separator
            + "ErrorTestCasConsumer.xml").getAbsolutePath();

    // created needed descriptors
    String colReaderDesc = DescriptorMakeUtil.makeCollectionReader(colReaderBase, documentCount);
    String taeDesc = DescriptorMakeUtil.makeAnalysisEngine(taeBase);
    String casConsumerDesc = DescriptorMakeUtil.makeCasConsumer(casConsumerBase);

    // create cpm descriptor
    cpeDesc = CpeDescriptorFactory.produceDescriptor();
    cpeDesc.setInputQueueSize(2);
    cpeDesc.setOutputQueueSize(2);
    cpeDesc.setProcessingUnitThreadCount(threadCount);

    if (singleThreaded) {
      cpeDesc.setDeployment("single-threaded");
    }

    // add tae
    CpeIntegratedCasProcessor integratedProcessor = CpeDescriptorFactory
            .produceCasProcessor("ErrorTestAnnotator");
    integratedProcessor.setDescriptor(taeDesc);
    cpeDesc.addCasProcessor(integratedProcessor);

    // add slow annotator if requested
    if (useSlowAnnotator) {
      CpeIntegratedCasProcessor slowProcessor = CpeDescriptorFactory
              .produceCasProcessor("SlowAnnotator");
      slowProcessor.setDescriptor(JUnitExtension.getFile("CpmTests" + separator
              + "SlowAnnotator.xml").getAbsolutePath());
      cpeDesc.addCasProcessor(slowProcessor);
    }

    // add casConsumer
    CpeIntegratedCasProcessor casConsumer = CpeDescriptorFactory
            .produceCasProcessor("ErrorTest CasConsumer");
    casConsumer.setDescriptor(casConsumerDesc);
    cpeDesc.addCasProcessor(casConsumer);

    // add collectionReader
    cpeDesc.addCollectionReader(colReaderDesc);

    // produce cpe
    cpe = UIMAFramework.produceCollectionProcessingEngine(cpeDesc, null, null);
  } catch (Exception e) {
    e.printStackTrace();
  }

  return cpe;
}
 
Example 16
Source File: SimpleRunCPE.java    From biomedicus with Apache License 2.0 4 votes vote down vote up
public SimpleRunCPE(CpeDescription cpeDesc) throws ResourceInitializationException {
  LOGGER.info("Instantiating CPE");
  collectionProcessingEngine = UIMAFramework.produceCollectionProcessingEngine(cpeDesc);
  collectionProcessingEngine.addStatusCallbackListener(new StatusCallbackListener() {

    @Override
    public void initializationComplete() {
      LOGGER.info("CPM Initialization Complete");
    }

    @Override
    public void batchProcessComplete() {
      LOGGER.info("Completed " + entityCount + " documents");
      if (size > 0) {
        LOGGER.info("; " + size + " characters");
      }
    }

    @Override
    public void collectionProcessComplete() {
      LOGGER.info("Completed " + entityCount + " documents");
      if (size > 0) {
        LOGGER.info("; " + size + " characters");
      }
      LOGGER.info(
          "PERFORMANCE REPORT \n" + collectionProcessingEngine.getPerformanceReport().toString());

      completionSemaphore.release();
    }

    @Override
    public void paused() {
      LOGGER.info("Paused");
    }

    @Override
    public void resumed() {
      LOGGER.info("Resumed");
    }

    @Override
    public void aborted() {
      LOGGER.error("CPE processing was aborted");

      completionSemaphore.release();
    }

    @Override
    public void entityProcessComplete(CAS aCas, EntityProcessStatus aStatus) {
      exceptions.addAll(aStatus.getExceptions());
      LOGGER.debug(aStatus.getStatusMessage());

      if (casConsumer != null) {
        casConsumer.accept(aCas);
      }

      for (Exception exception : exceptions) {
        LOGGER.error("Exception processing a CAS: ", exception);
      }

      entityCount++;
      String docText = aCas.getDocumentText();
      if (docText != null) {
        size += docText.length();
      }
    }
  });
}
 
Example 17
Source File: CpmCollectionReader_ErrorTest.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
/**
 * setup the CPM with base functionality.
 * 
 * @param documentCount
 *           how many documents should be processed
 * @param exceptionName
 *           the exception to be thrown
 * @param exceptionSequence
 *           the iteration rate of the exceptions
 * @param functionName
 *           the name of the function/method that throws the exception
 * 
 * @return CollectionProcessingEngine - initialized cpe
 */
private CollectionProcessingEngine setupCpm(int documentCount,
      String exceptionName, int exceptionSequence, String functionName) {
   CpeDescription cpeDesc = null;
   CollectionProcessingEngine cpe = null;

   try {
      String colReaderBase = JUnitExtension.getFile(
            "CpmTests" + FS + "ErrorTestCollectionReader.xml")
            .getAbsolutePath();
      String taeBase = JUnitExtension.getFile(
            "CpmTests" + FS + "ErrorTestAnnotator.xml").getAbsolutePath();
      String casConsumerBase = JUnitExtension.getFile(
            "CpmTests" + FS + "ErrorTestCasConsumer.xml").getAbsolutePath();

      // first, prepare all descriptors as needed
      String colReaderDesc = DescriptorMakeUtil.makeCollectionReader(
            colReaderBase, true, functionName, exceptionSequence,
            exceptionName, documentCount);
      String taeDesc = DescriptorMakeUtil.makeAnalysisEngine(taeBase);
      String casConsumerDesc = DescriptorMakeUtil
            .makeCasConsumer(casConsumerBase);

      // secondly, create the cpm based on the descriptors
      cpeDesc = CpeDescriptorFactory.produceDescriptor();

      // managing the default behaviour of this client
      CpeIntegratedCasProcessor integratedProcessor = CpeDescriptorFactory
            .produceCasProcessor("ErrorTestAnnotator");
      integratedProcessor.setDescriptor(taeDesc);

      CpeIntegratedCasProcessor casConsumer = CpeDescriptorFactory
            .produceCasProcessor("ErrorTest CasConsumer");
      casConsumer.setDescriptor(casConsumerDesc);

      // - add all descriptors
      cpeDesc.addCollectionReader(colReaderDesc);
      cpeDesc.addCasProcessor(integratedProcessor);
      cpeDesc.addCasProcessor(casConsumer);
      cpeDesc.setInputQueueSize(2);
      cpeDesc.setOutputQueueSize(2);
      cpeDesc.setProcessingUnitThreadCount(1);
      // - Create a new CPE
      cpe = UIMAFramework.produceCollectionProcessingEngine(cpeDesc, null,
            null);
   } catch (Exception e) {
      e.printStackTrace();
   }
   return cpe;
}
 
Example 18
Source File: CasPoolTest.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
/**
 * setup the CPM with base functionality.
 * 
 * @param documentCount
 *          how many documents should be processed
 * @param threadCount
 *          how many threads are used by the cpm
 * 
 * @return CollectionProcessingEngine - initialized cpe
 */
private CollectionProcessingEngine setupCpm(int documentCount, int threadCount) throws Exception {
  CpeDescription cpeDesc = null;
  CollectionProcessingEngine cpe = null;

  try {
    String colReaderBase = JUnitExtension.getFile("CpmTests" + separator
            + "ErrorTestCollectionReader.xml").getAbsolutePath();
    String taeBase = JUnitExtension.getFile("CpmTests" + separator + "ErrorTestAnnotator.xml").getAbsolutePath();
    String casConsumerBase = JUnitExtension.getFile("CpmTests" + separator
            + "ErrorTestCasConsumer.xml").getAbsolutePath();

    // created needed descriptors
    String colReaderDesc = DescriptorMakeUtil.makeCollectionReader(colReaderBase, documentCount);
    String taeDesc = DescriptorMakeUtil.makeAnalysisEngine(taeBase);
    String casConsumerDesc = DescriptorMakeUtil.makeCasConsumer(casConsumerBase);

    // create cpm descriptor
    cpeDesc = CpeDescriptorFactory.produceDescriptor();
    cpeDesc.setInputQueueSize(2);
    cpeDesc.setOutputQueueSize(2);
    cpeDesc.setProcessingUnitThreadCount(threadCount);

    // add tae
    CpeIntegratedCasProcessor integratedProcessor = CpeDescriptorFactory
            .produceCasProcessor("ErrorTestAnnotator");
    integratedProcessor.setDescriptor(taeDesc);
    cpeDesc.addCasProcessor(integratedProcessor);

    // add casConsumer
    CpeIntegratedCasProcessor casConsumer = CpeDescriptorFactory
            .produceCasProcessor("ErrorTest CasConsumer");
    casConsumer.setDescriptor(casConsumerDesc);
    cpeDesc.addCasProcessor(casConsumer);

    // add collectionReader
    cpeDesc.addCollectionReader(colReaderDesc);

    // produce cpe
    cpe = UIMAFramework.produceCollectionProcessingEngine(cpeDesc, null, null);
  } catch (Exception e) {
    e.printStackTrace();
  }

  return cpe;
}
 
Example 19
Source File: CpmStopTest.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
/**
 * setup the CPM with base functionality.
 * 
 * @param documentCount
 *          how many documents should be processed
 * @param threadCount
 *          how many threads are used by the cpm
 * 
 * @return CollectionProcessingEngine - initialized cpe
 */
private CollectionProcessingEngine setupCpm(int documentCount, int threadCount,
        boolean useSlowAnnotator) throws Exception {
  CpeDescription cpeDesc = null;
  CollectionProcessingEngine cpe = null;

  String colReaderBase = JUnitExtension.getFile("CpmTests" + separator
          + "ErrorTestCollectionReader.xml").getAbsolutePath();
  String taeBase = JUnitExtension.getFile("CpmTests" + separator + "ErrorTestAnnotator.xml").getAbsolutePath();
  String casConsumerBase = JUnitExtension.getFile("CpmTests" + separator
          + "ErrorTestCasConsumer.xml").getAbsolutePath();

  // created needed descriptors
  String colReaderDesc = DescriptorMakeUtil.makeCollectionReader(colReaderBase, documentCount);
  String taeDesc = DescriptorMakeUtil.makeAnalysisEngine(taeBase);
  String casConsumerDesc = DescriptorMakeUtil.makeCasConsumer(casConsumerBase);

  // create cpm descriptor
  cpeDesc = CpeDescriptorFactory.produceDescriptor();
  cpeDesc.setInputQueueSize(2);
  cpeDesc.setOutputQueueSize(2);
  cpeDesc.setProcessingUnitThreadCount(threadCount);

  // add tae
  CpeIntegratedCasProcessor integratedProcessor = CpeDescriptorFactory
          .produceCasProcessor("ErrorTestAnnotator");
  integratedProcessor.setDescriptor(taeDesc);
  cpeDesc.addCasProcessor(integratedProcessor);

  // add slow annotator if requested
  if (useSlowAnnotator) {
    CpeIntegratedCasProcessor slowProcessor = CpeDescriptorFactory
            .produceCasProcessor("SlowAnnotator");
    slowProcessor.setDescriptor(JUnitExtension.getFile("CpmTests" + separator + "SlowAnnotator.xml").getAbsolutePath());
    cpeDesc.addCasProcessor(slowProcessor);
  }

  // add casConsumer
  CpeIntegratedCasProcessor casConsumer = CpeDescriptorFactory
          .produceCasProcessor("ErrorTest CasConsumer");
  casConsumer.setDescriptor(casConsumerDesc);
  cpeDesc.addCasProcessor(casConsumer);

  // add collectionReader
  cpeDesc.addCollectionReader(colReaderDesc);

  // produce cpe
  cpe = UIMAFramework.produceCollectionProcessingEngine(cpeDesc, null, null);

  return cpe;
}
 
Example 20
Source File: CpmProcessingTest.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
/**
 * setup the CPM with base functionality.
 * 
 * @param documentCount
 *          how many documents should be processed
 * @param threadCount
 *          how many threads are used by the cpm
 * 
 * @return CollectionProcessingEngine - initialized cpe
 */
private CollectionProcessingEngine setupCpm(int documentCount, int threadCount) throws Exception {
  CpeDescription cpeDesc = null;
  CollectionProcessingEngine cpe = null;

  try {
    String colReaderBase = JUnitExtension.getFile("CpmTests" + separator
            + "ErrorTestCollectionReader.xml").getAbsolutePath();
    String taeBase = JUnitExtension.getFile("CpmTests" + separator + "ErrorTestAnnotator.xml").getAbsolutePath();
    String casConsumerBase = JUnitExtension.getFile("CpmTests" + separator
            + "ErrorTestCasConsumer.xml").getAbsolutePath();

    // created needed descriptors
    String colReaderDesc = DescriptorMakeUtil.makeCollectionReader(colReaderBase, documentCount);
    String taeDesc = DescriptorMakeUtil.makeAnalysisEngine(taeBase);
    String casConsumerDesc = DescriptorMakeUtil.makeCasConsumer(casConsumerBase);

    // create cpm descriptor
    cpeDesc = CpeDescriptorFactory.produceDescriptor();
    cpeDesc.setInputQueueSize(2);
    cpeDesc.setOutputQueueSize(2);
    cpeDesc.setProcessingUnitThreadCount(threadCount);

    // add tae
    CpeIntegratedCasProcessor integratedProcessor = CpeDescriptorFactory
            .produceCasProcessor("ErrorTestAnnotator");
    integratedProcessor.setDescriptor(taeDesc);
    cpeDesc.addCasProcessor(integratedProcessor);

    // add casConsumer
    CpeIntegratedCasProcessor casConsumer = CpeDescriptorFactory
            .produceCasProcessor("ErrorTest CasConsumer");
    casConsumer.setDescriptor(casConsumerDesc);
    cpeDesc.addCasProcessor(casConsumer);

    // add collectionReader
    cpeDesc.addCollectionReader(colReaderDesc);

    // produce cpe
    cpe = UIMAFramework.produceCollectionProcessingEngine(cpeDesc, null, null);
  } catch (Exception e) {
    e.printStackTrace();
  }

  return cpe;
}