Java Code Examples for org.apache.uima.cas.Feature#getName()

The following examples show how to use org.apache.uima.cas.Feature#getName() . 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
public static <T> T getFeature(FeatureStructure aFS, String aFeatureName)
{
    Feature feature = aFS.getType().getFeatureByBaseName(aFeatureName);

    if (feature == null) {
        throw new IllegalArgumentException("Type [" + aFS.getType().getName()
                + "] has no feature called [" + aFeatureName + "]");
    }

    switch (feature.getRange().getName()) {
    case CAS.TYPE_NAME_STRING:
        return (T) aFS.getStringValue(feature);
    case CAS.TYPE_NAME_BOOLEAN:
        return (T) (Boolean) aFS.getBooleanValue(feature);
    case CAS.TYPE_NAME_FLOAT:
        return (T) (Float) aFS.getFloatValue(feature);
    case CAS.TYPE_NAME_INTEGER:
        return (T) (Integer) aFS.getIntValue(feature);
    default:
        throw new IllegalArgumentException("Cannot get value of feature [" + feature.getName()
                + "] with type [" + feature.getRange().getName() + "]");
    }
}
 
Example 2
Source File: FSUtil.java    From uima-uimafit with Apache License 2.0 5 votes vote down vote up
private static void requireSingleValue(Feature aFeature, Object aArray)
{
  if (aArray == null) {
    throw new IllegalArgumentException("Cannot set [" + aFeature.getName() + "] to a null value.");
  }
  
  if (Array.getLength(aArray) != 1) {
    throw new IllegalArgumentException("Feature [" + aFeature.getName()
            + "] requires a single value but got " + asList(aArray));
  }
}
 
Example 3
Source File: FeatureStructureImplC.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/*************************************
 *  Validation checking
 *************************************/
private void _Check_feature_defined_for_this_type(Feature feat) {   
  if (!(((TypeImpl) (feat.getDomain()) ).subsumes(_typeImpl))) {
    /* Feature "{0}" is not defined for type "{1}". */
    throw new CASRuntimeException(CASRuntimeException.INAPPROP_FEAT, feat.getName(), _typeImpl.getName());
  }
}
 
Example 4
Source File: FeatureStructureImplC.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
private void _check_feature_range_is_FeatureStructure(Feature feat, FeatureStructureImplC fs) {
  Type range = feat.getRange();
  if (range.isPrimitive()) {
    throw new CASRuntimeException(CASRuntimeException.INAPPROP_RANGE_NOT_FS,
        feat.getName(), fs.getType().getName(), feat.getRange().getName() );
  }
}
 
Example 5
Source File: FeatureStructureImplC.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
private void featureValueValidation(Feature feat, Object v) {
  TypeImpl range = (TypeImpl)feat.getRange();
  if ((range.isArray() && !isOkArray(range, v)) ||
      (!range.isArray() && (!range.subsumesValue(v)))) {
    throw new CASRuntimeException(CASRuntimeException.INAPPROP_RANGE, feat.getName(), range.getName(), (v == null) ? "null" : v.getClass().getName());
  }
}
 
Example 6
Source File: CASImpl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Check the range is appropriate for this type/feature. Throws
 * LowLevelException if it isn't.
 * 
 * @param domType
 *                domain type
 * @param ranType
 *                range type
 * @param feat
 *                feature
 */
public final void checkTypingConditions(Type domType, Type ranType, Feature feat) {
  TypeImpl domainTi = (TypeImpl) domType;
  FeatureImpl fi = (FeatureImpl) feat;
  checkTypeHasFeature(domainTi, fi);
  if (!((TypeImpl) fi.getRange()).subsumes((TypeImpl) ranType)) {
    throw new LowLevelException(LowLevelException.FEAT_RAN_ERROR,
        fi.getCode(),
        feat.getName(),
        ((TypeImpl) ranType).getCode(),
        ranType.getName());
  }
}
 
Example 7
Source File: FeatureStructureImplC.java    From uima-uimaj with Apache License 2.0 3 votes vote down vote up
/**************************************
 *           S E T T E R S 
 * 4 levels of checking:  
 *   - check feature for validity (fv)
 *     -- this is skipped with feature comes from fs type info (internal calls)
 *   - check for setting something which could corrupt indexes (ci)
 *     -- this is skipped when the caller knows 
 *        --- the FS is not in the index, perhaps because they just created it
 *     -- skipped when the range is not a valid index key   
 *   - check for needing to log (journal) setting  (jrnl)
 *     -- this is skipped when the caller knows 
 *       --- no journalling is enabled or
 *       --- the FS is a new (above-the-line) FS
 *   - check the value is suitable
 *     -- this can be skipped if Java is doing the checking (via the type of the argument)
 *     -- done for string subtypes and Feature References
 *       --- skipped if the caller knows the value is OK (e.g., it is copying an existing FS)
 *       
 *   The jrnl and ic checks require the FeatureImpl. 
 *     For setters using these checks, there are two versions: 
 *       - one with the arg being the FeatureImpl (if it is available at the caller) and
 *       - one with the int offset (common code coverts this to the Feature Impl).
 *   
 * all 4 checks are normally done by the standard API call in the FeatureStructure interface 
 *    setXyzValue(Feature, value)
 *    
 * Besides the standard API call, other setter methods have suffixes and prefixes to the setter name
 *   - prefix is "_" to avoid conflicting with existing other names
 *   - suffixes are: 
 *     -- Nfc:    skip feature validity checking, ( ! fv,   jrnl,   ci )  (int/Feat)
 *     -- NcNj:   implies Nfc,                    ( ! fv, ! jrnl, ! ci )  (int/Feat)
 *     -- NcWj:   implies Nfc,                    ( ! fv,   jrnl, ! ci )  (int)
 *          The is for setters where value checking might be needed (i.e., Java checking isn't sufficient)
 *     -- NcNjNv: implies Nfc, skips all checks
 *     
 *          For JCas setters: convert offset to feature
 **************************************/

private void checkFeatRange(Feature feat, String shortRangeName) {
  if ( ! (feat.getRange().getShortName().equals(shortRangeName))) {
    /*Trying to access value of feature "{0}" as "{1}", but range of feature is "{2}".*/
    throw new CASRuntimeException(CASRuntimeException.INAPPROP_RANGE, feat.getName(), "uima.cas." + shortRangeName, feat.getRange().getName());
  }

}