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/10/21 17:54:26 UTC
svn commit: r1709869 - in /uima/ruta/trunk/ruta-core/src:
main/java/org/apache/uima/ruta/rule/RuleMatch.java
test/java/org/apache/uima/ruta/DisjunctiveRuleElementTest.java
Author: pkluegl
Date: Wed Oct 21 15:54:26 2015
New Revision: 1709869
URL: http://svn.apache.org/viewvc?rev=1709869&view=rev
Log:
UIMA-4592
- fixed wrong last annotation
Added:
uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/DisjunctiveRuleElementTest.java (with props)
Modified:
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleMatch.java
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleMatch.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleMatch.java?rev=1709869&r1=1709868&r2=1709869&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleMatch.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleMatch.java Wed Oct 21 15:54:26 2015
@@ -20,7 +20,6 @@
package org.apache.uima.ruta.rule;
import java.util.ArrayList;
-import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -37,22 +36,10 @@ import org.apache.uima.ruta.engine.RutaE
public class RuleMatch extends AbstractRuleMatch<RutaRule> {
- private static class RuleMatchComparator implements Comparator<RuleElementMatch> {
-
- public int compare(RuleElementMatch rem1, RuleElementMatch rem2) {
- AnnotationFS fs1 = rem1.getTextsMatched().get(0);
- AnnotationFS fs2 = rem2.getTextsMatched().get(0);
-
- return fs1.getBegin() < fs2.getBegin() ? -1 : 1;
- }
- }
-
private boolean applied = false;
private Map<RutaElement, ScriptApply> delegateApply;
- // private Map<RuleElement, List<RuleElementMatch>> map;
-
private ComposedRuleElementMatch rootMatch;
public RuleMatch(RutaRule rule) {
@@ -79,9 +66,21 @@ public class RuleMatch extends AbstractR
}
}
if (direction) {
- return matchedAnnotations.get(matchedAnnotations.size() - 1);
+ AnnotationFS matched = matchedAnnotations.get(matchedAnnotations.size() - 1);
+ if(annotation != null && matched.getEnd() < annotation.getEnd()) {
+ // multiple matches, but none last time
+ return annotation;
+ } else {
+ return matched;
+ }
} else {
- return matchedAnnotations.get(0);
+ AnnotationFS matched = matchedAnnotations.get(0);
+ if(annotation != null && matched.getBegin() > annotation.getBegin()) {
+ // multiple matches, but none last time
+ return annotation;
+ } else {
+ return matched;
+ }
}
}
Added: uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/DisjunctiveRuleElementTest.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/DisjunctiveRuleElementTest.java?rev=1709869&view=auto
==============================================================================
--- uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/DisjunctiveRuleElementTest.java (added)
+++ uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/DisjunctiveRuleElementTest.java Wed Oct 21 15:54:26 2015
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.ruta;
+
+import org.apache.uima.cas.CAS;
+import org.apache.uima.ruta.engine.Ruta;
+import org.apache.uima.ruta.engine.RutaTestUtils;
+import org.junit.Test;
+
+public class DisjunctiveRuleElementTest {
+
+ @Test
+ public void testOptionalDisjunctiveInMinMax() {
+ String document = ". Cw 1 2:3,4 sw . Cw 1 sw . Cw 1:2, sw . Cw 1,2,3,4,5,6,7 sw";
+
+ String script = "PERIOD CW (NUM{-> T1} (COMMA | SEMICOLON | COLON)?)[1,5] SW{-> T2};";
+ CAS cas = null;
+ try {
+ cas = RutaTestUtils.getCAS(document);
+ Ruta.apply(cas, script);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ RutaTestUtils.assertAnnotationsEquals(cas, 1, 7, "1", "2", "3", "4", "1", "1", "2");
+ RutaTestUtils.assertAnnotationsEquals(cas, 2, 3, "sw", "sw", "sw");
+
+ cas.release();
+ }
+}
Propchange: uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/DisjunctiveRuleElementTest.java
------------------------------------------------------------------------------
svn:eol-style = native