Пример #1
0
 private void release(RevWalk revWalk) {
   try {
     MethodUtils.invokeMethod(revWalk, "release", null); // $NON-NLS-1$
   } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
     try {
       MethodUtils.invokeMethod(revWalk, "close", null); // $NON-NLS-1$
     } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e1) {
       StatusHandler.log(
           new Status(
               IStatus.ERROR,
               ID_PLUGIN,
               "Failed to release revWalk " + revWalk,
               e1)); //$NON-NLS-1$
     }
   }
 }
Пример #2
0
 public void afterPropertiesSet() throws Exception {
   if (usePlaceholderProperties) {
     OrderComparator.sort(loaders);
     for (PropertiesLoaderSupport loader : loaders) {
       PROPERTIES.putAll((Properties) MethodUtils.invokeMethod(loader, "mergeProperties", null));
     }
   }
   PROPERTIES.putAll(mergeProperties());
   // 检查某些关键的配置顶是否存在,不存在就报初始化错误
   String[] keys = this.necessaryConfigs;
   if (keys != null) {
     for (String key : keys) {
       key = StringUtils.trimToEmpty(key);
       if (!PROPERTIES.containsKey(key)) {
         throw new IllegalStateException(
             "Can not find property \"" + key + "\" in configuration file.");
       }
     }
   }
 }
Пример #3
0
  /**
   * Creates a Stem annotation with same begin and end as the AnnotationFS fs, the value is the
   * stemmed value derived by applying the featurepath.
   *
   * @param jcas the JCas
   * @param fs the AnnotationFS where the Stem annotation is created
   * @throws AnalysisEngineProcessException if the {@code stem} method from the snowball stemmer
   *     cannot be invoked.
   */
  private void createStemAnnotation(JCas jcas, AnnotationFS fs)
      throws AnalysisEngineProcessException {
    // Check for blank text, it makes no sense to add a stem then (and raised an exception)
    String value = fp.getValue(fs);
    if (!StringUtils.isBlank(value)) {
      if (lowerCase) {
        // Fixme - should use locale/language defined in CAS.
        value = value.toLowerCase(Locale.US);
      }

      Stem stemAnnot = new Stem(jcas, fs.getBegin(), fs.getEnd());
      SnowballProgram programm = getSnowballProgram(jcas);
      programm.setCurrent(value);

      try {
        // The patched snowball from Lucene has this as a method on SnowballProgram
        // but if we have some other snowball also in the classpath, Java might
        // choose to use the other. So to be safe, we use a reflection here.
        // -- REC, 2011-04-17
        MethodUtils.invokeMethod(programm, "stem", null);
      } catch (Exception e) {
        throw new AnalysisEngineProcessException(e);
      }

      stemAnnot.setValue(programm.getCurrent());
      stemAnnot.addToIndexes(jcas);

      // Try setting the "stem" feature on Tokens.
      Feature feat = fs.getType().getFeatureByBaseName("stem");
      if (feat != null
          && feat.getRange() != null
          && jcas.getTypeSystem().subsumes(feat.getRange(), stemAnnot.getType())) {
        fs.setFeatureValue(feat, stemAnnot);
      }
    }
  }