Java Code Examples for org.apache.uima.cas.CommonArrayFS#size()

The following examples show how to use org.apache.uima.cas.CommonArrayFS#size() . 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: CasCopier.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * @param arrayFS
 * @return a copy of the array
 */
private TOP copyArray(TOP srcFS) {
  final CommonArrayFS srcCA = (CommonArrayFS) srcFS;
  final int size = srcCA.size();
  final TypeImpl tgtTi = getTargetType(((TOP)srcFS)._getTypeImpl());  // could be null for src = e.g. Annotation[]
  
  if (tgtTi == null) {
    return null; // can't copy
  }
  
  if (srcFS instanceof CommonPrimitiveArray) {
    CommonArrayFS copy = (CommonArrayFS) tgtCasViewImpl.createArray(tgtTi, size);
    copy.copyValuesFrom(srcCA);
    return (TOP) copy;
  }
  
  // is reference array, either
  //   FSArray or
  //   subtype of that (e.g. Annotation[])
  
  FSArray fsArray = (FSArray) tgtCasViewImpl.createArray(tgtTi, size);

  // we do a direct recursive call here because the depth of this is limited to the depth of array nesting
  // Contrast with normal FS copying, where the depth could be very large (e.g. FS Lists)
  int i = 0;
  TOP[] tgtArray = fsArray._getTheArray();
  
  for (TOP srcItem : ((FSArray)srcFS)._getTheArray()) {
    if (null != srcItem) {
      tgtArray[i] = copyFsInner(srcItem);
    }
    i++;
  }

  return fsArray;
}
 
Example 3
Source File: BinaryCasSerDes6.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
private int serializeArrayLength(CommonArrayFS array) throws IOException {
  final int length = array.size();
  writeVnumber(arrayLength_i, length);
  return length;
}
 
Example 4
Source File: CASImpl.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
public int getArraySize(CommonArrayFS fs) {
  return fs.size();
}
 
Example 5
Source File: BinaryCasSerDes4.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
private boolean isNoPrevArrayValue(CommonArrayFS prevCommonArray) {
  return prevCommonArray == null || prevCommonArray.size() == 0;
}