public boolean match()

in DictionaryAnnotator/src/main/java/org/apache/uima/annotator/dict_annot/impl/FeaturePathInfo_impl.java [288:413]


   public boolean match(AnnotationFS annotFS, Condition condition) {
      // handle special case where no featurePath was specified
      if (this.featurePathElementNames.size() == 0) {
         // no featurePath was specified, return the false
         return false;
      } else {
         // we have a feature path that must be evaluated

         // check if further featurePath elements are possible
         boolean noFurtherElementsPossible = false;

         // check condition result
         boolean checkCondidtion = false;

         // set current FS values
         FeatureStructure currentFS = annotFS;
         Type currentType = annotFS.getType();
         int currentFeatureTypeCode = LowLevelCAS.TYPE_CLASS_INVALID;
         // resolve feature path value
         for (int i = 0; i < this.featurePathElementNames.size(); i++) {

            // if we had in the last iteration a primitive feature or a FS that
            // was not set, the feature path is not valid for this annotation.
            if (noFurtherElementsPossible) {
               return false;
            }

            // get the Feature for the current featurePath element. If the
            // featurePath is always valid the featurePath Feature elements are
            // cached, otherwise the feature names must be resolved by name
            Feature feature;
            if (this.featurePathElements == null) {
               // resolve Feature by name
               feature = currentType
                     .getFeatureByBaseName(this.featurePathElementNames.get(i));
            } else {
               // use cached Feature element
               feature = this.featurePathElements.get(i);
            }

            // if feature is null the feature was not defined
            if (feature == null) {
               return false;
            }

            // get feature type and type code
            Type featureType = feature.getRange();
            currentFeatureTypeCode = TypeSystemUtils.classifyType(featureType);

            // switch feature type code
            switch (currentFeatureTypeCode) {
            case LowLevelCAS.TYPE_CLASS_STRING:
               checkCondidtion = checkString(annotFS.getStringValue(feature),
                     condition);
               noFurtherElementsPossible = true;
               break;
            case LowLevelCAS.TYPE_CLASS_INT:
               checkCondidtion = checkInt(annotFS.getIntValue(feature),
                     condition);
               noFurtherElementsPossible = true;
               break;
            case LowLevelCAS.TYPE_CLASS_BOOLEAN:
               checkCondidtion = checkBoolean(annotFS.getBooleanValue(feature),
                     condition);
               noFurtherElementsPossible = true;
               break;
            case LowLevelCAS.TYPE_CLASS_BYTE:
               checkCondidtion = checkByte(annotFS.getByteValue(feature),
                     condition);
               noFurtherElementsPossible = true;
               break;
            case LowLevelCAS.TYPE_CLASS_DOUBLE:
               checkCondidtion = checkDouble(annotFS.getDoubleValue(feature),
                     condition);
               noFurtherElementsPossible = true;
               break;
            case LowLevelCAS.TYPE_CLASS_FLOAT:
               checkCondidtion = checkFloat(annotFS.getFloatValue(feature),
                     condition);
               noFurtherElementsPossible = true;
               break;
            case LowLevelCAS.TYPE_CLASS_LONG:
               checkCondidtion = checkLong(annotFS.getLongValue(feature),
                     condition);
               noFurtherElementsPossible = true;
               break;
            case LowLevelCAS.TYPE_CLASS_INVALID:
               noFurtherElementsPossible = true;
               checkCondidtion = false;
               break;
            case LowLevelCAS.TYPE_CLASS_SHORT:
               checkCondidtion = checkShort(annotFS.getShortValue(feature),
                     condition);
               noFurtherElementsPossible = true;
               break;
            case LowLevelCAS.TYPE_CLASS_FS:
               currentFS = currentFS.getFeatureValue(feature);
               if (currentFS == null) {
                  // FS value not set - feature path cannot return a valid value
                  noFurtherElementsPossible = true;
                  checkCondidtion = false;
               } else {
                  currentType = currentFS.getType();
               }
               break;
            default:
               // create message for unsupported feature path type
               ResourceBundle bundle = ResourceBundle.getBundle(
                     DictionaryAnnotator.MESSAGE_DIGEST, Locale.getDefault(),
                     this.getClass().getClassLoader());
               // retrieve the message from the resource bundle
               String rawMessage = bundle
                     .getString("dictionary_annotator_error_feature_path_element_not_supported");
               MessageFormat messageFormat = new MessageFormat(rawMessage);
               messageFormat.setLocale(Locale.getDefault());
               String message = messageFormat.format(new Object[] {
                     currentType.getName(),
                     this.featurePathElementNames.get(i),
                     this.featurePathString });
               // throw a RuntimeException with the unsupported feature path
               throw new RuntimeException(message);
            }
         }
         return checkCondidtion;
      }
   }