gate.creole.ExecutionException Java Examples

The following examples show how to use gate.creole.ExecutionException. 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: AbstractDocumentProcessor.java    From gateplugin-LearningFramework with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void controllerExecutionStarted(Controller arg0)
        throws ExecutionException {
  controller = arg0;
  seenDocumentsThisDuplicate.set(0);
  // we count up to the number of duplicates we have. The first invocation of this is also
  // responsible for resetting the document counter (it needs to be the first because 
  // at any later time, another duplicate could already have their execute method invoked 
  int tmp = getRemainingDuplicates().getAndIncrement();
  if(tmp==0) {
    LOGGER.debug(this.getName()+": First controllerExecutionStarted invocation, resetting error and doc count in duplicate "+duplicateId);
    setLastError(null);
    getSeenDocuments().set(0);
  } else {
    LOGGER.debug(this.getName()+": controllerExecutionStarted invocation number "+tmp+" in duplicate "+duplicateId);
  }
  // just for checking that our assumption is right that invocation happens
  // in the order the duplicate was originally created in GCP.
  // System.err.println("DEBUG: "+this.getName()+" controllerExecutionStarted, duplicateId="+duplicateId+" remaining="+tmp);
  // Assert.assertEquals(tmp, duplicateId);
  
  controllerStarted(arg0);
}
 
Example #2
Source File: AbstractDocumentProcessor.java    From gateplugin-LearningFramework with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void execute() throws ExecutionException {
  // The document counting happens in this synchronized code block.
  // We could probably also use volatile Integer for the counting.
  synchronized (getSyncObject()) {
    seenDocumentsThisDuplicate.incrementAndGet();
    getSeenDocuments().incrementAndGet();
  }
  // actual processing happens in parallel if there are duplicates
  process(getDocument());
}
 
Example #3
Source File: AbstractDocumentProcessor.java    From gateplugin-LearningFramework with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Handle the controller execution aborted callback.
 * 
 * This does very much the same as the controller execution finished callback
 * but also stores the last Throwable so it can be inspected by the PR.
 * @param arg0 controller invoking the callback
 * @param arg1 throwable representing the error that was encountered
 * @throws ExecutionException can be thrown
 */
@Override
public void controllerExecutionAborted(Controller arg0, Throwable arg1)
        throws ExecutionException {
  // reset the flags for the next time the controller is run
  controller = arg0;
  setLastError(arg1);
  LOGGER.error("Controller ended with error "+arg1.getMessage());
  int tmp = getRemainingDuplicates().decrementAndGet();
  LOGGER.debug("DEBUG "+this.getName()+" controllerExecutionAborted invocation "+tmp+" for duplicate "+duplicateId);
  //System.err.println("DEBUG: "+this.getName()+" controllerExecutionAborted, duplicateId="+duplicateId+" remaining="+tmp);
  // Assert.assertEquals(tmp, duplicateId);    
  controllerFinished(arg0, arg1);
}
 
Example #4
Source File: AbstractDocumentProcessor.java    From gateplugin-LearningFramework with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void controllerExecutionFinished(Controller arg0)
        throws ExecutionException {
  controller = arg0;
  int tmp = getRemainingDuplicates().decrementAndGet();
  LOGGER.debug(this.getName()+": controllerExecutionFinished invocation "+tmp+" for duplicate "+duplicateId);
  // System.err.println("DEBUG: "+this.getName()+" controllerExecutionFinished, duplicateId="+duplicateId+" remaining="+tmp);
  // Assert.assertEquals(tmp, duplicateId);
  
  controllerFinished(arg0, null);
}
 
Example #5
Source File: Benchmark.java    From gate-core with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Executes the given {@link Executable}, logging its runtime under
 * the given benchmark ID (which is propagated to the Executable if it
 * is itself {@link Benchmarkable}).
 * 
 * @param executable the object to execute
 * @param benchmarkID the benchmark ID, which must not contain spaces
 *  as it is already used as a separator in the log, you can use
 * {@link #createBenchmarkId(String, String)} for it. 
 * @param objectInvokingThisCheckPoint the object invoking this method
 *          (typically the caller would pass <code>this</code> here)
 * @param benchmarkingFeatures features to include in the check point
 *          log
 * @throws ExecutionException any exceptions thrown by the underlying
 *           Executable are propagated.
 */
public static void executeWithBenchmarking(Executable executable,
        String benchmarkID, Object objectInvokingThisCheckPoint,
        Map<Object,Object> benchmarkingFeatures) throws ExecutionException {
  if(!benchmarkingEnabled) {
    executable.execute();
  }
  else {
    long startTime = startPoint();
    String savedBenchmarkID = null;
    try {
      if(executable instanceof Benchmarkable) {
        savedBenchmarkID = ((Benchmarkable)executable).getBenchmarkId();
        ((Benchmarkable)executable).setBenchmarkId(benchmarkID);
      }

      executable.execute();
    }
    catch(Exception e) {
      Map<Object,Object> tempFeatures = new HashMap<Object,Object>();
      if(benchmarkingFeatures != null) {
        tempFeatures.putAll(benchmarkingFeatures);
      }
      tempFeatures.put("exceptionThrown", e);
      checkPoint(startTime, benchmarkID, objectInvokingThisCheckPoint,
              tempFeatures);
      if(e instanceof ExecutionException) {
        throw (ExecutionException)e;
      }
      else {
        throw (RuntimeException)e;
      }
    }
    finally {
      if(savedBenchmarkID != null) {
        ((Benchmarkable)executable).setBenchmarkId(savedBenchmarkID);
      }
    }

    // succeeded, so log checkpoint with the original features
    checkPoint(startTime, benchmarkID, objectInvokingThisCheckPoint,
            benchmarkingFeatures);
  }
}
 
Example #6
Source File: TestGenFeaturesAffixes.java    From gateplugin-LearningFramework with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Test
public void testGenSuffixes1() throws ResourceInstantiationException, ExecutionException {
  Document doc = Factory.newDocument("This is a veryveryverylong word");
  AnnotationSet anns = doc.getAnnotations();
  FeatureMap fm;
  fm = gate.Utils.featureMap("string", "This");
  gate.Utils.addAnn(anns, 0L, 4L, "Token", fm);
  fm = gate.Utils.featureMap("string", "is");
  gate.Utils.addAnn(anns, 5L, 7L, "Token", fm);
  fm = gate.Utils.featureMap("string", "a");
  gate.Utils.addAnn(anns, 8L, 9L, "Token", fm);
  fm = gate.Utils.featureMap("string", "veryveryverylong");
  gate.Utils.addAnn(anns, 10L, 26L, "Token", fm);
  fm = gate.Utils.featureMap("string", "word");
  gate.Utils.addAnn(anns, 27L, 31L, "Token", fm);
  LF_GenFeatures_Affixes pr = new LF_GenFeatures_Affixes();
  pr.init();
  gate.Corpus c = Factory.newCorpus("tmp");
  c.add(doc);    
  pr.setGenPrefixes(Boolean.TRUE);
  pr.setGenSuffixes(Boolean.TRUE);
  pr.setInstanceType("Token");
  pr.setMapToUpper(Boolean.FALSE);
  pr.setMappingLanguage("en");
  pr.setMaxPrefixLength(4);
  pr.setMaxSuffixLength(4);
  pr.setMinNonSuffixLength(2);
  pr.setMinNonPrefixLength(2);
  pr.setMinPrefixLength(2);
  pr.setMinSuffixLength(2);
  pr.setPrefixFeatureName("pref");
  pr.setSuffixFeatureName("suf");
  pr.setStringFeature("string");
  SerialAnalyserController ctrl = 
          (SerialAnalyserController) Factory.createResource(
                  "gate.creole.SerialAnalyserController", 
                  Factory.newFeatureMap(), 
                  Factory.newFeatureMap(), "tmp"); 
  ctrl.add(pr);
  ctrl.setCorpus(c);
  ctrl.execute();
  anns = doc.getAnnotations();
  List<Annotation> sortedanns = anns.inDocumentOrder();
  fm = sortedanns.get(0).getFeatures();
  // System.err.println("DEBUG: doc="+doc);
  Assert.assertTrue(fm.containsKey("pref2"));
  Assert.assertTrue(fm.containsKey("suf2"));
  Assert.assertFalse(fm.containsKey("pref1"));
  Assert.assertFalse(fm.containsKey("pref3"));
  Assert.assertFalse(fm.containsKey("suf1"));
  Assert.assertFalse(fm.containsKey("suf3"));
  Assert.assertEquals("Th", fm.get("pref2"));
  Assert.assertEquals("is", fm.get("suf2"));
  fm = sortedanns.get(1).getFeatures();
  Assert.assertFalse(fm.containsKey("pref1"));
  Assert.assertFalse(fm.containsKey("pref2"));
  Assert.assertFalse(fm.containsKey("pref3"));
  Assert.assertFalse(fm.containsKey("suf1"));
  Assert.assertFalse(fm.containsKey("suf2"));
  Assert.assertFalse(fm.containsKey("suf3"));
  fm = sortedanns.get(3).getFeatures();
  Assert.assertFalse(fm.containsKey("pref1"));
  Assert.assertTrue(fm.containsKey("pref2"));
  Assert.assertTrue(fm.containsKey("pref3"));
  Assert.assertTrue(fm.containsKey("pref4"));
  Assert.assertFalse(fm.containsKey("pref5"));
  Assert.assertFalse(fm.containsKey("pref6"));
  Assert.assertFalse(fm.containsKey("suf1"));
  Assert.assertTrue(fm.containsKey("suf2"));
  Assert.assertTrue(fm.containsKey("suf3"));
  Assert.assertTrue(fm.containsKey("suf4"));
  Assert.assertFalse(fm.containsKey("suf5"));
  Assert.assertFalse(fm.containsKey("suf6"));
}
 
Example #7
Source File: Executable.java    From gate-core with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Starts the execution of this executable
 */
public void execute() throws ExecutionException;
 
Example #8
Source File: Controller.java    From gate-core with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * <p>
 * Executes this controller. Different controller implementations will
 * provide different strategies for executing the PRs they contain,
 * e.g. execute the PRs one after the other in sequence, execute them
 * once for each document in a corpus, or in parallel, based on some
 * condition, or in a branching workflow arrangement, etc.
 * </p>
 * 
 * <p>
 * If any of its child PRs implement the
 * {@link gate.creole.ControllerAwarePR} interface, then the controller
 * must ensure that all their relevant methods are called at the
 * correct times. See the documentation for {@link ControllerAwarePR}
 * for details.
 * </p>
 */
@Override
public void execute() throws ExecutionException;