You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by sc...@apache.org on 2014/12/12 18:41:56 UTC

svn commit: r1644991 - in /uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima: cas/impl/CASImpl.java cas/impl/FSsTobeAddedback.java util/CasCopier.java

Author: schor
Date: Fri Dec 12 17:41:55 2014
New Revision: 1644991

URL: http://svn.apache.org/r1644991
Log:
[UIMA-4135] optimize updateDocumentAnnotation, fix multiple addback case to drop the remember-er from the list in CASImpl when done, fix the CasCopier to un-index the documentat annotation before updating it, and then re-index it.

Modified:
    uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASImpl.java
    uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSsTobeAddedback.java
    uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasCopier.java

Modified: uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASImpl.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASImpl.java?rev=1644991&r1=1644990&r2=1644991&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASImpl.java (original)
+++ uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/CASImpl.java Fri Dec 12 17:41:55 2014
@@ -1693,7 +1693,7 @@ public class CASImpl extends AbstractCas
           loopIndexRep.addFS(fsIndex[i]);
         }
         loopStart += loopLen + 1;
-        ((CASImpl) view).updateDocumentAnnotation();
+          ((CASImpl) view).updateDocumentAnnotation();
       } else {
         loopStart += 1;
       }
@@ -4424,33 +4424,30 @@ public class CASImpl extends AbstractCas
   // For the "built-in" instance of Document Annotation, set the
   // "end" feature to be the length of the sofa string
   public void updateDocumentAnnotation() {
-    if (!mySofaIsValid()) {
+    if (!mySofaIsValid() || this == this.svd.baseCAS) {
       return;
     }
     final Type SofaType = this.svd.casMetadata.ts.sofaType;
     final Feature sofaString = SofaType.getFeatureByBaseName(FEATURE_BASE_NAME_SOFASTRING);
     String newDoc = getSofa(this.mySofaRef).getStringValue(sofaString);
     if (null != newDoc) {
-      getDocumentAnnotation(newDoc.length());
-    }
-  }
-
-  private AnnotationFS getDocumentAnnotation(int length) {
-    if (this == this.svd.baseCAS) {
-      // base CAS has no document
-      return null;
-    }
-    FSIterator<AnnotationFS> it = getAnnotationIndex(this.svd.casMetadata.ts.docType).iterator();
-    if (it.isValid()) {
-      AnnotationFS doc = it.get();
-      if (doc instanceof Annotation) {
-        ((Annotation)doc).setEnd(length);
+      int count = 0;
+      final FSIndexRepositoryImpl ir = (FSIndexRepositoryImpl) ll_getIndexRepository();
+      LowLevelIterator it = 
+          ir.ll_getIndex(CAS.STD_ANNOTATION_INDEX, 
+                                              this.svd.casMetadata.ts.docType.getCode()).ll_iterator();
+      if (it.isValid()) {
+        final int docAnnot = it.ll_get();
+        count = this.indexRepository.removeIfInCorrputableIndexInThisView(docAnnot);
+        setFeatureValueNoIndexCorruptionCheck(docAnnot, getTypeSystemImpl().endFeatCode, newDoc.length());
+        if (count > 0) {
+          ir.ll_addback(docAnnot, count);
+        }
       } else {
-        setFeatureValue(((AnnotationImpl)doc).addr, getTypeSystemImpl().endFeatCode, length);
+        // not in the index (yet)
+        createDocumentAnnotation(newDoc.length());
       }
-      return doc;
     }
-    return createDocumentAnnotation(length);
   }
   
   public AnnotationFS getDocumentAnnotation() {
@@ -4789,11 +4786,15 @@ public class CASImpl extends AbstractCas
    */
   @Override
   public AutoCloseable protectIndices() {
-    FSsTobeAddedback r = FSsTobeAddedback.createMultiple();
+    FSsTobeAddedback r = FSsTobeAddedback.createMultiple(this);
     svd.fssTobeAddedback.add(r);
     return r;
   }
   
+  void dropProtectIndicesLevel () {
+    svd.fssTobeAddedback.remove(svd.fssTobeAddedback.size() -1);
+  }
+  
   /**
    * This design is to support normal operations where the
    *   addbacks could be nested

Modified: uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSsTobeAddedback.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSsTobeAddedback.java?rev=1644991&r1=1644990&r2=1644991&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSsTobeAddedback.java (original)
+++ uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSsTobeAddedback.java Fri Dec 12 17:41:55 2014
@@ -180,6 +180,12 @@ abstract class FSsTobeAddedback implemen
     //   the ref to the view
     final Map<Integer, List<?>> fss2views = new HashMap<Integer, List<?>>();
     
+    final CASImpl cas;
+    
+    FSsTobeAddedbackMultiple(CASImpl cas) {
+      this.cas = cas;
+    }
+    
     @Override
     void recordRemove(int fsAddr, FSIndexRepositoryImpl view) {
       log(fsAddr, view);
@@ -202,6 +208,7 @@ abstract class FSsTobeAddedback implemen
         }
       }
       clear();
+      cas.dropProtectIndicesLevel();
     }
     
     @Override
@@ -213,6 +220,10 @@ abstract class FSsTobeAddedback implemen
   
   static class FSsTobeAddedbackMultipleCounts extends FSsTobeAddedbackMultiple {
      
+    public FSsTobeAddedbackMultipleCounts(CASImpl cas) {
+      super(cas);
+    }
+    
     @Override
     void recordRemove(int fsAddr, FSIndexRepositoryImpl view, int count) {
       log(fsAddr, view, count);
@@ -256,10 +267,10 @@ abstract class FSsTobeAddedback implemen
         new FSsTobeAddedbackSingle();
   }
   
-  public static FSsTobeAddedback createMultiple() {
+  public static FSsTobeAddedback createMultiple(CASImpl cas) {
     return (FSIndexRepositoryImpl.IS_ALLOW_DUP_ADD_2_INDICES) ?
-       new FSsTobeAddedbackMultipleCounts() :
-       new FSsTobeAddedbackMultiple();
+       new FSsTobeAddedbackMultipleCounts(cas) :
+       new FSsTobeAddedbackMultiple(cas);
   }
 }
 

Modified: uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasCopier.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasCopier.java?rev=1644991&r1=1644990&r2=1644991&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasCopier.java (original)
+++ uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/util/CasCopier.java Fri Dec 12 17:41:55 2014
@@ -463,9 +463,11 @@ public class CasCopier {
       //   has a reference to the DocumentAnnotation FS belonging to another view
       CAS destView = getOrCreateView(mOriginalTgtCasView, destViewName);
       FeatureStructure destDocAnnot = destView.getDocumentAnnotation();
+      destView.removeFsFromIndexes(destDocAnnot);  // because we're going to update it
       if (destDocAnnot != null) {  // Note: is always non-null, getDocumentAnnotation creates if not exist
         copyFeatures(aFS, destDocAnnot);
       }
+      destView.addFsToIndexes(destDocAnnot);  // add back
       return destDocAnnot;
     }