Java Code Examples for org.apache.uima.jcas.tcas.Annotation#getFeatureValue()

The following examples show how to use org.apache.uima.jcas.tcas.Annotation#getFeatureValue() . 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: FeatureUtils.java    From baleen with Apache License 2.0 6 votes vote down vote up
private static Object[] toArray(Feature f, Annotation a) {
  Object[] ret;

  try {
    CommonArrayFS array = (CommonArrayFS) a.getFeatureValue(f);
    ret = new Object[array.size()];
    int index = 0;
    for (String s : array.toStringArray()) {
      ret[index] = StringToObject.convertStringToObject(s);
      index++;
    }

    return ret;
  } catch (ClassCastException cce) {
    LoggerFactory.getLogger(FeatureUtils.class)
        .debug("Couldn't cast feature value to array", cce);
    return new Object[0];
  }
}
 
Example 2
Source File: MongoFieldMapping.java    From bluima with Apache License 2.0 6 votes vote down vote up
static void writeFieldToDb(String range, BasicDBObject o, Annotation a,
        String dbKey, Feature f) {

    if (range.equals("String")) {
        o.put(dbKey, a.getStringValue(f));
    } else if (range.equals("StringArray")) {
        StringArray sa = (StringArray) a.getFeatureValue(f);
        if (sa != null) {
            String[] vals = sa.toArray();
            o.put(dbKey, Lists.newArrayList(vals));
        }
    } else if (range.equals("Integer")) {
        o.put(dbKey, a.getIntValue(f));
    } else if (range.equals("Float")) {
        o.put(dbKey, a.getFloatValue(f));
    } else if (range.equals("Boolean")) {
        o.put(dbKey, a.getBooleanValue(f));
    } else {
        LOG.warn("range not supported " + range);
    }
}
 
Example 3
Source File: FeatureUtils.java    From baleen with Apache License 2.0 5 votes vote down vote up
/**
 * Convert a UIMA feature array to an array of Java objects of the correct type, parsing Strings
 * to objects where possible
 *
 * @param f UIMA CAS Feature
 * @param a UIMA CAS Annotation
 * @return Array of Java objects, or null if unable to convert
 */
public static Object[] featureToArray(Feature f, Annotation a) {
  Object[] ret;

  if (a.getFeatureValue(f) == null) {
    ret = new Object[0];
  } else {
    ret = toArray(f, a);
  }

  return ret;
}
 
Example 4
Source File: FeatureUtils.java    From baleen with Apache License 2.0 3 votes vote down vote up
/**
 * Convert a UIMA feature array to a List of Java objects of the correct type, parsing Strings to
 * objects where possible
 *
 * @param f UIMA CAS Feature
 * @param a UIMA CAS Annotation
 * @return List of Java objects, or empty if unable to convert
 */
public static List<Object> featureToList(Feature f, Annotation a) {
  if (a.getFeatureValue(f) == null) {
    return Collections.emptyList();
  }

  return Arrays.asList(toArray(f, a));
}