You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by pk...@apache.org on 2013/08/28 12:43:10 UTC

svn commit: r1518152 - in /uima/sandbox/ruta/trunk/ruta-core/src: main/java/org/apache/uima/ruta/type/ test/java/org/apache/uima/ruta/ test/resources/org/apache/uima/ruta/

Author: pkluegl
Date: Wed Aug 28 10:43:09 2013
New Revision: 1518152

URL: http://svn.apache.org/r1518152
Log:
UIMA-3212
- applied patch

Added:
    uima/sandbox/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/ShiftWithLowMemoryProfileTest.java
    uima/sandbox/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/ShiftWithLowMemoryProfileTest.ruta
    uima/sandbox/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/ShiftWithLowMemoryProfileTest.txt
Modified:
    uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/type/RutaBasic.java
    uima/sandbox/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/RutaTestUtils.java

Modified: uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/type/RutaBasic.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/type/RutaBasic.java?rev=1518152&r1=1518151&r2=1518152&view=diff
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/type/RutaBasic.java (original)
+++ uima/sandbox/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/type/RutaBasic.java Wed Aug 28 10:43:09 2013
@@ -123,7 +123,7 @@ public class RutaBasic extends Annotatio
   public Set<AnnotationFS> getEndAnchors(Type type) {
     Set<AnnotationFS> set = endMap.get(type);
     if (lowMemoryProfile) {
-      Set<AnnotationFS> result = new HashSet<AnnotationFS>(set);
+      Set<AnnotationFS> result = new HashSet<AnnotationFS>();
       if (set != null) {
         result.addAll(set);
       }

Modified: uima/sandbox/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/RutaTestUtils.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/RutaTestUtils.java?rev=1518152&r1=1518151&r2=1518152&view=diff
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/RutaTestUtils.java (original)
+++ uima/sandbox/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/RutaTestUtils.java Wed Aug 28 10:43:09 2013
@@ -25,6 +25,7 @@ import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
@@ -73,6 +74,13 @@ public class RutaTestUtils {
     return process(ruleFileName, textFileName, amount, false, false, null, null, null, null);
   }
 
+  public static CAS process(String ruleFileName, String textFileName, Map<String, Object> parameters, int amount)
+          throws URISyntaxException, IOException, InvalidXMLException,
+          ResourceInitializationException, AnalysisEngineProcessException,
+          ResourceConfigurationException {
+    return process(ruleFileName, textFileName, parameters, amount, null, null, null, null);
+  }
+
   public static CAS process(String ruleFileName, String textFileName, int amount,
           boolean dynamicAnchoring, boolean simpleGreedyForComposed,
           Map<String, String> complexTypes, String resourceDirName) throws URISyntaxException,
@@ -98,6 +106,19 @@ public class RutaTestUtils {
           String resourceDirName, CAS cas) throws URISyntaxException, IOException,
           InvalidXMLException, ResourceInitializationException, AnalysisEngineProcessException,
           ResourceConfigurationException {
+    final HashMap parameters = new HashMap();
+    parameters.put(RutaEngine.DYNAMIC_ANCHORING, dynamicAnchoring);
+    parameters.put(RutaEngine.SIMPLE_GREEDY_FOR_COMPOSED, simpleGreedyForComposed);
+
+    return process(ruleFileName, textFileName, parameters, amount, complexTypes, features, resourceDirName, cas);
+  }
+
+  public static CAS process(String ruleFileName, String textFileName, Map<String, Object> parameters,
+                            int amount,
+                            Map<String, String> complexTypes, Map<String, List<TestFeature>> features,
+                            String resourceDirName, CAS cas) throws URISyntaxException, IOException,
+          InvalidXMLException, ResourceInitializationException, AnalysisEngineProcessException,
+          ResourceConfigurationException {
     URL ruleURL = RutaTestUtils.class.getClassLoader().getResource(ruleFileName);
     File ruleFile = new File(ruleURL.toURI());
     URL textURL = RutaTestUtils.class.getClassLoader().getResource(textFileName);
@@ -141,17 +162,21 @@ public class RutaTestUtils {
     aed.getAnalysisEngineMetaData().setTypeSystem(mergeTypeSystems);
 
     AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(specifier);
-    ae.setConfigParameterValue(RutaEngine.SCRIPT_PATHS, new String[] { ruleFile.getParentFile()
-            .getPath() });
+    ae.setConfigParameterValue(RutaEngine.SCRIPT_PATHS, new String[]{ruleFile.getParentFile()
+            .getPath()});
     String name = ruleFile.getName();
     if (name.endsWith(RutaEngine.SCRIPT_FILE_EXTENSION)) {
       name = name.substring(0, name.length() - 5);
     }
+
+    for (Map.Entry<String, Object> parameter : parameters.entrySet()) {
+      ae.setConfigParameterValue(parameter.getKey(), parameter.getValue());
+    }
+
     ae.setConfigParameterValue(RutaEngine.MAIN_SCRIPT, name);
-    ae.setConfigParameterValue(RutaEngine.DYNAMIC_ANCHORING, dynamicAnchoring);
-    ae.setConfigParameterValue(RutaEngine.SIMPLE_GREEDY_FOR_COMPOSED, simpleGreedyForComposed);
+
     if (resourceFile != null) {
-      ae.setConfigParameterValue(RutaEngine.RESOURCE_PATHS, new String[] { resourceFile.getPath() });
+      ae.setConfigParameterValue(RutaEngine.RESOURCE_PATHS, new String[]{resourceFile.getPath()});
     }
 
     ae.reconfigure();

Added: uima/sandbox/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/ShiftWithLowMemoryProfileTest.java
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/ShiftWithLowMemoryProfileTest.java?rev=1518152&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/ShiftWithLowMemoryProfileTest.java (added)
+++ uima/sandbox/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/ShiftWithLowMemoryProfileTest.java Wed Aug 28 10:43:09 2013
@@ -0,0 +1,47 @@
+package org.apache.uima.ruta;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
+import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.FSIterator;
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.cas.text.AnnotationIndex;
+import org.apache.uima.resource.ResourceConfigurationException;
+import org.apache.uima.resource.ResourceInitializationException;
+import org.apache.uima.ruta.engine.RutaEngine;
+import org.apache.uima.util.InvalidXMLException;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * There was a {@link NullPointerException} when calling
+ * {@link org.apache.uima.ruta.type.RutaBasic#getEndAnchors(org.apache.uima.cas.Type)}
+ * with a type that is not annotated in the CAS when running on the low memory profile. This
+ * test ensures this bug does not come back.
+ */
+public class ShiftWithLowMemoryProfileTest {
+  @Test
+  public void testWithLowMemory() throws AnalysisEngineProcessException, InvalidXMLException, ResourceConfigurationException, IOException, URISyntaxException, ResourceInitializationException {
+    String name = this.getClass().getSimpleName();
+    String namespace = this.getClass().getPackage().getName().replaceAll("\\.", "/");
+    Map<String, Object> parameters = new HashMap<String, Object>();
+    parameters.put(RutaEngine.LOW_MEMORY_PROFILE, true);
+
+    CAS cas = RutaTestUtils.process(namespace + "/" + name + RutaEngine.SCRIPT_FILE_EXTENSION,
+            namespace + "/" + name + ".txt", parameters, 50);
+
+
+    Type t = cas.getTypeSystem().getType("org.apache.uima.ruta.type.W");
+    AnnotationIndex<AnnotationFS> ai = cas.getAnnotationIndex(t);
+    assertEquals(1, ai.size());
+    FSIterator<AnnotationFS> iterator = ai.iterator();
+    assertEquals("A", iterator.next().getCoveredText());
+    cas.release();
+  }
+}

Added: uima/sandbox/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/ShiftWithLowMemoryProfileTest.ruta
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/ShiftWithLowMemoryProfileTest.ruta?rev=1518152&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/ShiftWithLowMemoryProfileTest.ruta (added)
+++ uima/sandbox/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/ShiftWithLowMemoryProfileTest.ruta Wed Aug 28 10:43:09 2013
@@ -0,0 +1,3 @@
+PACKAGE org.apache.uima;
+
+W{->SHIFT(W, 1, 1)};
\ No newline at end of file

Added: uima/sandbox/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/ShiftWithLowMemoryProfileTest.txt
URL: http://svn.apache.org/viewvc/uima/sandbox/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/ShiftWithLowMemoryProfileTest.txt?rev=1518152&view=auto
==============================================================================
--- uima/sandbox/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/ShiftWithLowMemoryProfileTest.txt (added)
+++ uima/sandbox/ruta/trunk/ruta-core/src/test/resources/org/apache/uima/ruta/ShiftWithLowMemoryProfileTest.txt Wed Aug 28 10:43:09 2013
@@ -0,0 +1 @@
+A
\ No newline at end of file