Package org.apache.uima.cas

Examples of org.apache.uima.cas.FeatureStructure


      return null;
    }
    if (this.svd.useFSCache) {
      // FS object cache code.
      // ***** NOTE: This code has not been maintained and may not work ******
      FeatureStructure fs = null;
      try {
        fs = this.svd.fsArray[fsRef];
      } catch (ArrayIndexOutOfBoundsException e) {
        // Do nothing. Code below will expand array as needed.
      }
View Full Code Here


      CASRuntimeException e = new CASRuntimeException(CASRuntimeException.INVALID_BASE_CAS_METHOD,
          new String[] { "createAnnotation(Type, int, int)" });
      throw e;
    }
    final TypeSystemImpl ts = this.svd.casMetadata.ts;
    FeatureStructure fs = createFS(type);
    final int addr = ll_getFSRef(fs);
    // setSofaFeat(addr, this.mySofaRef); // already done by createFS
    setFeatureValue(addr, ts.startFeatCode, begin);
    // setStartFeat(addr, begin);
    setFeatureValue(addr, ts.endFeatCode, end);
View Full Code Here

        return array.get(slot());
      }
    }

    if (AnnotationFS.class.equals(adapter)) {
      FeatureStructure fs = (FeatureStructure) getAdapter(FeatureStructure.class);

      if (fs instanceof AnnotationFS) {
        return fs;
      }
    }
View Full Code Here

          buf.append(']');
          attrs.addAttribute("", featName, featName, "CDATA", buf.toString());
        }
      } else {
        // get value as FeatureStructure
        FeatureStructure fsVal = aFS.getFeatureValue(feat);
        if (fsVal == null) {
          attrs.addAttribute("", featName, featName, "CDATA", "null");
        } else {
          // record type name as value, and covered text if it's an annotation
          StringBuffer buf = new StringBuffer();
          buf.append(fsVal.getType().getShortName());

          if (fsVal instanceof AnnotationFS) {
            buf.append(" [");
            String str = ((AnnotationFS) fsVal).getCoveredText();
            if (str.length() > 64) {
View Full Code Here

          attrVal = buf.toString();
        }
        attrs.addAttribute("", featName, featName, "CDATA", attrVal);       
      } else {
        // get value as FeatureStructure
        FeatureStructure fsVal = aFS.getFeatureValue(feat);
        if (fsVal == null) {
          attrs.addAttribute("", featName, featName, "CDATA", "null");
        } else {
          // record type name as value, and covered text if it's an annotation
          StringBuffer buf = new StringBuffer();
          buf.append(fsVal.getType().getShortName());

          if (fsVal instanceof AnnotationFS) {
            buf.append(" [");
            String str = ((AnnotationFS) fsVal).getCoveredText();
            if (str.length() > 64) {
View Full Code Here

    try {
      CAS localCas = jcas.getCas();
      Type subTok = localCas.getTypeSystem().getType("SubToken");
      Annotation a1 = new Annotation(jcas);
      a1.addToIndexes();
      FeatureStructure f1 = localCas.createFS(subTok);
      localCas.getIndexRepository().addFS(f1);

      JFSIndexRepository ir = jcas.getJFSIndexRepository();
      FSIndex index = ir.getAnnotationIndex();
      FSIterator it = index.iterator();
View Full Code Here

  public void testFSListNotPromoted() throws Exception {
    try {
      CAS localCas = jcas.getCas();
      TypeSystem ts = localCas.getTypeSystem();
      Type fsl = ts.getType("uima.cas.NonEmptyFSList");
      FeatureStructure fs = localCas.createFS(fsl);
      assertTrue(fs instanceof NonEmptyFSList);
    } catch (Exception e) {
      JUnitExtension.handleException(e);
    }
  }
View Full Code Here

    Iterator<FSIndex<FeatureStructure>> indexes = aSrcCasView.getIndexRepository().getIndexes();
    while (indexes.hasNext()) {
      FSIndex<FeatureStructure> index = indexes.next();
      Iterator<FeatureStructure> iter = index.iterator();
      while (iter.hasNext()) {
        FeatureStructure fs = iter.next();
        if (!indexedFs.contains(fs)) {
          FeatureStructure copyOfFs = copyFs2(fs);
          // If the lenient option is used, it's possible that no FS was
          // created (e.g., FS is not defined in the target CAS. So ignore
          // this FS in the source CAS and move on to the next FS.
          if (lenient && copyOfFs == null) {
            continue; // Move to the next FS in the source CAS
          }
          // otherwise, won't be null (error thrown instead)

          // check for annotations with null Sofa reference - this can happen
          // if the annotations were created with the Low Level CAS API. If the
          // Sofa reference isn't set, attempting to add the FS to the indexes
          // will fail.
          if (fs instanceof AnnotationBaseFS) {
            FeatureStructure sofa = ((AnnotationBaseFS) copyOfFs).getFeatureValue(mDestSofaFeature);
            if (sofa == null) {
              copyOfFs.setFeatureValue(mDestSofaFeature, aTgtCasView.getSofa());
            }
          }
          // also don't index the DocumentAnnotation (it's indexed by default)
View Full Code Here

    return copyFs2(aFS);
  }
 
  private FeatureStructure copyFs2(FeatureStructure aFS) {
   
    FeatureStructure copy = copyFsInner(aFS)// doesn't copy the slot values, but enqueues them
    while (!fsToDo.isEmpty()) {
      FeatureStructure copyToFillSlots = fsToDo.remove(fsToDo.size()-1);
      FeatureStructure srcToFillSlots = fsToDo.remove(fsToDo.size()-1);
      copyFeatures(srcToFillSlots, copyToFillSlots);  
    }
    return copy;
  }
View Full Code Here

  private FeatureStructure copyFsInner(FeatureStructure aFS) {
    // FS must be in the source CAS
    assert ((CASImpl) aFS.getCAS()).getBaseCAS() == mSrcBaseCas;

    // check if we already copied this FS
    FeatureStructure copy = (FeatureStructure) mFsMap.get(aFS);
    if (copy != null)
      return copy;

    // get the type of the FS
    Type srcType = aFS.getType();

    // Certain types need to be handled specially

    // Sofa - cannot be created by normal methods. Instead, we return the Sofa with the
    // same Sofa ID in the target CAS. If it does not exist it will be created.
    if (aFS instanceof SofaFS) {
      String destSofaId = getDestSofaId(((SofaFS) aFS).getSofaID());
      return getOrCreateView(mDestBaseCas, destSofaId).getSofa();
    }

    // DocumentAnnotation - instead of creating a new instance, reuse the automatically created
    // instance in the destination view.
    if (isDocumentAnnotation(aFS)) {
      String destViewName = getDestSofaId(((AnnotationFS) aFS).getView().getViewName());

      // the DocumentAnnotation could be indexed in a different view than the one being copied
      // Note: The view might not exist in the target
      //   but this is unlikely.  To have this case this would require
      //   indexing some other feature structure in this view, which, in turn,
      //   has a reference to the DocumentAnnotation FS belonging to another view
      CAS destView = getOrCreateView(mDestBaseCas, destViewName);
      FeatureStructure destDocAnnot = destView.getDocumentAnnotation();
      if (destDocAnnot != null) {  // Note: is always non-null, getDocumentAnnotation creates if not exist
        copyFeatures(aFS, destDocAnnot);
      }
      return destDocAnnot;
    }

    // Arrays - need to be created a populated differently than "normal" FS
    if (aFS.getType().isArray()) {
      copy = copyArray(aFS);
      mFsMap.put(aFS, copy);
      return copy;
    }

    // create a new FS of the same type in the target CAS
    Type destType = (mDestBaseCas.getTypeSystem() == mSrcBaseCas.getTypeSystem()) ? srcType : mDestBaseCas
        .getTypeSystem().getType(srcType.getName());
    if (destType == null) {
      // If in lenient mode, do not act on this FS. Instead just
      // return (null) to the caller and let the caller deal with this case.
      if (lenient) {
        return null; // No FS to create
      } else {
        throw new UIMARuntimeException(UIMARuntimeException.TYPE_NOT_FOUND_DURING_CAS_COPY,
            new Object[] { srcType.getName() });
      }
    }
    // We need to use the LowLevel CAS interface to create the FS, because the usual
    // CAS.createFS() call doesn't allow us to create subtypes of AnnotationBase from
    // a base CAS. In any case we don't need the Sofa reference to be automatically
    // set because we'll set it manually when in the copyFeatures method.
   
    int typeCode = mLowLevelDestCas.ll_getTypeSystem().ll_getCodeForType(destType);
    int destFsAddr = mLowLevelDestCas.ll_createFS(typeCode);
    FeatureStructure destFs = mLowLevelDestCas.ll_getFSForRef(destFsAddr);

    // add to map so we don't try to copy this more than once
    mFsMap.put(aFS, destFs);

    fsToDo.add(aFS); // order important
View Full Code Here

TOP

Related Classes of org.apache.uima.cas.FeatureStructure

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.