Java Code Examples for org.apache.uima.cas.impl.TypeImpl#getFeatureImpls()

The following examples show how to use org.apache.uima.cas.impl.TypeImpl#getFeatureImpls() . 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: JsonCasSerializer.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * _feature_types : { "featName" : "_ref" or "_byte_array, ... }
 * 
 * @param type the type for which to generate the feature context info 
 * @throws IOException 
 */
private void addJsonFeatContext(TypeImpl type) throws IOException {
  final FeatureImpl[] feats = type.getFeatureImpls();
  startedFeatureTypes = false;
   
  for (FeatureImpl feat : feats) {
    final int fsClass = CasSerializerSupport.classifyType(feat.getRangeImpl());
    SerializedString featKind = featureTypeLabel(fsClass);
    if (null != featKind) {
      maybeDoStartFeatureTypes();
      jg.writeFieldName(getSerializedString(feat.getShortName())); 
      jg.writeString(featKind);
    }  
  }
  if (startedFeatureTypes) {
    jg.writeEndObject();
  } 
}
 
Example 2
Source File: JsonCasSerializer.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
private void writeFsOrLists(TOP fs, TypeImpl ti, boolean isListAsFSs) throws IOException {
      final FeatureImpl[] feats = ti.getFeatureImpls();
      
//      maybeWriteIdFeat(addr);
      maybeWriteTypeFeat(ti);
      
      for (final FeatureImpl feat : feats) {

        if (cds.isFiltering) {
          // skip features that aren't in the target type system
          String fullFeatName = feat.getName();
          if (cds.filterTypeSystem_inner.getFeatureByFullName(fullFeatName) == null) {
            continue;
          }
        }
        
//        final int featAddr = addr + cds.cas.getAdjustedFeatureOffset(featCode);
//        final int featValRaw = cds.cas.getHeapValue(featAddr);
        final int featureClass = CasSerializerSupport.classifyType(feat.getRangeImpl());
        final SerializedString shortName = getSerializedString(feat.getShortName());
                
        switch (featureClass) {
        
        case LowLevelCAS.TYPE_CLASS_BYTE:  writeNumeric(feat, fs._getByteValueNc (feat)); break;
        case LowLevelCAS.TYPE_CLASS_SHORT: writeNumeric(feat, fs._getShortValueNc(feat)); break; 
        case LowLevelCAS.TYPE_CLASS_INT:   writeNumeric(feat, fs._getIntValueNc  (feat)); break;  
        case LowLevelCAS.TYPE_CLASS_LONG:  writeNumeric(feat, fs._getLongValueNc (feat)); break;  

        case LowLevelCAS.TYPE_CLASS_FS: {
          TOP ref = fs._getFeatureValueNc(feat);
          if (ref == null /* && isOmitDefaultValues*/) continue;
          writeFsOrRef(ref, feat); // writes nl before embedded fs
          break;
        }
          
        case LowLevelCAS.TYPE_CLASS_FLOAT:
          final float floatVal = fs._getFloatValueNc(feat);
          if (floatVal == 0.F && isOmitDefaultValues) continue;
          jg.writeFieldName(shortName);
          jg.writeNumber(floatVal);
          break;
          
        case LowLevelCAS.TYPE_CLASS_DOUBLE:
          final double doubleVal = fs._getDoubleValueNc(feat);
          if (doubleVal == 0L && isOmitDefaultValues) continue;
          jg.writeFieldName(shortName);
          jg.writeNumber(doubleVal);
          break;
          
        case LowLevelCAS.TYPE_CLASS_BOOLEAN:
          jg.writeFieldName(shortName);
          jg.writeBoolean(fs._getBooleanValueNc(feat));           
          break; 
        
        case LowLevelCAS.TYPE_CLASS_STRING: {
          String s = fs._getStringValueNc(feat);
          if (s == null /*&& isOmitDefaultValues*/) continue; 
          jg.writeFieldName(shortName);
          jg.writeString(s);
          break; 
        }
        
        case LowLevelCAS.TYPE_CLASS_INTARRAY: 
        case LowLevelCAS.TYPE_CLASS_FLOATARRAY:
        case LowLevelCAS.TYPE_CLASS_BOOLEANARRAY:
        case LowLevelCAS.TYPE_CLASS_BYTEARRAY:
        case LowLevelCAS.TYPE_CLASS_SHORTARRAY:
        case LowLevelCAS.TYPE_CLASS_LONGARRAY:
        case LowLevelCAS.TYPE_CLASS_DOUBLEARRAY:
        case LowLevelCAS.TYPE_CLASS_STRINGARRAY:
        case LowLevelCAS.TYPE_CLASS_FSARRAY: 
          writeArray(fs, feat, featureClass);
          break;
          
        case CasSerializerSupport.TYPE_CLASS_INTLIST:
        case CasSerializerSupport.TYPE_CLASS_FLOATLIST:
        case CasSerializerSupport.TYPE_CLASS_STRINGLIST:
        case CasSerializerSupport.TYPE_CLASS_FSLIST:
          writeList(fs, feat, featureClass, isListAsFSs);
          break;        
        default: Misc.internalError(); 
        }  // end of switch
      } // end of loop over all features
    }