Java Code Examples for org.apache.uima.jcas.cas.Sofa#setLocalSofaData()

The following examples show how to use org.apache.uima.jcas.cas.Sofa#setLocalSofaData() . 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: XCASDeserializer.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Common code run at finalize time, to set ref values and handle out-of-typesystem data
 * 
 * @param extId the external ID identifying either a deserialized FS or an out-of-typesystem instance
 * @param fs Feature Structure whose fi reference feature is to be set with a value derived from extId and FSinfo
 * @param fi the featureImpl
*/
private void finalizeRefValue(int extId, TOP fs, FeatureImpl fi) {
  FSInfo fsInfo = fsTree.get(extId);
  if (fsInfo == null) {

    // this feature may be a ref to an out-of-typesystem FS.
    // add it to the Out-of-typesystem features list (APL)
    if (extId != 0 && outOfTypeSystemData != null) {
      List<Pair<String, Object>> ootsAttrs = outOfTypeSystemData.extraFeatureValues.computeIfAbsent(fs, k -> new ArrayList<>());
      String featFullName = fi.getName();
      int separatorOffset = featFullName.indexOf(TypeSystem.FEATURE_SEPARATOR);
      String featName = "_ref_" + featFullName.substring(separatorOffset + 1);
      ootsAttrs.add(new Pair(featName, Integer.toString(extId)));
    }
    CASImpl.setFeatureValueMaybeSofa(fs, fi, null);
  } else {
    // the sofa ref in annotationBase is set when the fs is created, not here
    if (fi.getCode() != TypeSystemConstants.annotBaseSofaFeatCode) { 
      if (fs instanceof Sofa) {
        // special setters for sofa values
        Sofa sofa = (Sofa) fs;
        switch (fi.getRangeImpl().getCode()) {
        case TypeSystemConstants.sofaArrayFeatCode: sofa.setLocalSofaData(fsInfo.fs); break;
        default: throw new CASRuntimeException(UIMARuntimeException.INTERNAL_ERROR);
        }
        return;
      }
      
      // handle case where feature is xyz[] (an array ref, not primitive) but the value of fs is FSArray
      ts.fixupFSArrayTypes(fi.getRangeImpl(), fsInfo.fs);
      CASImpl.setFeatureValueMaybeSofa(fs, fi, fsInfo.fs);
    }
  }
}
 
Example 2
Source File: BinaryCasSerDes.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * @param fs
 * @param feat
 * @param s
 * @param fixups4forwardFsRefs
 * @return true if caller needs to do an appropriate fs._setStringValue...
 */
private boolean updateStringFeature(TOP fs, FeatureImpl feat, String s, List<Runnable> fixups4forwardFsRefs) {
  if (null == s) {
    return false;  // null is the default value, no need to set it
  }
  if (fs instanceof Sofa) {
    if (feat == tsi.sofaId) {
      return false;  // do nothing, this value was already used
    }
    Sofa sofa = (Sofa)fs;
    if (feat == tsi.sofaMime) {
      sofa.setMimeType(s);
      return false;
    }
    if (feat == tsi.sofaUri) {
      sofa.setRemoteSofaURI(s);
      return false;
    }
    if (feat == tsi.sofaString) {
      if (fixups4forwardFsRefs != null) {
        // has to be deferred because it updates docAnnot which might not be deser yet.
        //   TODO no longer needed, calls the version which doesn't update docAnnot 9/2017
        Sofa capturedSofa = sofa;
        String capturedString = s;
        fixups4forwardFsRefs.add(() -> capturedSofa.setLocalSofaDataNoDocAnnotUpdate(capturedString));
      } else {
        sofa.setLocalSofaData(s);
      }
      return false;
    }
  }
  return true; //    fs._setStringValueNcNj(feat, s);
}
 
Example 3
Source File: CASImpl.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
/**
   * Supports setting slots to "0" for null values
   * @param fs The feature structure to update
   * @param feat the feature to update-
   * @param s the string representation of the value, could be null
   */
  public static void setFeatureValueFromString(FeatureStructureImplC fs, FeatureImpl feat, String s) {
    final TypeImpl range = feat.getRangeImpl();
    if (fs instanceof Sofa) {
      // sofa has special setters
      Sofa sofa = (Sofa) fs;
      switch (feat.getCode()) {
      case sofaMimeFeatCode : sofa.setMimeType(s); break;
      case sofaStringFeatCode: sofa.setLocalSofaData(s); break;
      case sofaUriFeatCode: sofa.setRemoteSofaURI(s); break;
      default: // left empty - ignore trying to set final fields
      }
      return;
    }
    
    if (feat.isInInt) {
      switch (range.getCode()) {
      case floatTypeCode :   fs.setFloatValue(feat, (s == null) ? 0F : Float.parseFloat(s)); break;
      case booleanTypeCode : fs.setBooleanValue(feat, (s == null) ? false : Boolean.parseBoolean(s)); break;
      case longTypeCode :    fs.setLongValue(feat, (s == null) ? 0L : Long.parseLong(s)); break;
      case doubleTypeCode :  fs.setDoubleValue(feat, (s == null) ? 0D : Double.parseDouble(s)); break;
      case byteTypeCode :  fs.setByteValue(feat, (s == null) ? 0 : Byte.parseByte(s)); break;
      case shortTypeCode :  fs.setShortValue(feat, (s == null) ? 0 : Short.parseShort(s)); break;
      case intTypeCode :  fs.setIntValue(feat, (s == null) ? 0 : Integer.parseInt(s)); break;
      default:                              fs.setIntValue(feat, (s == null) ? 0 : Integer.parseInt(s));
      }
    } else if (range.isRefType) {
      if (s == null) {
        fs.setFeatureValue(feat,  null);
      } else {
        // Setting a reference value "{0}" from a string is not supported. 
        throw new CASRuntimeException(CASRuntimeException.SET_REF_FROM_STRING_NOT_SUPPORTED, feat.getName());
      }
    } else if (range.isStringOrStringSubtype()) {  // includes TypeImplSubString
      // is String or Substring
      fs.setStringValue(feat, (s == null) ? null : s);
//    } else if (range == getTypeSystemImpl().javaObjectType) {
//      fs.setJavaObjectValue(feat, (s == null) ? null : deserializeJavaObject(s));
    } else {
      Misc.internalError();
    }    
  }