org.apache.uima.cas.CommonArrayFS Java Examples

The following examples show how to use org.apache.uima.cas.CommonArrayFS. 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: NewFeatureUtils.java    From baleen with Apache License 2.0 6 votes vote down vote up
/**
 * Set the array 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 setPrimitiveArray(
    final JCas jCas,
    final BaleenAnnotation annotation,
    final Feature feature,
    final Object value) {
  final Type componentType = feature.getRange().getComponentType();

  Collection<?> list;
  if (value instanceof Collection) {
    list = (Collection<?>) value;
  } else {
    list = Collections.singletonList(value);
  }

  CommonArrayFS fs = getCommonArrayFS(jCas, componentType, list);

  if (fs != null) {
    annotation.setFeatureValue(feature, fs);
  }
}
 
Example #2
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 #3
Source File: CASImpl.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
public void traceFSCreate(FeatureStructureImplC fs) {
    StringBuilder b = svd.traceFScreationSb;
    if (b.length() > 0) {
      traceFSflush();
    }
    // normally commented-out for matching with v2
//    // mark annotations created by subiterator
//    if (fs._getTypeCode() == TypeSystemConstants.annotTypeCode) {
//      StackTraceElement[] stktr = Thread.currentThread().getStackTrace();
//      if (stktr.length > 7 && stktr[6].getClassName().equals("org.apache.uima.cas.impl.Subiterator")) {
//        b.append('*');
//      }
//    }
    svd.id2addr.add(svd.nextId2Addr);
    svd.nextId2Addr += fs._getTypeImpl().getFsSpaceReq((TOP)fs);
    traceFSfs(fs);
    svd.traceFSisCreate = true;
    if (fs._getTypeImpl().isArray()) {
      b.append(" l:").append(((CommonArrayFS)fs).size());
    }
  }
 
Example #4
Source File: XmiCasDeserializer.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Create an array in the CAS.
 * 
 * @param arrayType
 *  	CAS type code for the array
 * @param values
 *      List of strings, each containing the value of an element of the array.
 * @return a reference to the array FS
 */
private CommonArrayFS createNewArray(TypeImpl type, List<String> values) {
  final int sz = values.size();
  CommonArrayFS fs = (sz == 0) 
                       ? casBeingFilled.emptyArray(type)
                       : (CommonArrayFS) casBeingFilled.createArray(type, sz);
  if (fs instanceof FSArray) {
    final FSArray fsArray = (FSArray) fs;
    for (int i = 0; i < sz; i++) {
      maybeSetFsArrayElement(values, i, fsArray);
    } 
  } else {
    CommonPrimitiveArray fsp = (CommonPrimitiveArray) fs;
    for (int i = 0; i < sz; i++) {
      fsp.setArrayValueFromString(i, values.get(i));
    }
  }    
  return fs;
}
 
Example #5
Source File: CASImpl.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
public CommonArrayFS emptyArray(Type type) {
  switch (((TypeImpl)type).getCode()) {
  case TypeSystemConstants.booleanArrayTypeCode :
    return emptyBooleanArray();
  case TypeSystemConstants.byteArrayTypeCode :
    return emptyByteArray();
  case TypeSystemConstants.shortArrayTypeCode :
    return emptyShortArray();
  case TypeSystemConstants.intArrayTypeCode :
    return emptyIntegerArray();
  case TypeSystemConstants.floatArrayTypeCode :
    return emptyFloatArray();
  case TypeSystemConstants.longArrayTypeCode :
    return emptyLongArray();
  case TypeSystemConstants.doubleArrayTypeCode :
    return emptyDoubleArray();
  case TypeSystemConstants.stringArrayTypeCode :
    return emptyStringArray();
  default: // TypeSystemConstants.fsArrayTypeCode or any other type
    return emptyFSArray();
  }
}
 
Example #6
Source File: CasComparer.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
private int validateSameType(CommonArrayFS a1, CommonArrayFS a2) {
  if (a1.getClass() == a2.getClass()) {
    return 0;
  }
  ARRAY_TYPE at1 = getArrayType(a1);
  ARRAY_TYPE at2 = getArrayType(a2);
  return chkEqual(Integer.compare(at1.ordinal(), at2.ordinal()), 
      "Types not equal, type1 = %s, type2 = %s", a1.getClass(), a2.getClass());    
}
 
Example #7
Source File: CasComparer.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
private ARRAY_TYPE getArrayType(CommonArrayFS c) {
  if (c instanceof ArrayFS) return ARRAY_TYPE.FS; 
  if (c instanceof StringArrayFS) return ARRAY_TYPE.STRING; 
  if (c instanceof BooleanArrayFS) return ARRAY_TYPE.BOOLEAN; 
  if (c instanceof ByteArrayFS) return ARRAY_TYPE.BYTE; 
  if (c instanceof ShortArrayFS) return ARRAY_TYPE.SHORT; 
  if (c instanceof IntArrayFS) return ARRAY_TYPE.INT; 
  if (c instanceof LongArrayFS) return ARRAY_TYPE.LONG; 
  if (c instanceof FloatArrayFS) return ARRAY_TYPE.FLOAT; 
  if (c instanceof DoubleArrayFS) return ARRAY_TYPE.DOUBLE;
  return null;
}
 
Example #8
Source File: FSArrayList.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
@Override
public void copyValuesFrom(CommonArrayFS v) {
  clear();
  Spliterator<T> si;
  if (v instanceof FSArrayList) {
    si = ((FSArrayList<T>) v).spliterator();
  } else if (v instanceof FSArray) {
    si = (Spliterator<T>) ((FSArray)v).spliterator();
  } else {
    throw new ClassCastException("argument must be of class FSArray or FSArrayList");
  } 
  
  si.forEachRemaining(fs -> add(fs));
}
 
Example #9
Source File: IntegerArrayList.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
@Override
public void copyValuesFrom(CommonArrayFS<Integer> v) {
  clear();
  Spliterator.OfInt si;
  
  if (v instanceof IntegerArrayList) {
    si = ((IntegerArrayList) v).spliterator();
  } else if (v instanceof IntegerArray) {
    si = ((IntegerArray) v).spliterator();
  } else {
    throw new ClassCastException("argument must be of class IntegerArray or IntegerArrayList");
  }
    
  si.forEachRemaining((int i) -> add(i));      
}
 
Example #10
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 #11
Source File: FeatureStructureImplC.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
   * For JCas use (done this way to allow "final")
   * The TypeImpl is derived from the JCas cover class name
   * @param jcasImpl - the view this is being created in
   */
  
  protected FeatureStructureImplC(JCasImpl jcasImpl) {
    _casView = jcasImpl.getCasImpl();
    _typeImpl = _casView.getTypeSystemImpl().getJCasRegisteredType(getTypeIndexID());
    _id = _casView.getNextFsId((TOP)this); 
    
    if (null == _typeImpl) {
      throw new CASRuntimeException(CASRuntimeException.JCAS_TYPE_NOT_IN_CAS, this.getClass().getName());
    }
    
    if (_casView.maybeMakeBaseVersionForPear(this, _typeImpl)) {
      _setPearTrampoline();
    }
    
    FeatureStructureImplC baseFs = _casView.pearBaseFs;
    if (null != baseFs) {
      _intData = baseFs._intData;
      _refData = baseFs._refData;
      _casView.pearBaseFs = null;
    } else {
      _intData = _allocIntData();
      _refData = _allocRefData();
    }
    
    if (traceFSs && !(this instanceof CommonArrayFS)) {
      _casView.traceFSCreate(this);
    }
    
    _casView.maybeHoldOntoFS(this);

//    if (_typeImpl.featUimaUID != null) {
//      final int id = _casView.getAndIncrUimaUID();
//      _setLongValueNcNj(_typeImpl.featUimaUID, id);
//      _casView.add2uid2fs(id, (TOP)this);
//    }
  }
 
Example #12
Source File: FeatureStructureImplC.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * For non-JCas use, Internal Use Only, called by cas.createFS via generators
 * @param casView -
 * @param type -
 */
protected FeatureStructureImplC(TypeImpl type, CASImpl casView) {
  _casView = casView;
  _typeImpl = type;
  _id = casView.getNextFsId((TOP)this);   
  
  if (_casView.maybeMakeBaseVersionForPear(this, _typeImpl)) {
    _setPearTrampoline();
  }

  FeatureStructureImplC baseFs = _casView.pearBaseFs;
  if (null != baseFs) {
    _intData = baseFs._intData;
    _refData = baseFs._refData;
    _casView.pearBaseFs = null;
  } else {
    _intData = _allocIntData();
    _refData = _allocRefData();
  }

  
  if (traceFSs && !(this instanceof CommonArrayFS)) {
    _casView.traceFSCreate(this);
  }
  
  _casView.maybeHoldOntoFS(this);
}
 
Example #13
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 #14
Source File: XmiCasDeserializer.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Update existing array.  The size has already been checked to be equal, but could be 0
 * @param arrayType
 * @param values
 * @param existingArray
 */
private void updateExistingArray(List<String> values, CommonArrayFS existingArray) {
  final int sz = values.size();
  
  if (existingArray instanceof FSArray) {
    final FSArray fsArray = (FSArray) existingArray;
    for (int i = 0; i < sz; i++) {
      
      String featVal = values.get(i);  
      if (emptyVal(featVal)) { // can be empty if JSON
        fsArray.set(i,  null);
      
      } else {
        maybeSetFsArrayElement(values, i, fsArray);
        final int xmiId = Integer.parseInt(featVal);
        final int pos = i;
        TOP tgtFs = maybeGetFsForXmiId(xmiId);
        if (null == tgtFs) {
          fixupToDos.add( () -> finalizeFSArrayRefValue(xmiId, fsArray, pos));
        } else {
          fsArray.set(i,  tgtFs);
        }
      }          
    }
    return;
  }
  
  CommonPrimitiveArray existingPrimitiveArray = (CommonPrimitiveArray) existingArray;
  for (int i = 0; i < sz; i++) {
    existingPrimitiveArray.setArrayValueFromString(i, values.get(i));
  }
}
 
Example #15
Source File: AbstractAhoCorasickAnnotator.java    From baleen with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private void setProperty(
    BaleenAnnotation entity, Method method, Map<String, Object> additionalData) {
  if (method.getName().startsWith("set")
      && method.getName().substring(3, 4).matches("[A-Z]")
      && method.getParameterCount() == 1) {
    String property = method.getName().substring(3);
    property = property.substring(0, 1).toLowerCase() + property.substring(1);
    Object obj = additionalData.get(property);

    if (obj == null) {
      return;
    }

    if (method.getParameterTypes()[0].isAssignableFrom(obj.getClass())) {
      setPropertyObject(entity, method, obj);
    } else if (method.getParameterTypes()[0].isAssignableFrom(String.class)) {
      getMonitor()
          .debug("Converting gazetteer object of type {} to String", obj.getClass().getName());

      if (obj instanceof Document) {
        // Special case for Mongo Document objects, where the toString function
        // doesn't convert to JSON as expected (e.g. for GeoJSON)
        setPropertyString(entity, method, ((Document) obj).toJson());
      } else {
        setPropertyString(entity, method, obj.toString());
      }
    } else if (List.class.isAssignableFrom(obj.getClass())
        && CommonArrayFS.class.isAssignableFrom(method.getParameterTypes()[0])) {
      setPropertyArray(entity, method, (List<Object>) obj);
    }
  }
}
 
Example #16
Source File: CasAnnotationViewer.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
   * Get feature value in string, if value is not another annotation and not
   * an array of annotations.
   *
   * @param aFS the a FS
   * @param feature the feature
   * @return the feature value in string
   */
  private String getFeatureValueInString(FeatureStructure aFS, Feature feature) {
    if (this.cas == null || this.typeSystem == null || this.stringType == null || this.fsArrayType == null) {
      return "null";
    }

    Type rangeType = feature.getRange();
    if (this.typeSystem.subsumes(this.fsArrayType, rangeType)) {
      // If the feature is an FSArray, cannot render it as simple as "name=value".
      return "*FSArray*";
    }
    if (this.typeSystem.subsumes(this.stringType, rangeType)) {
      return checkString(aFS.getStringValue(feature), "null", 64);
    }
    if (rangeType.isPrimitive()) {
      return checkString(aFS.getFeatureValueAsString(feature), "null", 64);
    }
    if (rangeType.isArray()) {
//      String rangeTypeName = rangeType.getName();
      CommonArrayFS arrayFS = (CommonArrayFS) aFS.getFeatureValue(feature);
      String[] values = (arrayFS == null) ? null : arrayFS.toStringArray();
      if (values == null || values.length == 0) {
        return "null";
      }

      StringBuffer displayValue = new StringBuffer();
      displayValue.append("[");
      for (int i = 0; i < values.length - 1; i++) {
        displayValue.append(values[i]);
        displayValue.append(",");
      }
      displayValue.append(values[values.length - 1]);
      displayValue.append("]");
      return displayValue.toString();
    }

    // If none of the above, then it is an annotation object. Cannot render it as simple as "name=value".
    return "*FS*";
  }
 
Example #17
Source File: FeatureStructureImplC.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
/**
   * See http://www.javaworld.com/article/2076332/java-se/how-to-avoid-traps-and-correctly-override-methods-from-java-lang-object.html
   * for suggestions on avoiding bugs in implementing clone
   * 
   * Because we have final fields for _intData, _refData, and _id, we can't use clone.
   * Instead, we use the createFS to create the FS of the right type.  This will use the generators.
   * 
   * Strategy for cloning:
   *   Goal is to create an independent instance of some subtype of this class, with 
   *   all the fields properly copied from this instance.
   *     - some fields could be in the _intData and _refData
   *     - some fields could be stored as features
   *     
   * Subcases to handle:
   *   - arrays - these have no features.
   *   
   * Note: CasCopier doesn't call this because it needs to do a deep copy
   *       This is not used by the framework
   *   
   * @return a new Feature Structure as a new instance of the same class, 
   *         with a new _id field, 
   *         with its features set to the values of the features in this Feature Structure
   * @throws CASRuntimeException (different from Object.clone()) if an exception occurs   
   */
  @Override
  public FeatureStructureImplC clone() throws CASRuntimeException { 
        
    if (_typeImpl.isArray()) {
      CommonArrayFS original = (CommonArrayFS) this;
      CommonArrayFS copy = (CommonArrayFS) _casView.createArray(_typeImpl, original.size());
      copy.copyValuesFrom(original);      
      return (FeatureStructureImplC) copy;
    }
    
    TOP fs = _casView.createFS(_typeImpl);
    TOP srcFs = (TOP) this;
    
   fs._copyIntAndRefArraysEqTypesFrom(srcFs);
    
    /* copy all the feature values except the sofa ref which is already set as part of creation */
//    for (FeatureImpl feat : _typeImpl.getFeatureImpls()) {
//      CASImpl.copyFeature(srcFs, feat, fs);
//    }   // end of for loop
    return fs;
  }
 
Example #18
Source File: CasComparer.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
private int compareArrayFSs(TOP arrayFS1fs, Feature feat1, TOP arrayFS2fs, Feature feat2, Set<TOP> visited) {

  CommonArrayFS arrayFS1 = (CommonArrayFS)arrayFS1fs.getFeatureValue(feat1);
  CommonArrayFS arrayFS2 = (CommonArrayFS)arrayFS2fs.getFeatureValue(feat2);
  
  if (null == arrayFS1 && null == arrayFS2)return 0; // are equal
  if (null == arrayFS1) return chkEqual(-1,  "Array FS1 is null, but Array FS2 is not");
  if (null == arrayFS2) return chkEqual(-1,  "Array FS2 is null, but Array FS1 is not");

  int r, len;
  if (0 != (r = Integer.compare(len = arrayFS1.size(), arrayFS2.size()))) {
    return chkEqual(r, "ArrayFSs are different sizes, fs1 size is %d, fs2 size is %d", arrayFS1.size(), arrayFS2.size());
  }
  // are same size
  r = validateSameType(arrayFS1, arrayFS2);
  if (0 != r) return r;
  
  switch(getArrayType(arrayFS1)) {
  case FS:
    for (int j = 0; j < len; j++) {
      if (0 != (r = compare1((TOP)((FSArray)arrayFS1).get(j), (TOP)((FSArray)arrayFS2).get(j), visited))) return r;
    }
    break;
  case BOOLEAN:
    for (int j = 0; j < len; j++) {
      if (0 != (r = compBoolean(((BooleanArrayFS)arrayFS1).get(j), ((BooleanArrayFS)arrayFS2).get(j)))) return r;
    }
    break;
  case BYTE:
    for (int j = 0; j < len; j++) {
      if (0 != (r = compLong(((ByteArrayFS)arrayFS1).get(j), ((ByteArrayFS)arrayFS2).get(j)))) return r;
    }
    break;
  case SHORT:
    for (int j = 0; j < len; j++) {
      if (0 != (r = compLong(((ShortArrayFS)arrayFS1).get(j), ((ShortArrayFS)arrayFS2).get(j)))) return r;
    }
    break;
  case INT:
    for (int j = 0; j < len; j++) {
      if (0 != (r = compLong(((IntArrayFS)arrayFS1).get(j), ((IntArrayFS)arrayFS2).get(j)))) return r;
    }
    break;
  case LONG:
    for (int j = 0; j < len; j++) {
      if (0 != (r = compLong(((LongArrayFS)arrayFS1).get(j), ((LongArrayFS)arrayFS2).get(j)))) return r;
    }
    break;
  case FLOAT:
    for (int j = 0; j < len; j++) {
      if (0 != (r = compDouble(((FloatArrayFS)arrayFS1).get(j), ((FloatArrayFS)arrayFS2).get(j)))) return r;
    }
    break;
  case DOUBLE:
    for (int j = 0; j < len; j++) {
      if (0 != (r = compDouble(((DoubleArrayFS)arrayFS1).get(j), ((DoubleArrayFS)arrayFS2).get(j)))) return r;
    }
    break;
  case STRING:
    for (int j = 0; j < len; j++) {
      if (0 != (r = compStr(((StringArrayFS)arrayFS1).get(j), ((StringArrayFS)arrayFS2).get(j)))) {
        return chkEqual(r, "String miscompare, s1 = %s, s2 = %s", ((StringArrayFS)arrayFS1).get(j), ((StringArrayFS)arrayFS2).get(j));
      }
    }
    break;
  }
  return 0;  // all were equal
}
 
Example #19
Source File: CasComparer.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
/**
 * 
 * @param fs1
 * @param fs2
 * @param visited when called for sorting FSs, is sortCompareSeen(cleared); 
 *                when called for comparing for equality, holds FSs already compared in other views
 * @return
 */
private int compare1(TOP fs1, TOP fs2, Set<TOP> visited) {
  if (!isSortUse) {  // only do null check for non- sort use
    if (fs1 == null && fs2 == null) {
      return 0;
    }
    if (fs1 == null) return chkEqual(-1, "fs1 was null and fs2 was not");
    if (fs2 == null) return chkEqual(1,  "fs2 was null and fs1 was not");
  }
  
  boolean wasPresent1 = !visited.add(fs1);
  boolean wasPresent2 = !visited.add(fs2);
  
  if (wasPresent1 && wasPresent2) {
    return 0;  // already checked and found equal
  }
  
  if (!wasPresent1 && !wasPresent2) {
    int r;
    TypeImpl t1, t2;
    if (0 != (r = compStr((t1 = (TypeImpl) fs1.getType()).getName(), (t2 = (TypeImpl) fs2.getType()).getName()))) {
      return chkEqual(r, "Types of FSs are different: Type1 = %s, Type2 = %s", t1, t2);
    }
    // types are the same
    
    if (CAS.TYPE_NAME_SOFA.equals(t1.getName())) {
      if (isSortUse) {
        return Integer.compare(((Sofa)fs1).getSofaNum(), ((Sofa)fs2).getSofaNum());
      }
      return 0;  // skip comparing sofa so this routine can be used for cas copier testing
    }

    if (t1.isArray()) {
      final int len1 = ((CommonArrayFS)fs1).size();
      if (0 != (r = Integer.compare(len1, ((CommonArrayFS)fs2).size()))) {
        return r;
      }
      
      SlotKind kind = t1.getComponentSlotKind();
      
      switch(kind) {
      case Slot_BooleanRef: return compareAllArrayElements(len1, i -> Boolean.compare(((BooleanArray  )fs1).get(i), ((BooleanArray)fs2).get(i)), "Miscompare Boolean Arrays %n%s%n%s", fs1, fs2);
      case Slot_ByteRef:    return compareAllArrayElements(len1, i -> Byte   .compare(((ByteArray     )fs1).get(i), ((ByteArray   )fs2).get(i)), "Miscompare Byte Arrays %n%s%n%s"   , fs1, fs2);
      case Slot_ShortRef:   return compareAllArrayElements(len1, i -> Short  .compare(((ShortArray    )fs1).get(i), ((ShortArray  )fs2).get(i)), "Miscompare Short Arrays %n%s%n%s"  , fs1, fs2);
      case Slot_Int:     return compareAllArrayElements   (len1, i -> Integer.compare(((IntegerArray  )fs1).get(i), ((IntegerArray)fs2).get(i)), "Miscompare Integer Arrays %n%s%n%s", fs1, fs2);
      case Slot_LongRef:    return compareAllArrayElements(len1, i -> Long   .compare(((LongArray     )fs1).get(i), ((LongArray   )fs2).get(i)), "Miscompare Long Arrays %n%s%n%s", fs1, fs2);
      case Slot_Float:   return compareAllArrayElements   (len1, i -> Integer.compare(Float.floatToRawIntBits   (((FloatArray )fs1).get(i)), 
                                                                                      Float.floatToRawIntBits   (((FloatArray )fs2).get(i))),    "Miscompare Float Arrays %n%s%n%s", fs1, fs2);
      case Slot_DoubleRef:  return compareAllArrayElements(len1, i -> Long   .compare(Double.doubleToRawLongBits(((DoubleArray)fs1).get(i)), 
                                                                                      Double.doubleToRawLongBits(((DoubleArray)fs2).get(i))),    "Miscompare Double Arrays %n%s%n%s", fs1, fs2);
      case Slot_HeapRef: return    compareAllArrayElements(len1, i ->        compare1((TOP)((FSArray<?>       )fs1).get(i), (TOP)((FSArray<?> )fs2).get(i), visited), "Miscompare FS Arrays %n%s%n%s", fs1, fs2);
      case Slot_StrRef:  return    compareAllArrayElements(len1, i -> Misc.compareStrings(((StringArray   )fs1).get(i), ((StringArray )fs2).get(i)), "Miscompare String Arrays %n%s%n%s", fs1, fs2);
      default: 
        Misc.internalError(); return 0;  // only to avoid a compile error
      }        
    }
    
    ts = fs1.getCAS().getTypeSystem();
    return compareFeatures(fs1, fs2, t1.getFeatureImpls(), t2.getFeatureImpls(), visited);           
  }
  
  // getting here: one was already traversed, the other not.  Possible use case:
  //   fs1 is a list with a loop; fs2 is a list without a loop
  //   arbitrarily return the one with a loop first
  
  if (fs1 instanceof EmptyList) { 
    return 0;  // allow different or shared EmptyList instances to compare equal
    // because some deserializers or user code can create them as shared or not
  }
  if (wasPresent1) {
    return chkEqual(-1, "First element had a ref loop %s%n, second didn't so far %s", fs1, fs2);
  }
  return chkEqual(-1, "Second element had a ref loop %s%n, first didn't so far %s", fs2, fs1);
  
}
 
Example #20
Source File: BooleanArray.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
@Override
public void copyValuesFrom(CommonArrayFS<Boolean> v) {
  BooleanArray bv = (BooleanArray) v;
  System.arraycopy(bv.theArray,  0,  theArray, 0, theArray.length);
  _casView.maybeLogArrayUpdates(this, 0, size());
}
 
Example #21
Source File: LongArray.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
@Override
public void copyValuesFrom(CommonArrayFS v) {
  LongArray bv = (LongArray) v;
  System.arraycopy(bv.theArray,  0,  theArray, 0, theArray.length);
  _casView.maybeLogArrayUpdates(this, 0, size());
}
 
Example #22
Source File: DoubleArray.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
@Override
public void copyValuesFrom(CommonArrayFS v) {
  DoubleArray bv = (DoubleArray) v;
  System.arraycopy(bv.theArray,  0,  theArray, 0, theArray.length);
}
 
Example #23
Source File: ByteArray.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
@Override
public void copyValuesFrom(CommonArrayFS<Byte> v) {
  ByteArray bv = (ByteArray) v;
  System.arraycopy(bv.theArray,  0,  theArray, 0, theArray.length);
  _casView.maybeLogArrayUpdates(this, 0, size());
}
 
Example #24
Source File: ShortArray.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
@Override
public void copyValuesFrom(CommonArrayFS v) {
  ShortArray bv = (ShortArray) v;
  System.arraycopy(bv.theArray,  0,  theArray, 0, theArray.length);
  _casView.maybeLogArrayUpdates(this, 0, size());
}
 
Example #25
Source File: IntegerArray.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
@Override
public void copyValuesFrom(CommonArrayFS v) {
  IntegerArray bv = (IntegerArray) v;
  System.arraycopy(bv.theArray,  0,  theArray, 0, theArray.length);
  _casView.maybeLogArrayUpdates(this, 0, size());
}
 
Example #26
Source File: FSArray.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
@Override
public void copyValuesFrom(CommonArrayFS<T> v) {
  FSArray<T> bv = (FSArray<T>) v;
  System.arraycopy(bv.theArray,  0,  theArray, 0, theArray.length);
  _casView.maybeLogArrayUpdates(this, 0, size());
}
 
Example #27
Source File: FSNode.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
/**
 * Gets the value string.
 *
 * @return the value string
 */
private String getValueString() {
  
  switch (this.nodeClass) {
    case INT_FS:
    case BYTE_FS:
    case SHORT_FS: {
      return Long.toString(this.intOrLongLikeValue);
    }
    case FLOAT_FS: {
      return Float.toString(CASImpl.int2float((int) this.intOrLongLikeValue));
    }
    case BOOL_FS: {
      return (0 == this.intOrLongLikeValue) ? "false" : "true";
    }
    case LONG_FS: {
      return Long.toString(this.intOrLongLikeValue);
    }
    case DOUBLE_FS: {
      return Double.toString(CASImpl.long2double(this.intOrLongLikeValue));
    }
    case STRING_FS: {
      if (this.string == null) {
        return getNullString();
      }
      String s = this.string;
      // Check if we need to shorten the string for display purposes
      String s1 = shortenString(s);
      // Remember if string is shortened
      this.isShortenedString = (s != s1);
      return "\"" + escapeLt(s1) + "\"";
    }
    case ARRAY_FS: {
      if (this.fs == null) {
        return getNullString();
      }
      return "<font color=blue>" + getType().getName() + "</font>["
              + ((CommonArrayFS)fs).size() + "]";
    }
    case STD_FS: {
      if (fs == null) {
        return getNullString();
      }
      return "<font color=blue>" + getType().getName() + "</font>";
    }
  }
  return null;
}
 
Example #28
Source File: FloatArray.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
@Override
public void copyValuesFrom(CommonArrayFS v) {
  FloatArray bv = (FloatArray) v;
  System.arraycopy(bv.theArray,  0,  theArray, 0, theArray.length);
  _casView.maybeLogArrayUpdates(this, 0, size());
}
 
Example #29
Source File: StringArray.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
@Override
public void copyValuesFrom(CommonArrayFS v) {
  StringArray bv = (StringArray) v;
  System.arraycopy(bv.theArray,  0,  theArray, 0, theArray.length);
  _casView.maybeLogArrayUpdates(this, 0, size());
}
 
Example #30
Source File: AllFSs.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
private void enqueueFeatures(TOP fs) {
    if (fs instanceof FSArray) {
      for (TOP item : ((FSArray)fs)._getTheArray()) {
        enqueueFS(item);
      }
      return;
    }
    
    // not an FS Array
    if (fs instanceof CommonArrayFS) {
      return;  // no refs
    }
  
    final TypeImpl srcType = fs._getTypeImpl();
    if (srcType.getStaticMergedNonSofaFsRefs().length > 0) {
      if (fs instanceof UimaSerializableFSs) {
        ((UimaSerializableFSs)fs)._save_fsRefs_to_cas_data();
      }
      for (FeatureImpl srcFeat : srcType.getStaticMergedNonSofaFsRefs()) {
        if (typeMapper != null) {
          FeatureImpl tgtFeat = typeMapper.getTgtFeature(srcType, srcFeat);
          if (tgtFeat == null) {
            continue;  // skip enqueue if not in target
          }
        }
        enqueueFS(fs._getFeatureValueNc(srcFeat)); 
      }
    }
    
    
//    
//    if (srcType.hasRefFeature) {
//      if (fs instanceof UimaSerializableFSs) {
//        ((UimaSerializableFSs)fs)._save_fsRefs_to_cas_data();
//      }
//      for (FeatureImpl srcFeat : srcType.getStaticMergedRefFeatures()) {
//        if (typeMapper != null) {
//          FeatureImpl tgtFeat = typeMapper.getTgtFeature(srcType, srcFeat);
//          if (tgtFeat == null) {
//            continue;  // skip enqueue if not in target
//          }
//        } 
//        if (srcFeat.getSlotKind() == SlotKind.Slot_HeapRef) {
////        if (srcFeat.getRangeImpl().isRefType) {
//          enqueueFS(fs._getFeatureValueNc(srcFeat));
//        }
//      }
//    }
  }