Java Code Examples for org.apache.uima.jcas.cas.TOP#_getTypeImpl

The following examples show how to use org.apache.uima.jcas.cas.TOP#_getTypeImpl . 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: XCASSerializer.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
private void encodeFeatures(TOP fs, AttributesImpl attrs) {
  TypeImpl ti = fs._getTypeImpl();
  
  for (FeatureImpl fi : ti.getFeatureImpls()) {
    String attrValue;
    if (fi.getRangeImpl().isRefType) {
      TOP v = fs.getFeatureValue(fi);
      attrValue = (null == v) ? null : Integer.toString(v._id);
    } else {
      attrValue = fs.getFeatureValueAsString(fi);
    }
    if (attrValue != null) {
      addAttribute(attrs, featureNames[fi.getCode()], attrValue);
    }
  }
}
 
Example 2
Source File: BinaryCasSerDes4.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * For delta, for each fsChange element, extract any strings
 * @param fsChange
 */
private void extractStringsFromModifications(FsChange fsChange) {
  final TOP fs = fsChange.fs;
  final TypeImpl type = fs._getTypeImpl();
  if (fsChange.arrayUpdates != null) {
    if (type.getComponentSlotKind() == SlotKind.Slot_StrRef) {
      String[] sa = ((StringArray)fs)._getTheArray();  
      fsChange.arrayUpdates.forAllInts(index -> {
        os.add(sa[index]);
      });
    } // end of is string array
  } else { // end of is array
    BitSet fm = fsChange.featuresModified;
    for (int offset = fm.nextSetBit(0); offset >= 0; offset = fm.nextSetBit(offset + 1)) {
      FeatureImpl feat = type.getFeatureImpls()[offset];
      if (feat.getSlotKind() == SlotKind.Slot_StrRef) {
        os.add(fs._getStringValueNc(feat));
      }
    } // end of iter over features
  } // end of is-not-array
}
 
Example 3
Source File: BinaryCasSerDes4.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
private void writeFs(TOP fs) throws IOException {
      TypeImpl type = fs._getTypeImpl();
      int typeCode = type.getCode();
      writeVnumber(typeCode_dos, typeCode);
      
      prevFs = prevFsByType[typeCode];            

      if (type.isArray()) {
        serializeArray(fs);
      } else {
        for (FeatureImpl feat : type.getFeatureImpls()) {
          serializeByKind(fs, feat);
        }
      }
    
      prevFsByType[typeCode] = fs;
//      if (doMeasurement) {
//        sm.statDetails[typeCode_i].incr(DataIO.lengthVnumber(tCode));
//        sm.mainHeapFSs ++;
//      }
    }
 
Example 4
Source File: BinaryCasSerDes4.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * add strings to the optimizestrings object
  * 
 * If delta, only process for fs's that are new; 
 * modified string values picked up when scanning FsChange items
 * @param fs feature structure
 */
private void extractStrings(TOP fs) {
  if (isDelta && !mark.isNew(fs)) {
    return;
  }
  TypeImpl type = fs._getTypeImpl();
 
  if (type.isArray()) {
    if (type.getComponentSlotKind() == SlotKind.Slot_StrRef) {
      for (String s : ((StringArray)fs)._getTheArray()) {
        os.add(s);
      }
    }
  } else {  // end of is-array        
    for (FeatureImpl feat : type.getFeatureImpls()) {
      if (feat.getSlotKind() == SlotKind.Slot_StrRef) {
        os.add(fs._getStringValueNc(feat));
      }
    } // end of iter over all features
  } // end of if-is-not-array
}
 
Example 5
Source File: XCASSerializer.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
private void enqueueFeatures(TOP fs, int heapValue) {
  TypeImpl ti = fs._getTypeImpl();
  
  if (fs instanceof UimaSerializable) {
    ((UimaSerializable)fs)._save_to_cas_data();
  }
  for (FeatureImpl fi : ti.getFeatureImpls()) {
    if (fi.getRangeImpl().isRefType) {
      TOP v = fs.getFeatureValue(fi);
      if (null != v) {
        enqueue(v);
      }
    }
  }
}
 
Example 6
Source File: BinaryCasSerDes6.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
   * serialize one feature structure, which is
   *   guaranteed not to be null
   *   guaranteed to exist in target if there is type mapping
   * Caller iterates over target slots, but the feat arg is for the corresponding src feature
   * @param fs the FS whose slot "feat" is to be serialize
   * @param feat the corresponding source feature slot to serialize
   * @throws IOException
   */
  private void serializeByKind(TOP fs, FeatureImpl feat) throws IOException {
    SlotKind kind = feat.getSlotKind();
    switch (kind) {
    //Slot_Int, Slot_Float, Slot_Boolean, Slot_Byte, Slot_Short
    case Slot_Short:     serializeDiffWithPrevTypeSlot(kind, fs, feat, fs._getShortValueNc(feat));       break;
    case Slot_Int:       serializeDiffWithPrevTypeSlot(kind, fs, feat, fs._getIntValueNc(feat));         break;
    case Slot_HeapRef:
//      if ()
      serializeDiffWithPrevTypeSlot(kind, fs, feat, getTgtSeqFromSrcFS(fs._getFeatureValueNc(feat))); 
      break;
    case Slot_Float:     writeFloat(CASImpl.float2int(fs._getFloatValueNc(feat)));                       break;
    case Slot_Boolean:   byte_dos.write(fs._getBooleanValueNc(feat) ? 1 : 0);                            break;
    case Slot_Byte:      byte_dos.write(fs._getByteValueNc(feat));                                       break;
    case Slot_StrRef:    writeString(fs._getStringValueNc(feat));                                        break;
    case Slot_LongRef:
      final TypeImpl ti = fs._getTypeImpl();
      final int offset = feat.getOffset();
      final long prevLong = getPrevLongValue(ti.getCode(), offset);
      final long vLong = fs._getLongValueNc(feat);
      writeLong(vLong, prevLong);
      updatePrevLongValue(ti, offset, vLong);
      break;
      
    case Slot_DoubleRef: writeDouble(Double.doubleToRawLongBits(fs._getDoubleValueNc(feat)));            break;
    default: 
      throw new RuntimeException("internal error");
    } // end of switch
  }
 
Example 7
Source File: BinaryCasSerDes6.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
private void serializeModifiedFSs() throws IOException {
      int nbrModifiedFSWritten = 0;
      // iterate over all modified feature structures
      int prevHeapSeq = 0;
      final int splitPoint = mark.nextFSId;
      for (FsChange fsChange : modifiedFSs) {
        final TOP fs = fsChange.fs;
        final TypeImpl srcType = fs._getTypeImpl();
        if (isTypeMapping && typeMapper.mapTypeSrc2Tgt(srcType) == null) {
          continue;  // skip - type is not in target
        }
        final int id= fs._id;
        // perhaps part of this if test is not needed:
        //   the id is probably guaranteed to be below the split point
        //   because logging doesn't happen unless a change is below the mark
        if ((id >= splitPoint && !foundFSs.contains(id)) ||
            (id < splitPoint && !foundFSsBelowMark.contains(id))) {
          // although it was modified, it isn't going to be serialized because
          //   it isn't indexed or referenced
          continue;
        }
        
        int v = fsStartIndexes.getTgtSeqFromSrcAddr(id);
        assert (v != -1);
//        System.out.format("debug ser mod, fsid: %,d after map %,d%n", id, v);
        // no isUpdatePrevOK here, to match what was serialized
        prevHeapSeq = writeDiff(fsIndexes_i, v, prevHeapSeq);
        writeModsForOneFs(fsChange);
      
        nbrModifiedFSWritten ++;
      }  // end of for loop over all modified FSs

      if (TRACE_MOD_SER) {
        System.out.format("trace writing mods, length mod list: %,d nbr written: %,d%n",
          modifiedFSs.length, nbrModifiedFSWritten);
      }

      // write out number of modified Feature Structures
      writeVnumber(control_dos, nbrModifiedFSWritten);
    }
 
Example 8
Source File: BinaryCasSerDes6.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Serializing:
 *   Called at beginning of serialize, scans whole CAS or just delta CAS
 *   If doing delta serialization, fsStartIndexes is passed in, pre-initialized with a copy of the map info below the line.
 */
private void initSrcTgtIdMapsAndStrings() {
     
  int nextTgtId = isSerializingDelta ? mark.nextFSId : 1;
  
  // for delta serialization - the iterator is only for things above the line.

  for (TOP fs : fssToSerialize) {
    TypeImpl srcType = fs._getTypeImpl();
    TypeImpl tgtType = isTypeMapping ? typeMapper.mapTypeSrc2Tgt(srcType) : srcType;
    final boolean isIncludedType = (tgtType != null);
    
    fsStartIndexes.addItemId(fs, nextTgtId, isIncludedType);  // maps src heap to tgt seq
    
    if (isIncludedType) {
      if (fs instanceof UimaSerializable) {
        ((UimaSerializable)fs)._save_to_cas_data();
      }
      // for features in type - 
      //    strings: accumulate those strings that are in the target, if optimizeStrings != null
      //      strings either in array, or in individual values
      //    byte (array), short (array), long/double (instance or array): record if entries in aux array are skipped
      //      (not in the target).  Note the recording will be in a non-ordered manner (due to possible updates by
      //       previous delta deserialization)

      // add strings for included types (only when serializing)
      if (os != null) { 
        addStringsFromFS(fs);
      }

      // Advance to next Feature Structure, in both source and target heap frame of reference
      nextTgtId ++;
    }
  }
}
 
Example 9
Source File: BinaryCasSerDes4.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
private void readModifiedFSs() throws IOException {
        final int modFSsLength = readVnumber(control_dis);
        int iPrevHeap = 0;
                 
        for (int i = 0; i < modFSsLength; i++) {
          iHeap = readVnumber(fsIndexes_dis) + iPrevHeap;
          // convention for a skipped entry: written as 0
          boolean isSkippedEntry = iHeap == iPrevHeap;
          if (isSkippedEntry) {
            continue;
          } else {
            iPrevHeap = iHeap;
          }
          TOP fs = csds.addr2fs.get(iHeap);
          assert(fs != null);
          TypeImpl type = fs._getTypeImpl();
                    
          final int numberOfModsInThisFs = readVnumber(fsIndexes_dis); 
  
          /**************************************************
           * handle aux byte, short, long array modifications
           **************************************************/
          if (type.isArray() && (!type.isHeapStoredArray())) {
            readModifiedAuxHeap(numberOfModsInThisFs, fs, type);
          } else {
            // https://issues.apache.org/jira/browse/UIMA-4100
            // see if any of the mods are keys
//            baseCas.removeFromCorruptableIndexAnyView(iHeap, indexToDos);
            try {
              readModifiedMainHeap(numberOfModsInThisFs, fs, type);
            } finally {
              baseCas.addbackSingle(fs);
            }
          }
        }
      }
 
Example 10
Source File: CASImpl.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Convert base FS to Pear equivalent
 * 3 cases:
 *   1) no trampoline needed, no conversion, return the original fs
 *   2) trampoline already exists - return that one
 *   3) create new trampoline
 * @param aFs
 * @return
 */
static <T extends FeatureStructure> T pearConvert(T aFs) {
  if (null == aFs) {
    return null;
  }
  final TOP fs = (TOP) aFs;
  final CASImpl view = fs._casView;
  final TypeImpl ti = fs._getTypeImpl();
  final FsGenerator3 generator = view.svd.generators[ti.getCode()];
  if (null == generator) {
    return aFs;
  }
  return (T) view.pearConvert(fs, generator);
}
 
Example 11
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));
//        }
//      }
//    }
  }
 
Example 12
Source File: CasCompare.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
/**
 * To work with Java sort, must implement the comparator contract:
 *   - compare(x, y) must be opposite compare(y, x)
 *   - compare(x, y) < 0 && compare(y, z) < 0 implies compare(x, z) < 0
 *   - compare(x, y) == 0 implies compare(x, z) same as compare(y, z) for any z
 * 
 * Inner part of compareRefs; that other method adds: 
 *   null-check
 *   type-mapping skips
 *   loop determination 
 *   
 * If not in a sort context, a miscompare generates messaging information.
 *   
 * @param callerTi - the type of another FS referencing this one, or null, used in congruence set testing
 * @param callerFi - the feature of the another FS referencing this one, or null, used in congruence set testing
 * 
 * @return the compare result
 * 
 */
private int compareFss(TOP fs1, TOP fs2, TypeImpl callerTi, FeatureImpl callerFi) {
 
  if (fs1 == fs2) {
    return 0;
  }
  
  TypeImpl ti1 = fs1._getTypeImpl();
  TypeImpl ti2 = fs2._getTypeImpl();  // even if not type mapping, may be "equal" but not ==
  int r = 0;
  
  if (!inSortContext && isTypeMapping) {
    ti2 = typeMapper.mapTypeTgt2Src(ti2);
  }

  r = ti1.compareTo(ti2);
  if (r != 0) {
    if (!inSortContext) {
      mismatchFs(fs1, fs2, "Different Types", callerTi, callerFi); // types mismatch
    }
    return r;
  }
 
  if (isCompareIds && !inSortContext) {
    if (fs1._id < maxId1 && fs2._id < maxId2 && fs1._id != fs2._id) {
      mismatchFs(fs1, fs2, "IDs miscompare", callerTi, callerFi);        
      return Integer.compare(fs1._id, fs2._id);
    }
  }

  if (ti1.isArray()) {
    return compareFssArray(fs1, fs2, callerTi, callerFi);
  } 

  FeatLists featLists = type2featLists.get(ti1);
  if (featLists == null) {
    type2featLists.put(ti1, featLists = computeFeatLists(ti1));
  }

  // compare features, non-refs first (for performance)
  for (FeatureImpl[] featSet : featLists.featsByEase) {
    for (FeatureImpl fi1 : featSet) {
      if (0 != (r = compareFeature(fs1, fs2, ti1, fi1))) {
        if (! inSortContext && IS_DEBUG_STOP_ON_MISCOMPARE) {
          System.out.println("debug stop feature miscompare " + fi1.getName());
        }
        return r;
      }
    } 
  }
  return 0;
}
 
Example 13
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 14
Source File: BinaryCasSerDes4.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
private void serializeModifiedFSs() throws IOException {
  
  int iPrevAddr = 0; 
  
  FsChange[] fsChanges = baseCas.getModifiedFSList();  
  // write out number of modified Feature Structures
  writeVnumber(control_dos, fsChanges.length);
  // iterate over all modified feature structures
  /**
   * Theorems about these data
   *   1) Assumption: if an AuxHeap array is modified, its heap FS is in the list of modFSs
   *   2) FSs with AuxHeap values have increasing ref values into the Aux heap as FS addr increases
   *      (because the ref is not updateable).
   *   3) Assumption: String array element modifications are main heap slot changes
   *      and recorded as such
   */

  for (FsChange fsChange : fsChanges) {
    
    TOP fs = fsChange.fs;
    TypeImpl ti = fs._getTypeImpl();
    final int addr = csds.fs2addr.get(fs);
    if (addr == 0) { // https://issues.apache.org/jira/browse/UIMA-5194
      // need to write a dummy entry because we already outputted the number of changes
      writeVnumber(fsIndexes_dos, 0);
      // don't update iPrevAddr  
      // NOTE: modify corresponding deserialization code to detect this convention
      continue;
    }
    // write out the address of the modified FS
    writeVnumber(fsIndexes_dos, addr - iPrevAddr);
    // delay updating iPrevAddr until end of "for" loop
    
    /**************************************************
     * handle aux byte, short, long array modifications
     **************************************************/
    if (ti.isArray() && !ti.isHeapStoredArray()) {
      writeAuxHeapMods(fsChange);           
    } else { 
      writeMainHeapMods(fsChange); 
    }  // end of processing 1 modified FS
    iPrevAddr = addr;
  }  // end of for loop over all modified FSs
}
 
Example 15
Source File: CASImpl.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
FsChange(TOP fs) {
  this.fs = fs;
  TypeImpl ti = fs._getTypeImpl();
  featuresModified = (ti.highestOffset == -1) ? null : new BitSet(ti.highestOffset + 1); 
  arrayUpdates = (ti.isArray()) ? new PositiveIntSet_impl() : null;
}
 
Example 16
Source File: XCASDeserializer.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
private void handleFeature(TOP fs, String featName, String featVal, boolean lenient)
        throws SAXParseException {
  Type type = fs._getTypeImpl();
  handleFeature(type, fs, featName, featVal, lenient);
}
 
Example 17
Source File: BinaryCasSerDes6.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
private void readModifiedFSs() throws IOException {
      final int modFSsLength = readVnumber(control_dis);
      if (TRACE_MOD_DES) {
        System.out.format("trace des mod nbr mods = %,d%n", modFSsLength);
      }
      int prevSeq = 0;
      
      if ((modFSsLength > 0) && (allowPreexistingFS == AllowPreexistingFS.disallow)) {
        throw new CASRuntimeException(CASRuntimeException.DELTA_CAS_PREEXISTING_FS_DISALLOWED,
           String.format("%,d pre-existing Feature Structures modified", modFSsLength));
      }
      
//        if (isTypeMapping) {
//          for (int i = 0; i < AuxHeapsCount; i++) {
//            srcHeapIndexOffset[i] = 0;
//            srcSkipIt[i] = fsStartIndexes.skips.get(i).iterator();
//            srcNextSkipped[i] = (srcSkipIt[i].hasNext()) ? srcSkipIt[i].next() : null;
//            srcNextSkippedIndex[i] = (srcNextSkipped[i] == null) ? Integer.MAX_VALUE : srcNextSkipped[i].skipIndex;
//          }
//        }
               
      for (int i = 0; i < modFSsLength; i++) {
        final int seqNbrModified = readDiff(fsIndexes_dis, prevSeq);
//          iHeap = readVnumber(fsIndexes_dis) + prevFs;
        prevSeq = seqNbrModified;
//          prevFs = iHeap;

        TOP fs= fsStartIndexes.getSrcFsFromTgtSeq(seqNbrModified);
        if (fs == null) {
          // never happen because in the delta CAS ts system use-case, the 
          //   target is always a subset of the source
          //   due to type system merging
          throw Misc.internalError();
        }
        
        TypeImpl srcType = fs._getTypeImpl();
        if (isTypeMapping) {
          tgtF2srcF = typeMapper.getSrcFeatures(typeMapper.mapTypeSrc2Tgt(srcType));
        }
        
        final int numberOfModsInThisFs = readVnumber(fsIndexes_dis); 

        if (TRACE_MOD_DES) {
          System.out.format("  %,d tr de mod fsId: %,d nbrMods: %,d type: %s%n", 
              i, fs._id, numberOfModsInThisFs, srcType.getShortName());
        }
         if (srcType.isAuxStoredArray()) { 
          /**************************************************
           * *** This strange split is to be compatible with v2 form 6 ***
           * 
           * handle aux byte, short, long array modifications
           *   Note: boolean stored in byte array
           *   Note: strings are heap-store-arrays
           **************************************************/
           readModifiedAuxHeap(numberOfModsInThisFs, fs, srcType);
        } else {
          // https://issues.apache.org/jira/browse/UIMA-4100
//          cas.removeFromCorruptableIndexAnyView(iHeap, indexToDos);          
          readModifiedMainHeap(numberOfModsInThisFs, fs, srcType);
        }
      }
    }
 
Example 18
Source File: BinaryCasSerDes6.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
/**
     * For Delta Serialization:
     * Add any strings below the line 
     * Assume: no TS mapping (because it's delta serialization)
     * Skips a modified item if in FS that isn't reachable
     */
    private void addModifiedStrings() {
//      System.out.println("Enter addModifiedStrings");
      for (FsChange changedFs : modifiedFSs) {
        final TOP fs = (TOP) changedFs.fs;
        final TypeImpl srcType = fs._getTypeImpl();
        if (isTypeMapping && null == typeMapper.mapTypeSrc2Tgt(srcType)) {
          continue; // skip this fs - it's not in target type system
        }

        // probably don't need this test, because change logging is done when a mark is set, 
        //   only for items below the line
        if (!foundFSsBelowMark.contains(fs._id)) {
//          System.out.format("  skipping heap addr %,d%n", currentFsId);
          continue;        
        }
        if (changedFs.arrayUpdates != null) {
          if (fs instanceof StringArray) {
            String[] strings = ((StringArray)fs)._getTheArray();
            IntListIterator it = changedFs.arrayUpdates.iterator();
            while (it.hasNext()) {
              os.add(strings[it.nextNvc()]);
            }
          }
        } else {
          if (fs instanceof UimaSerializable) {
            ((UimaSerializable)fs)._save_to_cas_data();
          }
          final BitSet featuresModified = changedFs.featuresModified;
          int next = featuresModified.nextSetBit(0);
          FeatureImpl[] feats = fs._getTypeImpl().getFeatureImpls();
          while (next >= 0) {
            FeatureImpl srcFeat = feats[next];
            // add only those strings in slots that are in target type system
            if (isTypeMapping && typeMapper.getTgtFeature(srcType, srcFeat) == null) {
                continue;  // skip - feature not in target type
            }
            if (srcFeat.getRangeImpl().isStringOrStringSubtype()) {
              os.add(fs._getStringValueNc(feats[next]));
            }
            next = featuresModified.nextSetBit(next + 1);
          }
        }
      }
    }
 
Example 19
Source File: TypeSystemImpl.java    From uima-uimaj with Apache License 2.0 3 votes vote down vote up
/**
 * When deserializing Xmi and XCAS, Arrays of Feature Structures are encoded as FSArray types, but they
 * may have a more restrictive typing, e.g. arrays of Annotation, with the type code of Annotation[].
 * 
 * This is determined by the range type of the feature referring to the array instance.
 * 
 * A fixup is done when
 *   - the arrayFs is not already subtyped (could be for 0 length arrays) 
 *   - it's not disabled (for backward compatibility with v2)
 * 
 * If the feature is marked as multipleReferencesAllowed, the presumption is that all references
 * are to the same subtype. 
 * 
 * 0-length arrays are created with the proper subtype already, and won't need fixing up
 *   
 * The fixup updates the type of the Feature Structure  
 * from FSArray to the array type declared; no checking is done to insure the elements conform, however.
 */
void fixupFSArrayTypes(TypeImpl featRange, TOP arrayFs) {
  if (CASImpl.IS_DISABLE_SUBTYPE_FSARRAY_CREATION) {
    return;  // for compatibility with V2
  }
  if (arrayFs != null && featRange.isTypedFsArray() ) { // https://issues.apache.org/jira/browse/UIMA-5446
    TypeImpl array_type = arrayFs._getTypeImpl();
    if (array_type.isTypedFsArray()) {
       // don't change an already subtyped FSArray
      return;
    }
    arrayFs._setTypeImpl(featRange);  // replace more general type with more specific type
  }
}