Java Code Examples for org.apache.uima.cas.CAS#TYPE_NAME_DOUBLE

The following examples show how to use org.apache.uima.cas.CAS#TYPE_NAME_DOUBLE . 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: WebAnnoCasUtil.java    From webanno with Apache License 2.0 6 votes vote down vote up
/**
 * Get the feature value of this {@code Feature} on this annotation
 */
private static Object getFeatureValue(FeatureStructure aFS, Feature aFeature)
{
    switch (aFeature.getRange().getName()) {
    case CAS.TYPE_NAME_STRING:
        return aFS.getFeatureValueAsString(aFeature);
    case CAS.TYPE_NAME_BOOLEAN:
        return aFS.getBooleanValue(aFeature);
    case CAS.TYPE_NAME_FLOAT:
        return aFS.getFloatValue(aFeature);
    case CAS.TYPE_NAME_INTEGER:
        return aFS.getIntValue(aFeature);
    case CAS.TYPE_NAME_BYTE:
        return aFS.getByteValue(aFeature);
    case CAS.TYPE_NAME_DOUBLE:
        return aFS.getDoubleValue(aFeature);
    case CAS.TYPE_NAME_LONG:
        aFS.getLongValue(aFeature);
    case CAS.TYPE_NAME_SHORT:
        aFS.getShortValue(aFeature);
    default:
        return null;
    // return aFS.getFeatureValue(aFeature);
    }
}
 
Example 2
Source File: TypeSystemImpl.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
   * The range type of features may include 
   *   special uima types that are not creatable, such as the primitive ones
   *   like integer, or string, or subtypes of string.
   * Other types are reference types
   */
  boolean classifyAsRefType(String name, TypeImpl superType) {
    switch(name) {
    case CAS.TYPE_NAME_BOOLEAN:
    case CAS.TYPE_NAME_BYTE:
    case CAS.TYPE_NAME_SHORT:
    case CAS.TYPE_NAME_INTEGER:
    case CAS.TYPE_NAME_LONG:
    case CAS.TYPE_NAME_FLOAT:
    case CAS.TYPE_NAME_DOUBLE:
    case CAS.TYPE_NAME_STRING:
//    case CAS.TYPE_NAME_JAVA_OBJECT:
//    case CAS.TYPE_NAME_MAP:
//    case CAS.TYPE_NAME_LIST:
      return false;
    }
    // superType is null for TOP, which is a Ref type
    if (superType != null && superType.getName().equals(CAS.TYPE_NAME_STRING)) { // can't compare to stringType - may not be set yet
      return false;
    }
    return true;
  }
 
Example 3
Source File: NewFeatureUtils.java    From baleen with Apache License 2.0 5 votes vote down vote up
private static CommonArrayFS getCommonArrayFS(JCas jCas, Type componentType, Collection<?> list) {
  CommonArrayFS fs = null;

  switch (componentType.getName()) {
    case CAS.TYPE_NAME_STRING:
      fs = getStringArray(jCas, list);
      break;
    case CAS.TYPE_NAME_INTEGER:
      fs = getIntegerArray(jCas, list);
      break;
    case CAS.TYPE_NAME_FLOAT:
      fs = getFloatArray(jCas, list);
      break;
    case CAS.TYPE_NAME_BOOLEAN:
      fs = getBooleanArray(jCas, list);
      break;
    case CAS.TYPE_NAME_BYTE:
      fs = getByteArray(jCas, list);
      break;
    case CAS.TYPE_NAME_SHORT:
      fs = getShortArray(jCas, list);
      break;
    case CAS.TYPE_NAME_LONG:
      fs = getLongArray(jCas, list);
      break;
    case CAS.TYPE_NAME_DOUBLE:
      fs = getDoubleArray(jCas, list);
      break;
    default:
      break;
  }
  return fs;
}
 
Example 4
Source File: FeatureUtils.java    From baleen with Apache License 2.0 5 votes vote down vote up
/**
 * Convert a UIMA feature to a Java object of the correct type
 *
 * @param f UIMA CAS Feature
 * @param a UIMA CAS Annotation
 * @return Java object, or null if unable to convert
 */
public static Object featureToObject(Feature f, Annotation a) {
  Object ret = null;

  switch (f.getRange().getName()) {
    case CAS.TYPE_NAME_STRING:
      ret = StringToObject.convertStringToObject(a.getStringValue(f));
      break;
    case CAS.TYPE_NAME_INTEGER:
      ret = a.getIntValue(f);
      break;
    case CAS.TYPE_NAME_FLOAT:
      ret = a.getFloatValue(f);
      break;
    case CAS.TYPE_NAME_BOOLEAN:
      ret = a.getBooleanValue(f);
      break;
    case CAS.TYPE_NAME_BYTE:
      ret = a.getByteValue(f);
      break;
    case CAS.TYPE_NAME_SHORT:
      ret = a.getShortValue(f);
      break;
    case CAS.TYPE_NAME_LONG:
      ret = a.getLongValue(f);
      break;
    case CAS.TYPE_NAME_DOUBLE:
      ret = a.getDoubleValue(f);
      break;
    default:
      ret = null;
  }

  return ret;
}
 
Example 5
Source File: AbstractJsonConsumer.java    From baleen with Apache License 2.0 5 votes vote down vote up
/**
 * Write primitive value.
 *
 * @param generator the generator
 * @param annotation the annotation
 * @param feature the feature
 * @throws IOException Signals that an I/O exception has occurred.
 */
private void writePrimitiveValue(
    JsonGenerator generator, FeatureStructure annotation, Feature feature) throws IOException {
  String range = feature.getRange().getName();
  switch (range) {
    case CAS.TYPE_NAME_INTEGER:
      generator.writeNumber(annotation.getIntValue(feature));
      break;
    case CAS.TYPE_NAME_FLOAT:
      generator.writeNumber(annotation.getFloatValue(feature));
      break;
    case CAS.TYPE_NAME_STRING:
      generator.writeString(annotation.getStringValue(feature));
      break;
    case CAS.TYPE_NAME_BOOLEAN:
      generator.writeBoolean(annotation.getBooleanValue(feature));
      break;
    case CAS.TYPE_NAME_BYTE:
      generator.writeNumber(annotation.getByteValue(feature));
      break;
    case CAS.TYPE_NAME_SHORT:
      generator.writeNumber(annotation.getShortValue(feature));
      break;
    case CAS.TYPE_NAME_LONG:
      generator.writeNumber(annotation.getLongValue(feature));
      break;
    case CAS.TYPE_NAME_DOUBLE:
      generator.writeNumber(annotation.getDoubleValue(feature));
      break;
    default:
      getMonitor().warn("Unexpected primitive type: " + range);
      break;
  }
}
 
Example 6
Source File: NewFeatureUtils.java    From baleen with Apache License 2.0 4 votes vote down vote up
/**
 * Set the primitve value for the given feature on the given annotation
 *
 * @param annotation to add the feature
 * @param feature to add
 * @param value to add
 */
public static void setPrimitive(
    final BaleenAnnotation annotation, final Feature feature, final Object value) {

  // Nothing to do
  if (value == null) {
    return;
  }

  // We could do more type conversion here (got double -> want integer)
  // but fail fast is better - this is a common / standard type system after all.

  switch (feature.getRange().getName()) {
    case CAS.TYPE_NAME_STRING:
      annotation.setStringValue(feature, value.toString()); // Can be stored as different type
      break;
    case CAS.TYPE_NAME_INTEGER:
      annotation.setIntValue(feature, ((Number) value).intValue());
      break;
    case CAS.TYPE_NAME_FLOAT:
      annotation.setFloatValue(feature, ((Number) value).floatValue());
      break;
    case CAS.TYPE_NAME_BOOLEAN:
      annotation.setBooleanValue(feature, (boolean) value);
      break;
    case CAS.TYPE_NAME_BYTE:
      annotation.setByteValue(feature, (byte) value);
      break;
    case CAS.TYPE_NAME_SHORT:
      annotation.setShortValue(feature, ((Number) value).shortValue());
      break;
    case CAS.TYPE_NAME_LONG:
      annotation.setLongValue(feature, ((Number) value).longValue());
      break;
    case CAS.TYPE_NAME_DOUBLE:
      annotation.setDoubleValue(feature, ((Number) value).doubleValue());
      break;
    default:
      break;
  }
}
 
Example 7
Source File: WebAnnoCasUtil.java    From webanno with Apache License 2.0 4 votes vote down vote up
public static boolean isNativeUimaType(String aType)
{
    Validate.notNull(aType, "Type must not be null");
    
    switch (aType) {
    case CAS.TYPE_NAME_ANNOTATION:
    case CAS.TYPE_NAME_ANNOTATION_BASE:
    case CAS.TYPE_NAME_ARRAY_BASE:
    case CAS.TYPE_NAME_BOOLEAN:
    case CAS.TYPE_NAME_BOOLEAN_ARRAY:
    case CAS.TYPE_NAME_BYTE:
    case CAS.TYPE_NAME_BYTE_ARRAY:
    case CAS.TYPE_NAME_DOCUMENT_ANNOTATION:
    case CAS.TYPE_NAME_DOUBLE:
    case CAS.TYPE_NAME_DOUBLE_ARRAY:
    case CAS.TYPE_NAME_EMPTY_FLOAT_LIST:
    case CAS.TYPE_NAME_EMPTY_FS_LIST:
    case CAS.TYPE_NAME_EMPTY_INTEGER_LIST:
    case CAS.TYPE_NAME_EMPTY_STRING_LIST:
    case CAS.TYPE_NAME_FLOAT:
    case CAS.TYPE_NAME_FLOAT_ARRAY:
    case CAS.TYPE_NAME_FLOAT_LIST:
    case CAS.TYPE_NAME_FS_ARRAY:
    case CAS.TYPE_NAME_FS_LIST:
    case CAS.TYPE_NAME_INTEGER:
    case CAS.TYPE_NAME_INTEGER_ARRAY:
    case CAS.TYPE_NAME_INTEGER_LIST:
    case CAS.TYPE_NAME_LIST_BASE:
    case CAS.TYPE_NAME_LONG:
    case CAS.TYPE_NAME_LONG_ARRAY:
    case CAS.TYPE_NAME_NON_EMPTY_FLOAT_LIST:
    case CAS.TYPE_NAME_NON_EMPTY_FS_LIST:
    case CAS.TYPE_NAME_NON_EMPTY_INTEGER_LIST:
    case CAS.TYPE_NAME_NON_EMPTY_STRING_LIST:
    case CAS.TYPE_NAME_SHORT:
    case CAS.TYPE_NAME_SHORT_ARRAY:
    case CAS.TYPE_NAME_SOFA:
    case CAS.TYPE_NAME_STRING:
    case CAS.TYPE_NAME_STRING_ARRAY:
    case CAS.TYPE_NAME_STRING_LIST:
    case CAS.TYPE_NAME_TOP:
        return true;
    }
    
    return false;
}