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 2015/06/25 16:14:55 UTC

svn commit: r1687528 - in /uima/ruta/trunk/ruta-core/src: main/java/org/apache/uima/ruta/RutaStream.java test/java/org/apache/uima/ruta/OutOfWindowTest.java

Author: pkluegl
Date: Thu Jun 25 14:14:54 2015
New Revision: 1687528

URL: http://svn.apache.org/r1687528
Log:
UIMA-4454
- allow out-of-window feature matches 
- but not sequential matching afterwards

Modified:
    uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java
    uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/OutOfWindowTest.java

Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java?rev=1687528&r1=1687527&r2=1687528&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java Thu Jun 25 14:14:54 2015
@@ -364,17 +364,16 @@ public class RutaStream extends FSIterat
             filter.getCurrentFilterTypes(), filter.getCurrentRetainTypes(), windowAnnotation,
             windowType, cas);
 
-    NavigableMap<Integer, RutaBasic> newBeginAnchors = beginAnchors.subMap(
-            windowAnnotation.getBegin(), true, windowAnnotation.getEnd(), false);
-    NavigableMap<Integer, RutaBasic> newEndAnchors = endAnchors.subMap(windowAnnotation.getBegin(),
-            false, windowAnnotation.getEnd(), true);
+//    NavigableMap<Integer, RutaBasic> newBeginAnchors = beginAnchors.subMap(
+//            windowAnnotation.getBegin(), true, windowAnnotation.getEnd(), false);
+//    NavigableMap<Integer, RutaBasic> newEndAnchors = endAnchors.subMap(windowAnnotation.getBegin(),
+//            false, windowAnnotation.getEnd(), true);
 
-    RutaStream stream = new RutaStream(cas, basicType, newBeginAnchors, newEndAnchors,
+    RutaStream stream = new RutaStream(cas, basicType, beginAnchors, endAnchors,
             filterManager, lowMemoryProfile, simpleGreedyForComposed, crowd);
     stream.setDynamicAnchoring(dynamicAnchoring);
     stream.setGreedyRuleElement(greedyRuleElement);
     stream.setGreedyRule(greedyRule);
-    stream.setGreedyRule(greedyRule);
     return stream;
   }
 

Modified: uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/OutOfWindowTest.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/OutOfWindowTest.java?rev=1687528&r1=1687527&r2=1687528&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/OutOfWindowTest.java (original)
+++ uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/OutOfWindowTest.java Thu Jun 25 14:14:54 2015
@@ -19,13 +19,20 @@
 
 package org.apache.uima.ruta;
 
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
 import org.apache.uima.cas.CAS;
+import org.apache.uima.ruta.engine.Ruta;
 import org.apache.uima.ruta.engine.RutaTestUtils;
+import org.apache.uima.ruta.engine.RutaTestUtils.TestFeature;
 import org.junit.Test;
 
 public class OutOfWindowTest {
   @Test
-  public void test() {
+  public void testSequentialInBlock() {
 
     CAS cas = RutaTestUtils.processTestScript(this.getClass());
 
@@ -34,4 +41,77 @@ public class OutOfWindowTest {
 
     cas.release();
   }
+  
+  @Test
+  public void testFeatureMatch() {
+    String document = "First Sentence. Second Sentence.";
+    String script = "";
+    script += "(# PERIOD){-> T1};";
+    script += "T1 #{-> T1};";
+    
+    script += "CW.ct==\"First\"{-> GATHER(Struct, \"next\" = 3)} # CW.ct==\"Second\";";
+    script += "T1->{Struct.next{REGEXP(\"Sec.*\") -> T2};};";
+    script += "T1<-{Struct.next{PARTOF(CW) -> T3};};";
+    
+    Map<String, String> complexTypes = new TreeMap<String, String>();
+    String typeName = "org.apache.uima.Struct";
+    complexTypes.put(typeName, "uima.tcas.Annotation");
+
+    Map<String, List<TestFeature>> features = new TreeMap<String, List<TestFeature>>();
+    List<TestFeature> list = new ArrayList<RutaTestUtils.TestFeature>();
+    features.put(typeName, list);
+    String fn1 = "next";
+    list.add(new TestFeature(fn1, "", "uima.tcas.Annotation"));
+    
+    CAS cas = null;
+    try {
+      cas = RutaTestUtils.getCAS(document, complexTypes, features);
+      Ruta.apply(cas, script);
+    } catch (Exception e) {
+      throw new AssertionError("No exception is expected when applying the rules.", e);
+    }
+   
+  
+    RutaTestUtils.assertAnnotationsEquals(cas, 2, 1, "Second");
+    RutaTestUtils.assertAnnotationsEquals(cas, 3, 1, "Second");
+
+    cas.release();
+  }
+  
+  @Test
+  public void testSequentialAfterOutOfWindowFeatureMatch() {
+    String document = "First Sentence. Second one.";
+    String script = "";
+    script += "(# PERIOD){-> T1};";
+    script += "T1 #{-> T1};";
+    
+    script += "CW.ct==\"First\"{-> GATHER(Struct, \"next\" = 3)} # CW.ct==\"Second\";";
+    script += "T1->{Struct.next{REGEXP(\"Sec.*\")} ANY{-> T2};};";
+    script += "T1<-{Struct.next{PARTOF(CW)} ANY{-> T3};};";
+    
+    Map<String, String> complexTypes = new TreeMap<String, String>();
+    String typeName = "org.apache.uima.Struct";
+    complexTypes.put(typeName, "uima.tcas.Annotation");
+
+    Map<String, List<TestFeature>> features = new TreeMap<String, List<TestFeature>>();
+    List<TestFeature> list = new ArrayList<RutaTestUtils.TestFeature>();
+    features.put(typeName, list);
+    String fn1 = "next";
+    list.add(new TestFeature(fn1, "", "uima.tcas.Annotation"));
+    
+    CAS cas = null;
+    try {
+      cas = RutaTestUtils.getCAS(document, complexTypes, features);
+      Ruta.apply(cas, script);
+    } catch (Exception e) {
+      throw new AssertionError("No exception is expected when applying the rules.", e);
+    }
+   
+  
+    RutaTestUtils.assertAnnotationsEquals(cas, 2, 0);
+    RutaTestUtils.assertAnnotationsEquals(cas, 3, 0);
+
+    cas.release();
+  }
+  
 }