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 2016/01/05 16:25:46 UTC
svn commit: r1723096 - in /uima/ruta/trunk/ruta-core/src:
main/java/org/apache/uima/ruta/expression/
main/java/org/apache/uima/ruta/expression/annotation/
test/java/org/apache/uima/ruta/expression/annotation/
Author: pkluegl
Date: Tue Jan 5 15:25:46 2016
New Revision: 1723096
URL: http://svn.apache.org/viewvc?rev=1723096&view=rev
Log:
UIMA-4725
- list expression for labels
Added:
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/annotation/AnnotationListLabelExpression.java (with props)
Modified:
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/MatchReference.java
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/annotation/AnnotationListFeatureExpression.java
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/annotation/AnnotationListVariableExpression.java
uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/expression/annotation/AnnotationLabelExpressionTest.java
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/MatchReference.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/MatchReference.java?rev=1723096&r1=1723095&r2=1723096&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/MatchReference.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/MatchReference.java Tue Jan 5 15:25:46 2016
@@ -26,6 +26,7 @@ import org.apache.uima.ruta.RutaBlock;
import org.apache.uima.ruta.RutaEnvironment;
import org.apache.uima.ruta.RutaStream;
import org.apache.uima.ruta.expression.annotation.AnnotationLabelExpression;
+import org.apache.uima.ruta.expression.annotation.AnnotationListLabelExpression;
import org.apache.uima.ruta.expression.annotation.AnnotationListVariableExpression;
import org.apache.uima.ruta.expression.annotation.AnnotationVariableExpression;
import org.apache.uima.ruta.expression.annotation.IAnnotationExpression;
@@ -112,6 +113,7 @@ public class MatchReference extends Ruta
RuleElement ruleElementWithLabel = ruleMatch.getRule().getRuleElementWithLabel(candidate);
if(ruleElementWithLabel != null) {
annotationExpression = new AnnotationLabelExpression(candidate);
+ annotationListExpression = new AnnotationListLabelExpression(candidate);
return true;
}
}
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/annotation/AnnotationListFeatureExpression.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/annotation/AnnotationListFeatureExpression.java?rev=1723096&r1=1723095&r2=1723096&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/annotation/AnnotationListFeatureExpression.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/annotation/AnnotationListFeatureExpression.java Tue Jan 5 15:25:46 2016
@@ -27,7 +27,6 @@ import org.apache.uima.cas.Type;
import org.apache.uima.cas.text.AnnotationFS;
import org.apache.uima.ruta.RutaStream;
import org.apache.uima.ruta.expression.feature.FeatureExpression;
-import org.apache.uima.ruta.expression.list.ListExpression;
import org.apache.uima.ruta.rule.MatchContext;
/**
Added: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/annotation/AnnotationListLabelExpression.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/annotation/AnnotationListLabelExpression.java?rev=1723096&view=auto
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/annotation/AnnotationListLabelExpression.java (added)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/annotation/AnnotationListLabelExpression.java Tue Jan 5 15:25:46 2016
@@ -0,0 +1,62 @@
+/*
+ * 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.expression.annotation;
+
+import java.util.List;
+
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.ruta.RutaStream;
+import org.apache.uima.ruta.rule.MatchContext;
+import org.apache.uima.ruta.rule.RuleMatch;
+
+/**
+ * An expression referring to an annotation matched by a rule element identified by a label.
+ *
+ */
+public class AnnotationListLabelExpression extends AbstractAnnotationListExpression {
+
+private String label;
+
+ public AnnotationListLabelExpression(String label) {
+ super();
+ this.label = label;
+ }
+
+ @Override
+ public List<AnnotationFS> getAnnotations(MatchContext context, RutaStream stream) {
+ return getList(context, stream);
+ }
+
+
+ @Override
+ public List<AnnotationFS> getList(MatchContext context, RutaStream stream) {
+ RuleMatch ruleMatch = context.getRuleMatch();
+ List<AnnotationFS> annotations = ruleMatch.getMatchedAnnotationsOfLabel(label);
+ return annotations;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+
+
+
+}
Propchange: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/annotation/AnnotationListLabelExpression.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/annotation/AnnotationListVariableExpression.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/annotation/AnnotationListVariableExpression.java?rev=1723096&r1=1723095&r2=1723096&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/annotation/AnnotationListVariableExpression.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/annotation/AnnotationListVariableExpression.java Tue Jan 5 15:25:46 2016
@@ -24,7 +24,6 @@ import java.util.List;
import org.apache.uima.cas.text.AnnotationFS;
import org.apache.uima.ruta.RutaBlock;
import org.apache.uima.ruta.RutaStream;
-import org.apache.uima.ruta.expression.list.ListExpression;
import org.apache.uima.ruta.rule.MatchContext;
public class AnnotationListVariableExpression extends AbstractAnnotationListExpression {
Modified: uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/expression/annotation/AnnotationLabelExpressionTest.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/expression/annotation/AnnotationLabelExpressionTest.java?rev=1723096&r1=1723095&r2=1723096&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/expression/annotation/AnnotationLabelExpressionTest.java (original)
+++ uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/expression/annotation/AnnotationLabelExpressionTest.java Tue Jan 5 15:25:46 2016
@@ -81,6 +81,41 @@ public class AnnotationLabelExpressionTe
}
@Test
+ public void testMultiple() {
+ String document = "Some text.";
+ String script = "b:(a:W)+{-PARTOF(Struct) -> CREATE(Struct, \"a\"=a, \"b\"=b, \"c\"=a, \"d\"=b)};";
+ script += "Struct.a{-> T1};";
+ script += "Struct.b{-> T2};";
+ script += "Struct.c{-> T3};";
+ script += "Struct.d{-> T4};";
+
+ Map<String, String> typeMap = new TreeMap<String, String>();
+ String typeName = "Struct";
+ typeMap.put(typeName, "uima.tcas.Annotation");
+
+ Map<String, List<TestFeature>> featureMap = new TreeMap<String, List<TestFeature>>();
+ List<TestFeature> list = new ArrayList<RutaTestUtils.TestFeature>();
+ featureMap.put(typeName, list);
+ list.add(new TestFeature("a", "", "uima.tcas.Annotation"));
+ list.add(new TestFeature("b", "", "uima.tcas.Annotation"));
+ list.add(new TestFeature("c", "", "uima.cas.FSArray"));
+ list.add(new TestFeature("d", "", "uima.cas.FSArray"));
+
+ CAS cas = null;
+ try {
+ cas = RutaTestUtils.getCAS(document, typeMap, featureMap);
+ Ruta.apply(cas, script);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ RutaTestUtils.assertAnnotationsEquals(cas, 1, 1, "text");
+ RutaTestUtils.assertAnnotationsEquals(cas, 2, 1, "Some text");
+ RutaTestUtils.assertAnnotationsEquals(cas, 3, 2, "Some", "text");
+ RutaTestUtils.assertAnnotationsEquals(cas, 4, 1, "Some text");
+ }
+
+ @Test
public void testLayers() {
String document = "Some text.";
String script = "d:(a:W b:W{-> CREATE(Struct, \"a\"=a, \"b\"=b, \"c\"=c, \"d\"=d)} c:PERIOD);";
@@ -117,33 +152,32 @@ public class AnnotationLabelExpressionTe
AnnotationFS a = null;
AnnotationFS next = null;
Feature f = null;
-
+
next = iterator.next();
assertEquals("text", next.getCoveredText());
-
-
+
f = t.getFeatureByBaseName("a");
a = (AnnotationFS) next.getFeatureValue(f);
assertNotNull("Feature value is null!", a);
assertEquals("Some", a.getCoveredText());
-
+
f = t.getFeatureByBaseName("b");
a = (AnnotationFS) next.getFeatureValue(f);
assertNotNull("Feature value is null!", a);
assertEquals("text", a.getCoveredText());
-
+
f = t.getFeatureByBaseName("c");
a = (AnnotationFS) next.getFeatureValue(f);
assertNotNull("Feature value is null!", a);
assertEquals(".", a.getCoveredText());
-
+
f = t.getFeatureByBaseName("d");
a = (AnnotationFS) next.getFeatureValue(f);
assertNotNull("Feature value is null!", a);
assertEquals("Some text.", a.getCoveredText());
}
-
+
@Test
public void testActions() {
String document = "Some text.";
@@ -152,13 +186,12 @@ public class AnnotationLabelExpressionTe
script += "a:W Struct2{-> SETFEATURE(\"a\", a)};";
script += "a:W Struct3{-> Struct3.a=a};";
-
Map<String, String> typeMap = new TreeMap<String, String>();
typeMap.put("Struct1", "uima.tcas.Annotation");
typeMap.put("Struct2", "uima.tcas.Annotation");
typeMap.put("Struct3", "uima.tcas.Annotation");
typeMap.put("Struct4", "uima.tcas.Annotation");
-
+
Map<String, List<TestFeature>> featureMap = new TreeMap<String, List<TestFeature>>();
List<TestFeature> list = new ArrayList<RutaTestUtils.TestFeature>();
featureMap.put("Struct1", list);
@@ -192,7 +225,7 @@ public class AnnotationLabelExpressionTe
a = (AnnotationFS) next.getFeatureValue(f);
assertNotNull("Feature value is null!", a);
assertEquals("Some", a.getCoveredText());
-
+
t = cas.getTypeSystem().getType("Struct2");
ai = cas.getAnnotationIndex(t);
assertEquals(1, ai.size());
@@ -203,7 +236,7 @@ public class AnnotationLabelExpressionTe
a = (AnnotationFS) next.getFeatureValue(f);
assertNotNull("Feature value is null!", a);
assertEquals("Some", a.getCoveredText());
-
+
t = cas.getTypeSystem().getType("Struct3");
ai = cas.getAnnotationIndex(t);
assertEquals(1, ai.size());