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

The following examples show how to use org.apache.uima.jcas.cas.ByteArray. 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: 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 #2
Source File: AidaDisambiguationSettings.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
/** setter for disambiguationSettingsBytes - sets  
 *
 * @param v value to set into the feature 
 */
public void setDisambiguationSettingsBytes(ByteArray v) {
  if (AidaDisambiguationSettings_Type.featOkTst && ((AidaDisambiguationSettings_Type) jcasType).casFeat_disambiguationSettingsBytes == null)
    jcasType.jcas.throwFeatMissing("disambiguationSettingsBytes", "de.mpg.mpi_inf.ambiversenlu.nlu.entitylinking.uima.type.AidaDisambiguationSettings");
  jcasType.ll_cas
      .ll_setRefValue(addr, ((AidaDisambiguationSettings_Type) jcasType).casFeatCode_disambiguationSettingsBytes, jcasType.ll_cas.ll_getFSRef(v));
}
 
Example #3
Source File: CASImpl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
@Override
public ByteArray emptyByteArray() {
    if (null == svd.emptyByteArray) {
      svd.emptyByteArray = new ByteArray(this.getJCas(), 0);
    }
    return svd.emptyByteArray;
  }
 
Example #4
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 #5
Source File: NewFeatureUtils.java    From baleen with Apache License 2.0 5 votes vote down vote up
private static ByteArray getByteArray(JCas jCas, Collection<?> list) {
  final ByteArray a = new ByteArray(jCas, list.size());
  int i = 0;
  for (final Object s : list) {
    a.set(i++, (Byte) s);
  }
  return a;
}
 
Example #6
Source File: DisambiguationSettings.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
public void addToJCas(AidaDocumentSettings ads, JCas jcas) throws IOException {
  AidaDisambiguationSettings ds = new AidaDisambiguationSettings(jcas);
  byte[] bytes = encode(this);
  ByteArray ba = new ByteArray(jcas, bytes.length);
  ba.copyFromArray(bytes, 0, 0, bytes.length);
  ba.addToIndexes();
  ds.setDisambiguationSettingsBytes(ba);
  ds.addToIndexes();
  ads.setDisambiguationSettings(ds);
}
 
Example #7
Source File: AidaDisambiguationSettings.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
/** getter for disambiguationSettingsBytes - gets 
 *
 * @return value of the feature 
 */
public ByteArray getDisambiguationSettingsBytes() {
  if (AidaDisambiguationSettings_Type.featOkTst && ((AidaDisambiguationSettings_Type) jcasType).casFeat_disambiguationSettingsBytes == null)
    jcasType.jcas.throwFeatMissing("disambiguationSettingsBytes", "de.mpg.mpi_inf.ambiversenlu.nlu.entitylinking.uima.type.AidaDisambiguationSettings");
  return (ByteArray) (jcasType.ll_cas
      .ll_getFSForRef(jcasType.ll_cas.ll_getRefValue(addr, ((AidaDisambiguationSettings_Type) jcasType).casFeatCode_disambiguationSettingsBytes)));
}
 
Example #8
Source File: FSCollectionFactory.java    From uima-uimafit with Apache License 2.0 4 votes vote down vote up
public static ByteArray createByteArray(JCas aJCas, byte... aArray) {
  return fillArray(new ByteArray(aJCas, aArray.length), aArray);
}
 
Example #9
Source File: JsonCasSerializerTest.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
private FeatureStructure setAllValues(int v) throws CASException {
  cas = (CASImpl) cas.getView(CAS.NAME_DEFAULT_SOFA);  // create the default initial view sofa.
  JCas jcas = cas.getJCas();
  boolean s1 = v == 0;
  boolean s2 = v == 1;
  FeatureStructure fs = cas.createFS(allTypesType);
  cas.addFsToIndexes(fs);

  FeatureStructure fs2 = cas.createFS(allTypesType);
  
  fs.setBooleanValue(allTypesType.getFeatureByBaseName("aBoolean"), s1 ? true : false);
  fs.setByteValue   (allTypesType.getFeatureByBaseName("aByte"), s1 ? (byte) -117 : (byte) 0);
  fs.setShortValue  (allTypesType.getFeatureByBaseName("aShort"), s1 ? (short) -112 : (short) 0);
  fs.setIntValue    (allTypesType.getFeatureByBaseName("aInteger"), s1 ? 0 : 1);
  fs.setLongValue   (allTypesType.getFeatureByBaseName("aLong"), s2 ? 4321 : 1234);
  fs.setFloatValue  (allTypesType.getFeatureByBaseName("aFloat"), s1 ?  1.3F : Float.NaN);
  fs.setDoubleValue (allTypesType.getFeatureByBaseName("aDouble"), s2 ? Float.NEGATIVE_INFINITY : 2.6);
  fs.setStringValue (allTypesType.getFeatureByBaseName("aString"),  "some \"String\"");
  fs.setFeatureValue(allTypesType.getFeatureByBaseName("aFS"),  fs2);
  
  FeatureStructure fsAboolean = cas.createBooleanArrayFS(s1 ? 1 : 0);
  ByteArray fsAbyte    = new ByteArray(jcas, s1 ? 2 : 0);
  if (s1) {
    fsAbyte.set(0, (byte) 15);
    fsAbyte.set(1,  (byte) 0xee);
  }
  FeatureStructure fsAshort   = cas.createShortArrayFS(s2 ? 2 : 0);
  FeatureStructure fsAstring  = cas.createStringArrayFS(s1 ? 1 : 0);
  
  fsa1 = cas.createFS(allTypesType);
  fsa2 = cas.createFS(allTypesType);
  fsa3 = cas.createFS(allTypesType);
  
  fsaa = new FSArray(jcas, 3);
  fsaa.set(0, fsa1);
  fsaa.set(1, fsa2);
  fsaa.set(2, fsa3);;
  
  FeatureStructure fsMrAboolean = cas.createBooleanArrayFS(1);
  FeatureStructure fsMrAbyte    = cas.createByteArrayFS(2);
  FeatureStructure fsMrAshort   = cas.createShortArrayFS(0);
  FeatureStructure fsMrAstring  = cas.createStringArrayFS(1);
  
  fs.setFeatureValue (allTypesType.getFeatureByBaseName("aArrayBoolean"), fsAboolean);
  fs.setFeatureValue (allTypesType.getFeatureByBaseName("aArrayByte"),     fsAbyte);
  fs.setFeatureValue (allTypesType.getFeatureByBaseName("aArrayShort"),    fsAshort);
  fs.setFeatureValue (allTypesType.getFeatureByBaseName("aArrayString"),   fsAstring);
  
  fs.setFeatureValue (allTypesType.getFeatureByBaseName("aArrayMrBoolean"),  fsMrAboolean);
  fs.setFeatureValue (allTypesType.getFeatureByBaseName("aArrayMrByte"),     fsMrAbyte);
  fs.setFeatureValue (allTypesType.getFeatureByBaseName("aArrayMrShort"),    fsMrAshort);
  fs.setFeatureValue (allTypesType.getFeatureByBaseName("aArrayMrString"),   fsMrAstring);

  
  FeatureStructure fsLinteger0 = cas.createFS(tsi.getType(CAS.TYPE_NAME_EMPTY_INTEGER_LIST));
  
  FeatureStructure fsLstring0  = cas.createFS(tsi.getType(CAS.TYPE_NAME_NON_EMPTY_STRING_LIST));
  FeatureStructure fsLstring1  = cas.createFS(tsi.getType(CAS.TYPE_NAME_EMPTY_STRING_LIST));
  fsLstring0.setStringValue (tsi.getFeatureByFullName(CAS.TYPE_NAME_NON_EMPTY_STRING_LIST + ":head"), "testStr");
  fsLstring0.setFeatureValue (tsi.getFeatureByFullName(CAS.TYPE_NAME_NON_EMPTY_STRING_LIST + ":tail"), fsLstring1);
  
  
  FeatureStructure fsLfs0  = cas.createFS(tsi.getType(CAS.TYPE_NAME_NON_EMPTY_FS_LIST));
  FeatureStructure fsLfs1  = cas.createFS(tsi.getType(CAS.TYPE_NAME_EMPTY_FS_LIST));
  fsLfs0.setFeatureValue (tsi.getFeatureByFullName(CAS.TYPE_NAME_NON_EMPTY_FS_LIST + ":tail"), fsLfs1);
  
  fs.setFeatureValue (allTypesType.getFeatureByBaseName("aListInteger"), fsLinteger0);
  fs.setFeatureValue (allTypesType.getFeatureByBaseName("aListString"), fsLstring0);
  fs.setFeatureValue (allTypesType.getFeatureByBaseName("aListFs"), fsLfs0);
  
  cas.addFsToIndexes(fs);
  return fs;
}
 
Example #10
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 #11
Source File: FSCollectionFactory.java    From uima-uimafit with Apache License 2.0 4 votes vote down vote up
public static ByteArray createByteArray(JCas aJCas, Collection<Byte> aCollection) {
  return fillArray(new ByteArray(aJCas, aCollection.size()), aCollection);
}
 
Example #12
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 ByteArray emptyByteArray() {
  return ((CASImpl)getLowLevelCAS()).emptyByteArray();
}
 
Example #13
Source File: CASImpl.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
@Override
public void ll_setByteArrayValue(int fsRef, int position, byte value) {
  ((ByteArray) getFsFromId_checked(fsRef)).set(position, value);
}
 
Example #14
Source File: CASImpl.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
@Override
public byte ll_getByteArrayValue(int fsRef, int position) {
  return ((ByteArray) getFsFromId_checked(fsRef)).get(position);
}
 
Example #15
Source File: CASImpl.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
@Override
public ByteArrayFS createByteArrayFS(int length) throws CASRuntimeException {
  checkArrayPreconditions(length);
  return new ByteArray(this.getJCas(), length);
}
 
Example #16
Source File: FSCollectionFactory.java    From uima-uimafit with Apache License 2.0 4 votes vote down vote up
public static ByteArray fillArray(ByteArray aArray, byte... aValues) {
  return (ByteArray) 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 ByteArray fillArray(ByteArray aArray, Iterable<Byte> aValues) {
  return (ByteArray) fillArrayFS(aArray, aValues);
}
 
Example #18
Source File: AllTypes.java    From uima-uimaj with Apache License 2.0 2 votes vote down vote up
/** indexed setter for aArrayByte - sets an indexed value - 
 * @generated
 * @param i index in the array to set
 * @param v value to set into the array 
 */
public void setAArrayByte(int i, byte v) {
  ((ByteArray)(_getFeatureValueNc(wrapGetIntCatchException(_FH_aArrayByte)))).set(i, v);
}
 
Example #19
Source File: AllTypes.java    From uima-uimaj with Apache License 2.0 2 votes vote down vote up
/** indexed getter for aArrayByte - gets an indexed value - 
 * @generated
 * @param i index in the array to get
 * @return value of the element at index i 
 */
public byte getAArrayByte(int i) {
   return ((ByteArray)(_getFeatureValueNc(wrapGetIntCatchException(_FH_aArrayByte)))).get(i);}
 
Example #20
Source File: AllTypes.java    From uima-uimaj with Apache License 2.0 2 votes vote down vote up
/** setter for aArrayByte - sets  
 * @generated
 * @param v value to set into the feature 
 */
public void setAArrayByte(ByteArray v) {
  _setFeatureValueNcWj(wrapGetIntCatchException(_FH_aArrayByte), v);
}
 
Example #21
Source File: AllTypes.java    From uima-uimaj with Apache License 2.0 2 votes vote down vote up
/** getter for aArrayByte - gets 
 * @generated
 * @return value of the feature 
 */
public ByteArray getAArrayByte() { return (ByteArray)(_getFeatureValueNc(wrapGetIntCatchException(_FH_aArrayByte)));}
 
Example #22
Source File: AllTypes.java    From uima-uimaj with Apache License 2.0 2 votes vote down vote up
/** indexed setter for aArrayMrByte - sets an indexed value - 
 * @generated
 * @param i index in the array to set
 * @param v value to set into the array 
 */
public void setAArrayMrByte(int i, byte v) {
  ((ByteArray)(_getFeatureValueNc(wrapGetIntCatchException(_FH_aArrayMrByte)))).set(i, v);
}
 
Example #23
Source File: AllTypes.java    From uima-uimaj with Apache License 2.0 2 votes vote down vote up
/** indexed getter for aArrayMrByte - gets an indexed value - 
 * @generated
 * @param i index in the array to get
 * @return value of the element at index i 
 */
public byte getAArrayMrByte(int i) {
   return ((ByteArray)(_getFeatureValueNc(wrapGetIntCatchException(_FH_aArrayMrByte)))).get(i);}
 
Example #24
Source File: AllTypes.java    From uima-uimaj with Apache License 2.0 2 votes vote down vote up
/** setter for aArrayMrByte - sets  
 * @generated
 * @param v value to set into the feature 
 */
public void setAArrayMrByte(ByteArray v) {
  _setFeatureValueNcWj(wrapGetIntCatchException(_FH_aArrayMrByte), v);
}
 
Example #25
Source File: AllTypes.java    From uima-uimaj with Apache License 2.0 2 votes vote down vote up
/** getter for aArrayMrByte - gets 
 * @generated
 * @return value of the feature 
 */
public ByteArray getAArrayMrByte() { return (ByteArray)(_getFeatureValueNc(wrapGetIntCatchException(_FH_aArrayMrByte)));}
 
Example #26
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 ByteArray
 */
default ByteArray emptyByteArray() {
  return this.getCas().emptyByteArray();
}