コード例 #1
0
  @Override
  public void execute() throws ExecutionException {
    Document doc = getDocument();
    AnnotationSet as = doc.getAnnotations(getAnnotationSetName());
    AnnotationSet tocs = as.get(getTokenAnnotationTypeName());

    try {

      for (Annotation t : tocs) {
        String content = Utils.stringFor(doc, t);
        String val = getOrthographyValue(content);
        if (val != null) t.getFeatures().put("orth", val);
      }

    } catch (Exception e) {
      throw new ExecutionException(e);
    }
  }
コード例 #2
0
  /**
   * Method is executed after the init() method has finished its execution. <br>
   *
   * @throws ExecutionException
   */
  public void execute() throws ExecutionException {
    // lets start the progress and initialize the progress counter
    fireProgressChanged(0);

    // If no document provided to process throw an exception
    if (document == null) {
      fireProcessFinished();
      throw new GateRuntimeException("No document to process!");
    }

    // langugage ID feature Name
    if (languageIdFeatureName == null || languageIdFeatureName.trim().length() == 0)
      languageIdFeatureName = "lang";

    /* Default behaviour: classify the text of the whole document and
     * store the result as a document feature.     */
    if ((annotationType == null) || (annotationType.length() == 0)) {
      String docText = document.getContent().toString();
      Classification classification = classifier.classify(docText);
      document.getFeatures().put(languageIdFeatureName, classification.bestCategory());
    }

    /* Optional behaviour: classify the text underlying each annotation
     * and store each results as an annotation feature.     */
    else {
      AnnotationSet annotations = document.getAnnotations(annotationSetName).get(annotationType);

      for (Annotation annotation : annotations) {
        String text = Utils.stringFor(document, annotation);
        Classification classification = classifier.classify(text);
        annotation.getFeatures().put(languageIdFeatureName, classification.bestCategory());
      }
    }

    // process finished, acknowledge user about this.
    fireProcessFinished();
  }