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 2014/02/07 10:36:31 UTC
svn commit: r1565595 - in /uima/ruta/trunk/ruta-core/src:
main/java/org/apache/uima/ruta/condition/PartOfNeqCondition.java
test/java/org/apache/uima/ruta/condition/PartOfNEQ2Test.java
Author: pkluegl
Date: Fri Feb 7 09:36:31 2014
New Revision: 1565595
URL: http://svn.apache.org/r1565595
Log:
UIMA-3604
- PARTOFNEQ is now sensible to type hierarchy
- added test
Added:
uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/condition/PartOfNEQ2Test.java (with props)
Modified:
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/PartOfNeqCondition.java
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/PartOfNeqCondition.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/PartOfNeqCondition.java?rev=1565595&r1=1565594&r2=1565595&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/PartOfNeqCondition.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/PartOfNeqCondition.java Fri Feb 7 09:36:31 2014
@@ -63,6 +63,13 @@ public class PartOfNeqCondition extends
}
private boolean check(AnnotationFS annotation, RutaStream stream, Type t) {
+ RutaBasic beginAnchor = stream.getBeginAnchor(annotation.getBegin());
+ RutaBasic endAnchor = stream.getEndAnchor(annotation.getEnd());
+ boolean partOf = beginAnchor.isPartOf(t) || endAnchor.isPartOf(t);
+ if (!partOf) {
+ return false;
+ }
+
try {
stream.moveTo(annotation);
} catch (Exception e) {
@@ -70,13 +77,15 @@ public class PartOfNeqCondition extends
while (stream.isValid()) {
RutaBasic each = (RutaBasic) stream.get();
Collection<AnnotationFS> set = each.getBeginAnchors(t);
+ // TODO: maybe faster to move in the other direction?
if (set == null) {
stream.moveToPrevious();
continue;
}
for (AnnotationFS afs : set) {
if (afs != null
- && afs.getType().equals(t)
+ && (afs.getType().equals(t) || stream.getCas().getTypeSystem()
+ .subsumes(t, afs.getType()))
&& ((afs.getBegin() < annotation.getBegin() && afs.getEnd() > annotation.getEnd())
|| (afs.getBegin() == annotation.getBegin() && afs.getEnd() > annotation
.getEnd()) || (afs.getBegin() < annotation.getBegin() && afs
Added: uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/condition/PartOfNEQ2Test.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/condition/PartOfNEQ2Test.java?rev=1565595&view=auto
==============================================================================
--- uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/condition/PartOfNEQ2Test.java (added)
+++ uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/condition/PartOfNEQ2Test.java Fri Feb 7 09:36:31 2014
@@ -0,0 +1,91 @@
+/*
+ * 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.condition;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.Map;
+import java.util.TreeMap;
+
+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.ruta.RutaTestUtils;
+import org.apache.uima.ruta.engine.Ruta;
+import org.junit.Test;
+
+public class PartOfNEQ2Test {
+
+ @Test
+ public void test() {
+ String document = "> 51%";
+ String script = "";
+ script += "\"> 51%\" -> Leaf1;\n";
+ script += "\"51%\" -> Leaf2;\n";
+ script += "Base{PARTOFNEQ(Base) -> UNMARK(Base)};\n";
+
+ Map<String, String> complexTypes = new TreeMap<String, String>();
+ String typeName1 = "uima.ruta.Base";
+ complexTypes.put(typeName1, "uima.tcas.Annotation");
+ String typeName2 = "uima.ruta.Leaf1";
+ complexTypes.put(typeName2, typeName1);
+ String typeName3 = "uima.ruta.Leaf2";
+ complexTypes.put(typeName3, typeName1);
+
+ CAS cas = null;
+ try {
+ cas = RutaTestUtils.getCAS(document, complexTypes, null);
+ Ruta.apply(cas, script);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ Type t = null;
+ AnnotationIndex<AnnotationFS> ai = null;
+ FSIterator<AnnotationFS> iterator = null;
+
+ t = cas.getTypeSystem().getType(typeName2);
+ ai = cas.getAnnotationIndex(t);
+ for (AnnotationFS each : ai) {
+ System.out.println(each.getCoveredText());
+ }
+
+ t = cas.getTypeSystem().getType(typeName3);
+ ai = cas.getAnnotationIndex(t);
+ for (AnnotationFS each : ai) {
+ System.out.println(each.getCoveredText());
+ }
+
+ t = cas.getTypeSystem().getType(typeName1);
+ ai = cas.getAnnotationIndex(t);
+ assertEquals(1, ai.size());
+ iterator = ai.iterator();
+ assertEquals("> 51%", iterator.next().getCoveredText());
+
+
+ if (cas != null) {
+ cas.release();
+ }
+
+ }
+
+}
Propchange: uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/condition/PartOfNEQ2Test.java
------------------------------------------------------------------------------
svn:eol-style = native