public String getValue()

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


   public String getValue(AnnotationFS annotFS) {
      // handle special case where no featurePath was specified
      // (featurePathString == null)
      if (this.featurePathElementNames.size() == 0) {
         // no featurePath was specified, return the coveredText of the annotFS
         // as matching text
         return annotFS.getCoveredText();
      } else {
         // we have a feature path that must be evaluated

         // featurePathValue
         String featurePathValue = null;
         // check if further featurePath elements are possible
         boolean noFurtherElementsPossible = 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 null;
            }

            // 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 null;
            }

            // 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:
               featurePathValue = currentFS.getStringValue(feature);
               noFurtherElementsPossible = true;
               break;
            case LowLevelCAS.TYPE_CLASS_INT:
               featurePathValue = Integer.toString(currentFS
                     .getIntValue(feature));
               noFurtherElementsPossible = true;
               break;
            case LowLevelCAS.TYPE_CLASS_BOOLEAN:
               featurePathValue = Boolean.toString(currentFS
                     .getBooleanValue(feature));
               noFurtherElementsPossible = true;
               break;
            case LowLevelCAS.TYPE_CLASS_BYTE:
               featurePathValue = Byte
                     .toString(currentFS.getByteValue(feature));
               noFurtherElementsPossible = true;
               break;
            case LowLevelCAS.TYPE_CLASS_DOUBLE:
               featurePathValue = Double.toString(currentFS
                     .getDoubleValue(feature));
               noFurtherElementsPossible = true;
               break;
            case LowLevelCAS.TYPE_CLASS_FLOAT:
               featurePathValue = Float.toString(currentFS
                     .getFloatValue(feature));
               noFurtherElementsPossible = true;
               break;
            case LowLevelCAS.TYPE_CLASS_LONG:
               featurePathValue = Long
                     .toString(currentFS.getLongValue(feature));
               noFurtherElementsPossible = true;
               break;
            case LowLevelCAS.TYPE_CLASS_INVALID:
               featurePathValue = null;
               noFurtherElementsPossible = true;
               break;
            case LowLevelCAS.TYPE_CLASS_SHORT:
               featurePathValue = Short.toString(currentFS
                     .getShortValue(feature));
               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;
                  featurePathValue = null;
               } 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);
            }
         }

         // the featurePath was processed correctly, check the featurePath value
         if (featurePathValue != null) {
            return featurePathValue;
         } else {
            // it seems that the last featurePath element was a FS
            // check now if the FS is of type AnnotationFS
            if (currentFS != null
                  && currentFeatureTypeCode == LowLevelCAS.TYPE_CLASS_FS) {
               if (currentFS instanceof AnnotationFS) {
                  // the last FS was an Annotation, so return the covered Text
                  // of the annotation as featurePath value
                  return ((AnnotationFS) currentFS).getCoveredText();
               }
            }
            return null;
         }
      }
   }