org.apache.uima.jcas.cas.FloatArray Java Examples

The following examples show how to use org.apache.uima.jcas.cas.FloatArray. 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: JCasTest.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
public void make() {
	Root r1 = new Root(jcas);
	// Note: Java 7 can return -ve hashcodes so must avoid -ve remainders.
	int k = System.identityHashCode(r1);
	int imax = 1 + Math.abs(k % 10);
	r1.setArrayFloat(new FloatArray(jcas, imax));
	for (int i = 0; i < imax; i++) {
		r1.setArrayFloat(i, (float) k / (i + 1));
	}
	int imaxFS = 1 + Math.abs((k % 3));
	r1.setArrayRef(new FSArray(jcas, imaxFS));
	for (int i = 1; i < imaxFS; i++) {
		r1.setArrayRef(i, endOfSentenceInstance);
	}
	r1.setPlainString("" + k);
	r1.addToIndexes();
}
 
Example #2
Source File: CASImpl.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
public TOP createArray(TypeImpl array_type, int arrayLength) {
    TypeImpl_array tia = (TypeImpl_array) array_type;
    TypeImpl componentType = tia.getComponentType();
    if (componentType.isPrimitive()) {
      checkArrayPreconditions(arrayLength);
      switch (componentType.getCode()) {
      case intTypeCode: return new IntegerArray(array_type, this, arrayLength);
      case floatTypeCode: return new FloatArray(array_type, this, arrayLength);
      case booleanTypeCode: return new BooleanArray(array_type, this, arrayLength);
      case byteTypeCode: return new ByteArray(array_type, this, arrayLength);
      case shortTypeCode: return new ShortArray(array_type, this, arrayLength);
      case longTypeCode: return new LongArray(array_type, this, arrayLength);
      case doubleTypeCode: return new DoubleArray(array_type, this, arrayLength);
      case stringTypeCode: return new StringArray(array_type, this, arrayLength);
      default: throw Misc.internalError();
      }
    }
//    return (TOP) createArrayFS(/* array_type, */ arrayLength);  // for backwards compat w/ v2, don't create typed arrays
    if (IS_DISABLE_SUBTYPE_FSARRAY_CREATION) {
      return (TOP) createArrayFS(arrayLength);
    } else {
      return (TOP) createArrayFS(array_type, arrayLength);
    }
  }
 
Example #3
Source File: NewFeatureUtils.java    From baleen with Apache License 2.0 5 votes vote down vote up
private static FloatArray getFloatArray(JCas jCas, Collection<?> list) {
  final FloatArray a = new FloatArray(jCas, list.size());
  int i = 0;
  for (final Object s : list) {
    a.set(i++, ((Number) s).floatValue());
  }
  return a;
}
 
Example #4
Source File: CASImpl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
@Override
public FloatArray emptyFloatArray() {
    if (null == svd.emptyFloatArray) {
      svd.emptyFloatArray = new FloatArray(this.getJCas(), 0);
    }
    return svd.emptyFloatArray;
  }
 
Example #5
Source File: FeatureStructureImplC.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
private boolean isOkArray(TypeImpl range, Object v) {
    if (v == null) {
      return true;
    }
    
    
    final int rangeTypeCode = range.getCode();

    /* The assignment is stricter than the Java rules - must match */
    switch (rangeTypeCode) {
    case TypeSystemConstants.booleanArrayTypeCode:
      return v instanceof BooleanArray;
    case TypeSystemConstants.byteArrayTypeCode:
    return v instanceof ByteArray;
    case TypeSystemConstants.shortArrayTypeCode:
      return v instanceof ShortArray;
    case TypeSystemConstants.intArrayTypeCode:
      return v instanceof IntegerArray;
    case TypeSystemConstants.floatArrayTypeCode:
      return v instanceof FloatArray;
    case TypeSystemConstants.longArrayTypeCode:
      return v instanceof LongArray;
    case TypeSystemConstants.doubleArrayTypeCode:
      return v instanceof DoubleArray;
    case TypeSystemConstants.stringArrayTypeCode:
      return v instanceof StringArray;
//    case TypeSystemConstants.javaObjectArrayTypeCode:
//      return v instanceof JavaObjectArray;
    case TypeSystemConstants.fsArrayTypeCode:
      return v instanceof FSArray;
    }
    
    // it is possible that the array has a special type code corresponding to a type "someUserType"[]
    //   meaning an array of some user type.  UIMA implements these as instances of FSArray (I think)
    
    if (!(v instanceof FSArray)) { return false; }
    
    return true;
  }
 
Example #6
Source File: DocumentLine.java    From bluima with Apache License 2.0 4 votes vote down vote up
/** getter for beginnings - gets 
 * @generated
 * @return value of the feature 
 */
public FloatArray getBeginnings() {
  if (DocumentLine_Type.featOkTst && ((DocumentLine_Type)jcasType).casFeat_beginnings == null)
    jcasType.jcas.throwFeatMissing("beginnings", "ch.epfl.bbp.uima.types.DocumentLine");
  return (FloatArray)(jcasType.ll_cas.ll_getFSForRef(jcasType.ll_cas.ll_getRefValue(addr, ((DocumentLine_Type)jcasType).casFeatCode_beginnings)));}
 
Example #7
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 #8
Source File: JCasImpl.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
@Deprecated
public FloatArray getFloatArray0L() {
  return this.getCas().emptyFloatArray();
}
 
Example #9
Source File: CAS.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
/** 
 * @return a lazily created shared (for this CAS) 0-length array
 */
default FloatArray emptyFloatArray() {
  return ((CASImpl)getLowLevelCAS()).emptyFloatArray();
}
 
Example #10
Source File: BinaryCasSerDes.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
/**
 * Doing updates for delta cas for existing objects.
 * Cases:
 *   - item in heap-stored-array = update the corresponding item in the FS
 *   - non-ref in feature slot - update the corresponding feature
 *   - ref (to long/double value, to string)
 *       -- these always reference entries in long/string tables that are new (above the line)
 *       -- these have already been deserialized
 *   - ref (to main heap) - can update this directly       
 *   NOTE: entire aux arrays never have their refs to the aux heaps updated, for 
 *           arrays of boolean, byte, short, long, double
 *   NOTE: Slot updates for FS refs always point to addr which are in the addr2fs table or are 0 (null),
 *           because if the ref is to a new one, those have been already deserialized by this point, and
 *                   if the ref is to a below-the-line one, those are already put into the addr2fs table
 * @param bds - helper data
 * @param slotAddr - the main heap slot addr being updated
 * @param slotValue - the new value
 */
private void updateHeapSlot(BinDeserSupport bds, int slotAddr, int slotValue, Int2ObjHashMap<TOP, TOP> addr2fs) {
  TOP fs = bds.fs;
  TypeImpl type = fs._getTypeImpl();
  if (type.isArray()) {
    // only heap stored arrays have mod updates.  
    final int hsai = slotAddr - bds.fsStartAddr - arrayContentOffset;  // heap stored array index
    switch(type.getComponentSlotKind()) {
    // heap stored arrays
    case Slot_Int: ((IntegerArray)fs).set(hsai,                   slotValue);  break;
    case Slot_Float: ((FloatArray)fs).set(hsai, CASImpl.int2float(slotValue)); break;
    
    case Slot_StrRef: ((StringArray)fs).set(hsai,  stringHeap.getStringForCode(slotValue)); break;
    case Slot_HeapRef:((FSArray    )fs).set(hsai, addr2fs.get(slotValue)); break;
    
    default: Misc.internalError();
    } // end of switch for component type of arrays
  } else { // end of arrays
    // is plain fs with fields
    final int offset0 = slotAddr - bds.fsStartAddr - 1;  // 0 based offset of feature, -1 for type code word
    FeatureImpl feat = type.getFeatureImpls()[offset0];
    SlotKind slotKind = feat.getSlotKind();
    switch(slotKind) {
    case Slot_Boolean:
    case Slot_Byte:   
    case Slot_Short:  
    case Slot_Int:    
    case Slot_Float: fs._setIntLikeValue(slotKind, feat, slotValue); break;
    
    case Slot_LongRef:   fs.setLongValue(feat, longHeap.getHeapValue(slotValue)); break;
    case Slot_DoubleRef: fs.setDoubleValue(feat, CASImpl.long2double(longHeap.getHeapValue(slotValue))); break;
    case Slot_StrRef: {
      String s = stringHeap.getStringForCode(slotValue);        
      if (updateStringFeature(fs, feat, s, null)) {
        fs.setStringValue(feat, stringHeap.getStringForCode(slotValue));
      }
      break;
    }
      
    case Slot_HeapRef:   fs.setFeatureValue(feat, addr2fs.get(slotValue)); break;
    default: Misc.internalError();
    }
  }
}
 
Example #11
Source File: CASImpl.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
@Override
public void ll_setFloatArrayValue(int fsRef, int position, float value) {
  FloatArray array = getFsFromId_checked(fsRef);
  array.set(position,  value);  // that set operation does required journaling
}
 
Example #12
Source File: CASImpl.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
@Override
public final float ll_getFloatArrayValue(int fsRef, int position) {
  return getFloatArrayValue(((FloatArray)getFsFromId_checked(fsRef)), position);
}
 
Example #13
Source File: CASImpl.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
public final float getFloatArrayValue(FloatArray array, int i) {
  return array.get(i);
}
 
Example #14
Source File: CASImpl.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
@Override
public FloatArrayFS createFloatArrayFS(int length) {
  checkArrayPreconditions(length);
  return new FloatArray(getTypeSystemImpl().floatArrayType, this, length);
}
 
Example #15
Source File: FSCollectionFactory.java    From uima-uimafit with Apache License 2.0 4 votes vote down vote up
public static FloatArray fillArray(FloatArray aArray, float... aValues) {
  return (FloatArray) fillArrayFS(aArray, aValues);
}
 
Example #16
Source File: FSCollectionFactory.java    From uima-uimafit with Apache License 2.0 4 votes vote down vote up
public static FloatArray fillArray(FloatArray aArray, Iterable<Float> aValues) {
  return (FloatArray) fillArrayFS(aArray, aValues);
}
 
Example #17
Source File: FSCollectionFactory.java    From uima-uimafit with Apache License 2.0 4 votes vote down vote up
public static FloatArray createFloatArray(JCas aJCas, float... aArray) {
  return fillArray(new FloatArray(aJCas, aArray.length), aArray);
}
 
Example #18
Source File: FSCollectionFactory.java    From uima-uimafit with Apache License 2.0 4 votes vote down vote up
public static FloatArray createFloatArray(JCas aJCas, Collection<Float> aCollection) {
  return fillArray(new FloatArray(aJCas, aCollection.size()), aCollection);
}
 
Example #19
Source File: DocumentLine.java    From bluima with Apache License 2.0 4 votes vote down vote up
/** setter for endings - sets  
 * @generated
 * @param v value to set into the feature 
 */
public void setEndings(FloatArray v) {
  if (DocumentLine_Type.featOkTst && ((DocumentLine_Type)jcasType).casFeat_endings == null)
    jcasType.jcas.throwFeatMissing("endings", "ch.epfl.bbp.uima.types.DocumentLine");
  jcasType.ll_cas.ll_setRefValue(addr, ((DocumentLine_Type)jcasType).casFeatCode_endings, jcasType.ll_cas.ll_getFSRef(v));}
 
Example #20
Source File: DocumentLine.java    From bluima with Apache License 2.0 4 votes vote down vote up
/** getter for endings - gets 
 * @generated
 * @return value of the feature 
 */
public FloatArray getEndings() {
  if (DocumentLine_Type.featOkTst && ((DocumentLine_Type)jcasType).casFeat_endings == null)
    jcasType.jcas.throwFeatMissing("endings", "ch.epfl.bbp.uima.types.DocumentLine");
  return (FloatArray)(jcasType.ll_cas.ll_getFSForRef(jcasType.ll_cas.ll_getRefValue(addr, ((DocumentLine_Type)jcasType).casFeatCode_endings)));}
 
Example #21
Source File: DocumentLine.java    From bluima with Apache License 2.0 4 votes vote down vote up
/** setter for beginnings - sets  
 * @generated
 * @param v value to set into the feature 
 */
public void setBeginnings(FloatArray v) {
  if (DocumentLine_Type.featOkTst && ((DocumentLine_Type)jcasType).casFeat_beginnings == null)
    jcasType.jcas.throwFeatMissing("beginnings", "ch.epfl.bbp.uima.types.DocumentLine");
  jcasType.ll_cas.ll_setRefValue(addr, ((DocumentLine_Type)jcasType).casFeatCode_beginnings, jcasType.ll_cas.ll_getFSRef(v));}
 
Example #22
Source File: JCas.java    From uima-uimaj with Apache License 2.0 2 votes vote down vote up
/**
 * Retrieve a lazily-created constant from the cas which holds a 0-length instance. 
 * Since this can be a common value, we
 * avoid creating multiple copies of it. All uses can use the same value because it is not
 * updatable (it has no subfields). This is initialized lazily on first reference, and reset when
 * the CAS is reset.
 * @return 0-length instance of a FloatArray
 * @deprecated renamed emptyXXXArray
 */
@Deprecated
default FloatArray getFloatArray0L() {
  return this.getCas().emptyFloatArray();
}
 
Example #23
Source File: JCas.java    From uima-uimaj with Apache License 2.0 2 votes vote down vote up
/**
 * Retrieve a lazily-created constant from the cas which holds a 0-length instance. 
 * Since this can be a common value, we
 * avoid creating multiple copies of it. All uses can use the same value because it is not
 * updatable (it has no subfields). This is initialized lazily on first reference, and reset when
 * the CAS is reset.
 * @return 0-length instance of a FloatArray
 */
default FloatArray emptyFloatArray() {
  return this.getCas().emptyFloatArray();
}
 
Example #24
Source File: Root.java    From uima-uimaj with Apache License 2.0 2 votes vote down vote up
/** getter for arrayFloat - gets 
 * @generated
 * @return value of the feature 
 */
public FloatArray getArrayFloat() { return (FloatArray)(_getFeatureValueNc(wrapGetIntCatchException(_FH_arrayFloat)));}
 
Example #25
Source File: Root.java    From uima-uimaj with Apache License 2.0 2 votes vote down vote up
/** setter for arrayFloat - sets  
 * @generated
 * @param v value to set into the feature 
 */
public void setArrayFloat(FloatArray v) {
  _setFeatureValueNcWj(wrapGetIntCatchException(_FH_arrayFloat), v);
}
 
Example #26
Source File: Root.java    From uima-uimaj with Apache License 2.0 2 votes vote down vote up
/** indexed getter for arrayFloat - gets an indexed value - 
 * @generated
 * @param i index in the array to get
 * @return value of the element at index i 
 */
public float getArrayFloat(int i) {
   return ((FloatArray)(_getFeatureValueNc(wrapGetIntCatchException(_FH_arrayFloat)))).get(i);}
 
Example #27
Source File: Root.java    From uima-uimaj with Apache License 2.0 2 votes vote down vote up
/** indexed setter for arrayFloat - sets an indexed value - 
 * @generated
 * @param i index in the array to set
 * @param v value to set into the array 
 */
public void setArrayFloat(int i, float v) {
  ((FloatArray)(_getFeatureValueNc(wrapGetIntCatchException(_FH_arrayFloat)))).set(i, v);
}