Java Code Examples for org.apache.uima.cas.Type#getFeatures()

The following examples show how to use org.apache.uima.cas.Type#getFeatures() . 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: Tsv3XCasSchemaAnalyzer.java    From webanno with Apache License 2.0 6 votes vote down vote up
public static boolean isRelationLayer(Type aType)
{
    Feature relSourceFeat = aType.getFeatureByBaseName(FEAT_REL_SOURCE);
    boolean hasSourceFeature = relSourceFeat != null && !isPrimitiveFeature(relSourceFeat);
    Feature relTargetFeat = aType.getFeatureByBaseName(FEAT_REL_TARGET);
    boolean hasTargetFeature = relTargetFeat != null && !isPrimitiveFeature(relTargetFeat);
    
    boolean compatible = true;
    for (Feature feat : aType.getFeatures()) {
        if (
                CAS.FEATURE_BASE_NAME_SOFA.equals(feat.getShortName()) ||
                FEAT_REL_SOURCE.equals(feat.getShortName()) || 
                FEAT_REL_TARGET.equals(feat.getShortName())
        ) {
            continue;
        }
        
        if (!isPrimitiveFeature(feat)) {
            compatible = false;
            //LOG.debug("Incompatible feature in type [" + aType + "]: " + feat);
            break;
        }
    }
    
    return hasSourceFeature && hasTargetFeature && compatible;
}
 
Example 2
Source File: Tsv3XCasSchemaAnalyzer.java    From webanno with Apache License 2.0 6 votes vote down vote up
public static boolean isSpanLayer(Type aType)
{
    boolean compatible = true;
    for (Feature feat : aType.getFeatures()) {
        if (CAS.FEATURE_BASE_NAME_SOFA.equals(feat.getShortName())) {
            continue;
        }
        
        if (!(isPrimitiveFeature(feat) || isSlotFeature(feat))) {
            compatible = false;
            //LOG.debug("Incompatible feature in type [" + aType + "]: " + feat);
            break;
        }

    }
    
    return compatible;
}
 
Example 3
Source File: AnnotationFeaturesViewer.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the feature names for type.
 *
 * @param aTypeName the a type name
 * @param cas the cas
 * @return the feature names for type
 */
// untimely ripped from UIMA since it does not work with a taeDescription
private String[] getFeatureNamesForType(String aTypeName, CAS cas) {
  TypeSystem ts = cas.getTypeSystem();
  Type t = ts.getType(aTypeName);
  if (t != null) {
    List features = t.getFeatures();
    String[] featNames = new String[features.size()];
    for (int i = 0; i < features.size(); i++) {
      Feature f = (Feature) features.get(i);
      featNames[i] = f.getShortName();
    }
    return featNames;
  } else {
    return null;
  }
}
 
Example 4
Source File: AddIndexKeyDialog.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the sortable feature names.
 *
 * @param selectedTypeName the selected type name
 * @return an array of features whose range is primitive
 */
private String[] getSortableFeatureNames(String selectedTypeName) {
  Type selectedType = section.editor.getCurrentView().getTypeSystem().getType(selectedTypeName);
  List feats = selectedType.getFeatures();
  Collection sortableFeatureNames = new ArrayList();

  for (int i = 0; i < feats.size(); i++) {
    Feature feature = (Feature) feats.get(i);
    Type rangeType = feature.getRange();
    if (AbstractSection.isIndexableRange(rangeType.getName())) {
      if (!alreadyUsedKeys.contains(feature.getShortName()))
        sortableFeatureNames.add(feature.getShortName());
    }
  }
  String[] result = (String[]) sortableFeatureNames.toArray(stringArray0);
  Arrays.sort(result);
  return result;
}
 
Example 5
Source File: ConstraintsVerifier.java    From webanno with Apache License 2.0 6 votes vote down vote up
@Override
public boolean verify(FeatureStructure featureStructure, ParsedConstraints parsedConstraints)
{

    boolean isOk = false;
    Type type = featureStructure.getType();
    for (Feature feature : type.getFeatures()) {
        if (feature.getRange().isPrimitive()) {
            String scopeName = featureStructure.getFeatureValueAsString(feature);
            List<Rule> rules = parsedConstraints.getScopeByName(scopeName).getRules();

            // Check if all the feature values are ok according to the
            // rules;
        }
        else {
            // Here some recursion would be in order
        }
    }
    return isOk;
}
 
Example 6
Source File: AbstractJsonConsumer.java    From baleen with Apache License 2.0 6 votes vote down vote up
/**
 * Write an annotation to the file.
 *
 * @param generator the generator
 * @param annotation the annotation
 * @throws IOException Signals that an I/O exception has occurred.
 */
private void writeFS(JsonGenerator generator, FeatureStructure annotation) throws IOException {
  generator.writeStartObject();

  Type type = annotation.getType();
  generator.writeStringField("type", type.getName());

  List<Feature> features = type.getFeatures();
  if (annotation instanceof AnnotationFS) {
    AnnotationFS annotationFS = (AnnotationFS) annotation;
    if (!(annotationFS.getEnd() == 0 && annotationFS.getBegin() == 0)) {
      generator.writeStringField("coveredText", annotationFS.getCoveredText());
    }
  }

  if (!features.isEmpty()) {
    writeFS(generator, annotation, features);
  }
  generator.writeEndObject();
}
 
Example 7
Source File: AutomationUtil.java    From webanno with Apache License 2.0 5 votes vote down vote up
private static boolean isSamAnno(Type aType, AnnotationFS aMFs, AnnotationFS aFs)
{
    for (Feature f : aType.getFeatures()) {
        // anywhere is ok
        if (f.getName().equals(CAS.FEATURE_FULL_NAME_BEGIN)) {
            continue;
        }
        // anywhere is ok
        if (f.getName().equals(CAS.FEATURE_FULL_NAME_END)) {
            continue;
        }
        if (!f.getRange().isPrimitive() && aMFs.getFeatureValue(f) instanceof SofaFS) {
            continue;
        }
        // do not attach relation on empty span annotations
        if (aMFs.getFeatureValueAsString(f) == null) {
            continue;
        }
        if (aFs.getFeatureValueAsString(f) == null) {
            continue;
        }
        if (!aMFs.getFeatureValueAsString(f).equals(aFs.getFeatureValueAsString(f))) {
            return false;
        }
    }
    return true;
}
 
Example 8
Source File: RsType.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * returns the Features for a type in a result spec 
 * @param ts The type system, may be null
 * @return list of features for a type in a result spec
 */
List<Feature> getAllAppropriateFeatures(final TypeSystem ts) {
  if (null == ts) {
    return EMPTY_FEATURE_LIST;
  }
  Type t = ts.getType(typeName);
  return (null == t) ? EMPTY_FEATURE_LIST : t.getFeatures();
}
 
Example 9
Source File: TypeSystemUtil.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Convert a {@link Type} to an equivalent {@link TypeDescription}.
 * 
 * @param aType
 *          type object to convert
 * @param aTypeSystem
 *          the TypeSystem that contains <code>aType</code>
 * @return a TypeDescription that is equivalent to <code>aType</code>
 */
public static TypeDescription type2TypeDescription(Type aType, TypeSystem aTypeSystem) {
  TypeDescription typeDesc = UIMAFramework.getResourceSpecifierFactory().createTypeDescription();
  typeDesc.setName(aType.getName());
  Type superType = aTypeSystem.getParent(aType);
  typeDesc.setSupertypeName(superType.getName());
  // special handling for string subtypes (which have "allowed values", rather than features)
  Type stringType = aTypeSystem.getType("uima.cas.String");
  if (aTypeSystem.subsumes(stringType, aType)) {
    String[] allowedValues = getAllowedValuesForType(aType, aTypeSystem);
    AllowedValue[] avObjs = new AllowedValue[allowedValues.length];
    for (int i = 0; i < allowedValues.length; i++) {
      AllowedValue av = UIMAFramework.getResourceSpecifierFactory().createAllowedValue();
      av.setString(allowedValues[i]);
      avObjs[i] = av;
    }
    typeDesc.setAllowedValues(avObjs);
  } else {
    List<FeatureDescription> featDescs = new ArrayList<>();
    for (Feature feat : aType.getFeatures()){ 
      if (!superType.getFeatures().contains(feat)) {
        featDescs.add(feature2FeatureDescription(feat));
      }
    }
    FeatureDescription[] featDescArr = new FeatureDescription[featDescs.size()];
    featDescs.toArray(featDescArr);
    typeDesc.setFeatures(featDescArr);
  }
  return typeDesc;
}
 
Example 10
Source File: TypeSystemImpl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
public Vector<Feature> getIntroFeatures(Type type) {
  Vector<Feature> feats = new Vector<>();
  List<Feature> appropFeats = type.getFeatures();
  final int max = appropFeats.size();
  Feature feat;
  for (int i = 0; i < max; i++) {
    feat = appropFeats.get(i);
    if (feat.getDomain() == type) {
      feats.add(feat);
    }
  }
  return feats;
}
 
Example 11
Source File: FeatureStructureContentProvider.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
@Override
public Object[] getElements(Object inputElement) {

  if (inputElement != null) {

    FeatureStructure featureStructure = (FeatureStructure) inputElement;

    Type type = featureStructure.getType();

    if (!type.isArray()) {

      Collection<FeatureValue> featureValues = new LinkedList<>();

      for (Feature feature : type.getFeatures()) {
        featureValues.add(new FeatureValue(mDocument, featureStructure, feature));
      }

      return featureValues.toArray();
    }
    else {
      int size = arraySize(featureStructure);

      ArrayValue arrayValues[] = new ArrayValue[size];

      for (int i = 0; i < size; i++) {
        arrayValues[i] = new ArrayValue(featureStructure, i);
      }

      return arrayValues;
    }

  } else {
    return new Object[0];
  }
}
 
Example 12
Source File: Tsv3XCasSchemaAnalyzer.java    From webanno with Apache License 2.0 5 votes vote down vote up
public static boolean isChainLayer(Type aType)
{
    boolean hasTypeFeature = aType.getFeatureByBaseName(COREFERENCE_TYPE_FEATURE) != null;
    boolean hasRelationFeature = aType
            .getFeatureByBaseName(COREFERENCE_RELATION_FEATURE) != null;
    boolean nameEndsInLink = aType.getName().endsWith("Link");

    boolean compatible = true;
    for (Feature feat : aType.getFeatures()) {
        if (
                CAS.FEATURE_BASE_NAME_SOFA.equals(feat.getShortName()) ||
                CHAIN_NEXT_FEAT.equals(feat.getShortName()) || 
                COREFERENCE_TYPE_FEATURE.equals(feat.getShortName()) || 
                COREFERENCE_RELATION_FEATURE.equals(feat.getShortName())
        ) {
            continue;
        }
        
        if (!isPrimitiveFeature(feat)) {
            compatible = false;
            LOG.debug("Incompatible feature in type [" + aType + "]: " + feat);
            break;
        }
    }

    return hasTypeFeature && hasRelationFeature && nameEndsInLink && compatible;
}
 
Example 13
Source File: Tsv3XCasSchemaAnalyzer.java    From webanno with Apache License 2.0 5 votes vote down vote up
private static void generateColumns(TypeSystem aTypeSystem, TsvSchema aSchema,
        LayerType aLayerType, Type aType)
{
    List<String> specialFeatures = asList(
            CAS.FEATURE_FULL_NAME_BEGIN,
            CAS.FEATURE_FULL_NAME_END,
            CAS.FEATURE_FULL_NAME_SOFA);
    
    for (Feature feat : aType.getFeatures()) {
        if (specialFeatures.contains(feat.getName())) {
            continue;
        }

        if (isPrimitiveFeature(feat)) {
            aSchema.addColumn(new TsvColumn(aType, aLayerType, feat, FeatureType.PRIMITIVE));
        }
        else if (SPAN.equals(aLayerType) && isSlotFeature(aTypeSystem, feat)) {
            aSchema.addColumn(new TsvColumn(aType, aLayerType, feat, FeatureType.SLOT_ROLE));
            Type slotTargetType = feat.getRange().getComponentType()
                    .getFeatureByBaseName(FEAT_SLOT_TARGET).getRange();
            TsvColumn targetColumn = new TsvColumn(aType, aLayerType, feat,
                    FeatureType.SLOT_TARGET);
            targetColumn.setTargetTypeHint(slotTargetType);
            aSchema.addColumn(targetColumn);
        }
    }
}
 
Example 14
Source File: MongoCollectionReader.java    From bluima with Apache License 2.0 4 votes vote down vote up
@Override
public void getNext(JCas jCas) throws IOException, CollectionException {

    // text & id
    DBObject doc = cur.next();
    Object text = doc.get(TEXT);
    if (text != null)
        jCas.setDocumentText(doc.get(TEXT).toString());
    else
        jCas.setDocumentText("");
    Header h = new Header(jCas);
    h.setDocId(doc.get(ID).toString());
    if (doc.containsField(TITLE) && doc.get(TITLE) != null)
        h.setTitle(doc.get(TITLE).toString());
    else
        h.setTitle("");
    h.addToIndexes();

    // all other annotations, from mappings
    for (String dbListsName : doc.keySet()) {

        for (String annotClass : ALL_MAPPINGS_KEYS) {
            MongoFieldMapping fm = ALL_MAPPINGS.get(annotClass);

            if (fm.shortName.equals(dbListsName)) {

                BasicDBList dbList = (BasicDBList) doc.get(dbListsName);
                for (Object o : dbList) {
                    BasicDBObject dbO = (BasicDBObject) o;

                    try {
                        Annotation a = getAnnotationByClassName(jCas,
                                annotClass);
                        a.setBegin(dbO.getInt(BEGIN));// LATER maybe opt.
                        a.setEnd(dbO.getInt(END));

                        Type t = a.getType();
                        for (Feature f : t.getFeatures()) {
                            // System.err.println("f.short "
                            // + f.getShortName());

                            if (fm.fieldMappings.containsKey(f
                                    .getShortName())) {

                                String fieldKey = fm.fieldMappings.get(f
                                        .getShortName());
                                String range = f.getRange().getShortName();

                                MongoFieldMapping.readFieldFromDb(fieldKey,
                                        range, a, f, dbO, jCas);
                            }
                        }
                        a.addToIndexes();

                    } catch (Exception e) {
                        LOG.error("while processing docId " + doc.get(ID),
                                e);
                    }
                }
            }
        }
    }
}
 
Example 15
Source File: WebannoTsv3Writer.java    From webanno with Apache License 2.0 4 votes vote down vote up
private void setRelationAnnoPerFeature(
        Map<AnnotationUnit, List<List<String>>> annotationsPertype, Type type, AnnotationFS fs,
        AnnotationUnit depUnit, AnnotationUnit govUnit, int aGovRef, int aDepRef, Type aDepType)
{
    List<String> annoPerFeatures = new ArrayList<>();
    featurePerLayer.putIfAbsent(type.getName(), new LinkedHashSet<>());
    List<Feature> features = type.getFeatures();
    Collections.sort(features, (a, b) -> 
            StringUtils.compare(a.getShortName(), b.getShortName()));
    for (Feature feature : features) {
        if (feature.getName().equals(CAS.FEATURE_FULL_NAME_SOFA)
                || feature.getName().equals(CAS.FEATURE_FULL_NAME_BEGIN)
                || feature.getName().equals(CAS.FEATURE_FULL_NAME_END)
                || feature.getShortName().equals(GOVERNOR)
                || feature.getShortName().equals(DEPENDENT)
                || feature.getShortName().equals(FIRST)
                || feature.getShortName().equals(NEXT)) {
            continue;
        }
        int ref = getRefId(type, fs, depUnit);
        String annotation = fs.getFeatureValueAsString(feature);
        if (annotation == null) {
            annotation = "*";
        }
        else {
            annotation = replaceEscapeChars(annotation);
        }
        annoPerFeatures.add(annotation);// +(ref > 0 ? "[" + ref + "]" : ""));
        featurePerLayer.get(type.getName()).add(feature.getShortName());
    }
    // add the governor and dependent unit addresses (separated by _
    String govRef = unitsLineNumber.get(govUnit)
            + ((aDepRef > 0 || aGovRef > 0) ? "[" + aGovRef + "_" + aDepRef + "]" : "");
    annoPerFeatures.add(govRef);
    featurePerLayer.get(type.getName()).add(BT + aDepType.getName());
    // the column for the dependent unit address
    annotationsPertype.putIfAbsent(depUnit, new ArrayList<>());
    if (annoPerFeatures.size() == 0) {
        annoPerFeatures.add("*");
    }
    annotationsPertype.get(depUnit).add(annoPerFeatures);
}
 
Example 16
Source File: WebannoTsv3Writer.java    From webanno with Apache License 2.0 4 votes vote down vote up
private void setChainAnnoPerFeature(Map<AnnotationUnit, List<List<String>>> aAnnotationsPertype,
        Type aType, AnnotationFS aFs, AnnotationUnit aUnit, int aLinkNo, int achainNo,
        boolean aMultiUnit, boolean aFirst)
{
    List<String> annoPerFeatures = new ArrayList<>();
    List<Feature> features = aType.getFeatures();
    Collections.sort(features, (a, b) -> 
            StringUtils.compare(a.getShortName(), b.getShortName()));
    for (Feature feature : features) {
        if (feature.getName().equals(CAS.FEATURE_FULL_NAME_SOFA)
                || feature.getName().equals(CAS.FEATURE_FULL_NAME_BEGIN)
                || feature.getName().equals(CAS.FEATURE_FULL_NAME_END)
                || feature.getShortName().equals(GOVERNOR)
                || feature.getShortName().equals(DEPENDENT)
                || feature.getShortName().equals(FIRST)
                || feature.getShortName().equals(NEXT)) {
            continue;
        }
        String annotation = aFs.getFeatureValueAsString(feature);

        if (annotation == null) {
            annotation = "*";
        }
        else {
            annotation = replaceEscapeChars(annotation);
        }

        if (feature.getShortName().equals(REF_REL)) {
            annotation = annotation + "->" + achainNo + "-" + aLinkNo;
        }
        else if (aMultiUnit) {
            annotation = annotation + "[" + achainNo + "]";
        }
        else {
            annotation = annotation + "[" + achainNo + "]";
        }
        featurePerLayer.get(aType.getName()).add(feature.getShortName());

        annoPerFeatures.add(annotation);
    }
    aAnnotationsPertype.putIfAbsent(aUnit, new ArrayList<>());
    ambigUnits.putIfAbsent(aType.getName(), new HashMap<>());
    ambigUnits.get(aType.getName()).put(aUnit, true); // coref are always ambig

    if (annoPerFeatures.size() == 0) {
        annoPerFeatures.add("*" + "[" + achainNo + "]");
    }
    aAnnotationsPertype.get(aUnit).add(annoPerFeatures);
}
 
Example 17
Source File: CasAnnotationViewer.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
/**
 * Check if an annotation matches the filters set by the user. If true, the
 * annotation will be added to the annotation tree display panel.
 *
 * @param annotation the annotation
 * @return true, if is match
 */
private boolean isMatch(Annotation annotation) {
  Type type = annotation.getType();
  switch (this.viewMode) {
    case MODE_ANNOTATIONS:
      if (this.typeToCheckBoxMap.size() == 0) {
        return false;
      }
      JCheckBox typeCheckBox = this.typeToCheckBoxMap.get(type);
      return typeCheckBox != null && typeCheckBox.isSelected();
    case MODE_ENTITIES:
      if (this.entityToCheckBoxMap.size() == 0) {
        return false;
      }
      Entity entity = this.entityResolver.getEntity(annotation);
      if (entity == null) {
        return false;
      }
      JCheckBox entityCheckBox = this.entityToCheckBoxMap.get(entity);
      return entityCheckBox != null && entityCheckBox.isSelected();
    case MODE_FEATURES:
      JRadioButton typeRadioButton = this.typeRadioButtonMap.get(type);
      if (typeRadioButton == null || !typeRadioButton.isSelected()) {
        return false;
      }
      List<Feature> features = type.getFeatures();
      if (features == null || features.size() == 0) {
        return false;
      }
      for (Feature feature : features) {
        String featureName = feature.getShortName();
        if (featureName == null || featureName.length() == 0) {
          continue;
        }
        JRadioButton featureRadioButton = this.featureRadioButtonMap.get(featureName);
        if (featureRadioButton == null || !featureRadioButton.isSelected()) {
          continue;
        }
        String featureValue = this.getFeatureValueInString(annotation, feature);
        if (featureValue == null || featureValue.length() == 0) {
          continue;
        }
        JCheckBox featureValueCheckBox = this.featureValueCheckBoxMap.get(featureValue);
        return featureValueCheckBox != null && featureValueCheckBox.isSelected();
      }
      break;
    default:
      break;
  }
  return false;
}
 
Example 18
Source File: WebannoTsv3Writer.java    From webanno with Apache License 2.0 4 votes vote down vote up
private void setRelationAnnotation(JCas aJCas)
{
    for (String l : relationLayers) {
        if (l.equals(Token.class.getName())) {
            continue;
        }
        Map<AnnotationUnit, List<List<String>>> annotationsPertype;
        if (annotationsPerPostion.get(l) == null) {
            annotationsPertype = new HashMap<>();

        }
        else {
            annotationsPertype = annotationsPerPostion.get(l);
        }
        Type type = getType(aJCas.getCas(), l);
        Feature dependentFeature = null;
        Feature governorFeature = null;

        List<Feature> features = type.getFeatures();
        Collections.sort(features, (a, b) -> 
                StringUtils.compare(a.getShortName(), b.getShortName()));
        for (Feature feature : features) {
            if (feature.getShortName().equals(DEPENDENT)) {

                // check if the dependent is
                dependentFeature = feature;
            }
            if (feature.getShortName().equals(GOVERNOR)) {
                governorFeature = feature;
            }
        }
        for (AnnotationFS fs : CasUtil.select(aJCas.getCas(), type)) {
            AnnotationFS depFs = (AnnotationFS) fs.getFeatureValue(dependentFeature);
            AnnotationFS govFs = (AnnotationFS) fs.getFeatureValue(governorFeature);

            Type govType = govFs.getType();

            AnnotationUnit govUnit = getFirstUnit(
                    getUnit(govFs.getBegin(), govFs.getEnd(), govFs.getCoveredText()));
            if (ambigUnits.get(govType.getName()).get(govUnit) == null) {
                govUnit = getUnit(govFs.getBegin(), govFs.getEnd(), govFs.getCoveredText());
            }

            AnnotationUnit depUnit = getFirstUnit(
                    getUnit(depFs.getBegin(), depFs.getEnd(), depFs.getCoveredText()));
            if (ambigUnits.get(govType.getName()).get(depUnit) == null) {
                depUnit = getUnit(depFs.getBegin(), depFs.getEnd(), depFs.getCoveredText());
            }
            // Since de.tudarmstadt.ukp.dkpro.core.api.syntax.type.dependency.Dependency is over
            // Over POS anno which itself attached to Token, we need the POS type here

            if (type.getName().equals(Dependency.class.getName())) {
                govType = aJCas.getCas().getTypeSystem().getType(POS.class.getName());
            }

            int govRef = 0;
            int depRef = 0;

            // For that unit test case only, where annotations are on Tokens.
            // The WebAnno world do not ever process Token as an annotation
            if (!govType.getName().equals(Token.class.getName())
                    && ambigUnits.get(govType.getName()).get(govUnit).equals(true)) {
                govRef = annotaionRefPerType.get(govType).get(govFs);
            }

            if (!govType.getName().equals(Token.class.getName())
                    && ambigUnits.get(govType.getName()).get(depUnit).equals(true)) {
                depRef = annotaionRefPerType.get(govType).get(depFs);
            }

            setRelationAnnoPerFeature(annotationsPertype, type, fs, depUnit, govUnit, govRef,
                    depRef, govType);

        }
        if (annotationsPertype.keySet().size() > 0) {
            annotationsPerPostion.put(l, annotationsPertype);
        }
    }
}
 
Example 19
Source File: DebugFSLogicalStructure.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
public static Object getDebugLogicalStructure_FeatureStructure(FeatureStructure fs) {

    if (fs instanceof StringArrayFS) {
      return ((StringArrayFS) fs).toArray();
    }
    if (fs instanceof FloatArrayFS) {
      return ((FloatArrayFS) fs).toArray();
    }
    if (fs instanceof IntArrayFS) {
      return ((IntArrayFS) fs).toArray();
    }
    if (fs instanceof ArrayFS) {
      return ((ArrayFS) fs).toArray();
    }
    CASImpl cas = (CASImpl) fs.getCAS();
    TypeSystem ts = cas.getTypeSystem();
    Type fsType = fs.getType();
    if (ts.subsumes(ts.getType("uima.cas.FloatList"), fsType)) {
      return (floatListToArray(fs));
    }
    if (ts.subsumes(ts.getType("uima.cas.IntegerList"), fsType)) {
      return (integerListToArray(fs));
    }
    if (ts.subsumes(ts.getType("uima.cas.StringList"), fsType)) {
      return (stringListToArray(fs));
    }
    if (ts.subsumes(ts.getType("uima.cas.FSList"), fsType)) {
      return (fsListToArray(fs));
    }

    DebugNameValuePair[] result;
    String typeName = fsType.getName();

    List<Feature> features = fsType.getFeatures();
    int nbrFeats = features.size();
    boolean isAnnotation = false;
    boolean isJCasClass = false;
    if (fs.getClass().getName().equals(typeName)) { // true for JCas cover classes
      isJCasClass = true;
    }

    if (ts.subsumes(cas.getAnnotationType(), fsType)) {
      isAnnotation = true;
    }

    result = new DebugNameValuePair[(isJCasClass ? 0 : 1) // slot for type name if not JCas
            + (isAnnotation ? 3 : nbrFeats) // annotations have 4 slot display
    ];
    int i = 0;
    if (!isJCasClass) {
      result[i++] = new DebugNameValuePair("CasType", typeName);
    }

    if (isAnnotation) {
      DebugNameValuePair[] featResults = new DebugNameValuePair[nbrFeats];
      fillFeatures(featResults, 0, fs, features);
      result[i++] = new DebugNameValuePair("Features", featResults);
      result[i++] = new DebugNameValuePair("Covered Text", ((AnnotationFS) fs).getCoveredText());
      result[i++] = new DebugNameValuePair("SubAnnotations", new UnexpandedFeatureStructures(
              (AnnotationFS) fs));
    } else {
      fillFeatures(result, isJCasClass ? 0 : 1, fs, features);
    }

    return result;
  }