You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by ea...@apache.org on 2007/05/19 23:40:07 UTC

svn commit: r539803 - in /incubator/uima/uimaj/trunk/uimaj-core/src: main/java/org/apache/uima/cas/impl/FSIndexComparatorImpl.java main/java/org/apache/uima/cas/impl/FSLeafIndexImpl.java test/java/org/apache/uima/cas/test/NewPrimitiveTypesTest.java

Author: eae
Date: Sat May 19 14:40:06 2007
New Revision: 539803

URL: http://svn.apache.org/viewvc?view=rev&rev=539803
Log:
UIMA-407 Enable use as per Report by Mikhail Sogrin; 
Fix bug in long as key; Add test case for keys=double, long, short.

Modified:
    incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSIndexComparatorImpl.java
    incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSLeafIndexImpl.java
    incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/NewPrimitiveTypesTest.java

Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSIndexComparatorImpl.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSIndexComparatorImpl.java?view=diff&rev=539803&r1=539802&r2=539803
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSIndexComparatorImpl.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSIndexComparatorImpl.java Sat May 19 14:40:06 2007
@@ -58,7 +58,8 @@
   }
 
   private boolean checkType(Type t) {
-    if (this.cas.isIntType(t) || this.cas.isFloatType(t) || this.cas.isStringType(t)) {
+    if (this.cas.isIntType(t) || this.cas.isFloatType(t) || this.cas.isStringType(t)
+            || this.cas.isDoubleType(t) || this.cas.isLongType(t) || this.cas.isShortType(t)) {
       return true;
     }
     return false;

Modified: incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSLeafIndexImpl.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSLeafIndexImpl.java?view=diff&rev=539803&r1=539802&r2=539803
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSLeafIndexImpl.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/main/java/org/apache/uima/cas/impl/FSLeafIndexImpl.java Sat May 19 14:40:06 2007
@@ -284,7 +284,7 @@
         }
         case LONG_CODE: {
           long long1 = this.lowLevelCAS.longHeap.getHeapValue(val1);
-          long long2 = this.lowLevelCAS.longHeap.getHeapValue(val1);
+          long long2 = this.lowLevelCAS.longHeap.getHeapValue(val2);
           if (long1 < long2) {
             if (this.keyComp[i] == FSIndexComparator.STANDARD_COMPARE) {
               return -1;

Modified: incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/NewPrimitiveTypesTest.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/NewPrimitiveTypesTest.java?view=diff&rev=539803&r1=539802&r2=539803
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/NewPrimitiveTypesTest.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/NewPrimitiveTypesTest.java Sat May 19 14:40:06 2007
@@ -48,6 +48,7 @@
 import org.apache.uima.cas.Type;
 import org.apache.uima.cas.admin.CASFactory;
 import org.apache.uima.cas.admin.CASMgr;
+import org.apache.uima.cas.admin.FSIndexComparator;
 import org.apache.uima.cas.admin.FSIndexRepositoryMgr;
 import org.apache.uima.cas.admin.TypeSystemMgr;
 import org.apache.uima.cas.impl.CASImpl;
@@ -162,8 +163,27 @@
 
       // Create the Base indexes.
       casMgr.initCASIndexes();
+
+      // create custom indexes to test new primitive keys
       FSIndexRepositoryMgr irm = casMgr.getIndexRepositoryMgr();
-      // init.initIndexes(irm, casMgr.getTypeSystemMgr());
+      FSIndexComparator comp = irm.createComparator();
+      comp.setType(tsa.getType("test.primitives.Example"));
+      comp.addKey(tsa.getFeatureByFullName("test.primitives.Example:doubleFeature"),
+          FSIndexComparator.STANDARD_COMPARE);
+      irm.createIndex(comp, "doubleIndex");
+
+      comp = irm.createComparator();
+      comp.setType(tsa.getType("test.primitives.Example"));
+      comp.addKey(tsa.getFeatureByFullName("test.primitives.Example:longFeature"),
+          FSIndexComparator.REVERSE_STANDARD_COMPARE);
+      irm.createIndex(comp, "longIndex");
+
+      comp = irm.createComparator();
+      comp.setType(tsa.getType("test.primitives.Example"));
+      comp.addKey(tsa.getFeatureByFullName("test.primitives.Example:shortFeature"),
+          FSIndexComparator.STANDARD_COMPARE);
+      irm.createIndex(comp, "shortIndex");
+
       irm.commit();
 
       cas = casMgr.getCAS().getView(CAS.NAME_DEFAULT_SOFA);
@@ -498,6 +518,60 @@
     fs.setFeatureValue(longArrayFeature, longArrayFS);
     fs.setDoubleValue(doubleFeature, Double.MAX_VALUE);
     fs.setFeatureValue(doubleArrayFeature, doubleArrayFS);
+  }
+
+  public void testNewPrimitiveTypeKeys() throws Exception {
+    // Create FS with features set in reverse order
+    for (int i=0; i<5; i++) {
+      AnnotationFS fs = cas.createAnnotation(exampleType, 0, 0);
+      fs.setDoubleValue(doubleFeature, 5.0 - i );
+      fs.setLongValue(longFeature, (long)1+i );
+      fs.setShortValue(shortFeature, (short)(5 - i) );
+      cas.getIndexRepository().addFS(fs);
+    }
+
+    // test double as key
+    FSIterator iter = cas.getIndexRepository().getIndex("doubleIndex", exampleType).iterator();
+//    System.out.println("\nDouble");
+    for (int i=0; i<5; i++) {
+      AnnotationFS testfs = (AnnotationFS)iter.get();
+//      System.out.println("exampleType has double=" + testfs.getDoubleValue(doubleFeature)
+//              + " long=" + testfs.getLongValue(longFeature)
+//              + " short=" + testfs.getShortValue(shortFeature));
+      assertTrue(1+i == testfs.getDoubleValue(doubleFeature));
+      assertTrue(5-i == testfs.getLongValue(longFeature));
+      assertTrue(1+i == testfs.getShortValue(shortFeature));
+      iter.moveToNext();
+    }
+
+    // test long as key
+    iter = cas.getIndexRepository().getIndex("longIndex", exampleType).iterator();
+//    System.out.println("\nLong");
+    for (int i=0; i<5; i++) {
+      AnnotationFS testfs = (AnnotationFS)iter.get();
+//      System.out.println("exampleType has double=" + testfs.getDoubleValue(doubleFeature)
+//              + " long=" + testfs.getLongValue(longFeature)
+//              + " short=" + testfs.getShortValue(shortFeature));
+      assertTrue(1+i == testfs.getDoubleValue(doubleFeature));
+      assertTrue(5-i == testfs.getLongValue(longFeature));
+      assertTrue(1+i == testfs.getShortValue(shortFeature));
+      iter.moveToNext();
+    }
+
+    // test short as key
+    iter = cas.getIndexRepository().getIndex("shortIndex", exampleType).iterator();
+//    System.out.println("\nShort");
+    for (int i=0; i<5; i++) {
+      AnnotationFS testfs = (AnnotationFS)iter.get();
+//      System.out.println("exampleType has double=" + testfs.getDoubleValue(doubleFeature)
+//              + " long=" + testfs.getLongValue(longFeature)
+//              + " short=" + testfs.getShortValue(shortFeature));
+      assertTrue(1+i == testfs.getDoubleValue(doubleFeature));
+      assertTrue(5-i == testfs.getLongValue(longFeature));
+      assertTrue(1+i == testfs.getShortValue(shortFeature));
+      iter.moveToNext();
+    }
+
   }
 
   // public void testUimaTypeSystem2Ecore() throws Exception