[maven-release-plugin] copy for tag ruta-2.4.0
git-svn-id: https://svn.apache.org/repos/asf/uima/ruta/tags/ruta-2.4.0@1726596 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ruta-core/src/main/java/org/apache/uima/ruta/condition/ConditionFactory.java b/ruta-core/src/main/java/org/apache/uima/ruta/condition/ConditionFactory.java
index 28bdb61..ee9d705 100644
--- a/ruta-core/src/main/java/org/apache/uima/ruta/condition/ConditionFactory.java
+++ b/ruta-core/src/main/java/org/apache/uima/ruta/condition/ConditionFactory.java
@@ -19,6 +19,7 @@
package org.apache.uima.ruta.condition;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -35,6 +36,7 @@
import org.apache.uima.ruta.expression.type.AbstractTypeListExpression;
import org.apache.uima.ruta.expression.type.ITypeExpression;
import org.apache.uima.ruta.extensions.RutaParseRuntimeException;
+import org.apache.uima.ruta.verbalize.RutaVerbalizer;
public class ConditionFactory {
@@ -101,8 +103,21 @@
(INumberExpression) arg4, (IBooleanExpression) arg5, parent);
}
}
-
- return null;
+ StringBuilder sb = new StringBuilder();
+ RutaVerbalizer verb = new RutaVerbalizer();
+ Iterator<IRutaExpression> iterator = args.iterator();
+ while (iterator.hasNext()) {
+ IRutaExpression each = iterator.next();
+ sb.append(verb.verbalize(each));
+ sb.append("(");
+ sb.append(each.getClass().getSimpleName());
+ sb.append(")");
+ if(iterator.hasNext()) {
+ sb.append(", ");
+ }
+ }
+
+ throw new RutaParseRuntimeException("The condition CONTAINS does not support the following arguments: " + sb.toString());
}
public static AbstractRutaCondition createConditionContains(ITypeExpression typeExpr,
diff --git a/ruta-core/src/main/java/org/apache/uima/ruta/expression/feature/GenericFeatureExpression.java b/ruta-core/src/main/java/org/apache/uima/ruta/expression/feature/GenericFeatureExpression.java
index d84d95e..f6a0c68 100644
--- a/ruta-core/src/main/java/org/apache/uima/ruta/expression/feature/GenericFeatureExpression.java
+++ b/ruta-core/src/main/java/org/apache/uima/ruta/expression/feature/GenericFeatureExpression.java
@@ -39,11 +39,12 @@
import org.apache.uima.ruta.expression.number.INumberListExpression;
import org.apache.uima.ruta.expression.string.IStringExpression;
import org.apache.uima.ruta.expression.string.IStringListExpression;
+import org.apache.uima.ruta.expression.type.ITypeExpression;
import org.apache.uima.ruta.rule.MatchContext;
public class GenericFeatureExpression extends ListExpression<Object> implements INumberExpression,
IBooleanExpression, IStringExpression, IAnnotationExpression, IAnnotationListExpression,
- IBooleanListExpression, INumberListExpression, IStringListExpression {
+ IBooleanListExpression, INumberListExpression, IStringListExpression, ITypeExpression {
private FeatureExpression featureExpression;
@@ -63,6 +64,8 @@
private IAnnotationListExpression annotationListExpression;
+ private ITypeExpression typeExpression;
+
public GenericFeatureExpression(FeatureExpression fe) {
super();
this.featureExpression = fe;
@@ -116,6 +119,15 @@
return annotationExpression.getAnnotation(context, stream);
}
+ @Override
+ public Type getType(MatchContext context, RutaStream stream) {
+ // special case where an argument is interpreted as a type expression
+ if (typeExpression == null) {
+ typeExpression = featureExpression.getTypeExpr(context, stream);
+ }
+ return typeExpression.getType(context, stream);
+ }
+
public FeatureExpression getFeatureExpression() {
return featureExpression;
}
@@ -180,4 +192,6 @@
return result;
}
+
+
}
diff --git a/ruta-core/src/main/java/org/apache/uima/ruta/rule/quantifier/MinMaxReluctant.java b/ruta-core/src/main/java/org/apache/uima/ruta/rule/quantifier/MinMaxReluctant.java
index dd8c50c..56077fa 100644
--- a/ruta-core/src/main/java/org/apache/uima/ruta/rule/quantifier/MinMaxReluctant.java
+++ b/ruta-core/src/main/java/org/apache/uima/ruta/rule/quantifier/MinMaxReluctant.java
@@ -91,23 +91,22 @@
int minValue = min.getIntegerValue(context, stream);
int maxValue = max.getIntegerValue(context, stream);
List<RuleElementMatch> list = containerMatch.getInnerMatches().get(ruleElement);
+ int matchedSize = list != null ? list.size() : 0;
if (list == null) {
- if (maxValue > 0) {
+ if (maxValue > 0 && minValue != 0) {
return true;
- } else {
- return false;
}
- }
-
- int matchedSize = list.size();
- if (list == null || list.isEmpty() || matchedSize < minValue) {
+ } else if (matchedSize < minValue) {
return true;
}
+
RuleElementMatch lastMatch = null;
- if (after) {
- lastMatch = list.get(list.size() - 1);
- } else {
- lastMatch = list.get(0);
+ if (list != null) {
+ if (after) {
+ lastMatch = list.get(list.size() - 1);
+ } else {
+ lastMatch = list.get(0);
+ }
}
RuleElement nextElement = ruleElement.getContainer().getNextElement(after, ruleElement);
@@ -122,7 +121,8 @@
boolean nextMatched = nextElementMatched(nextElement, continueMatch);
return (matchedSize < maxValue && matchedSize >= minValue && !nextMatched)
- || (!lastMatch.matched() && matchedSize >= minValue && matchedSize <= maxValue && !nextMatched);
+ || (lastMatch != null && !lastMatch.matched() && matchedSize >= minValue
+ && matchedSize <= maxValue && !nextMatched);
}
@Override
diff --git a/ruta-core/src/test/java/org/apache/uima/ruta/QuantifierTest.java b/ruta-core/src/test/java/org/apache/uima/ruta/QuantifierTest.java
new file mode 100644
index 0000000..80f58df
--- /dev/null
+++ b/ruta-core/src/test/java/org/apache/uima/ruta/QuantifierTest.java
@@ -0,0 +1,66 @@
+/*
+ * 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 java.io.IOException;
+
+import junit.framework.Assert;
+
+import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
+import org.apache.uima.cas.CASException;
+import org.apache.uima.jcas.JCas;
+import org.apache.uima.resource.ResourceInitializationException;
+import org.apache.uima.ruta.engine.Ruta;
+import org.apache.uima.ruta.engine.RutaTestUtils;
+import org.apache.uima.util.InvalidXMLException;
+import org.junit.Test;
+
+public class QuantifierTest {
+
+ @Test
+ public void testRightToLeftMinMaxReluctantToLiteral() throws CASException, ResourceInitializationException, InvalidXMLException,
+ IOException, AnalysisEngineProcessException {
+
+ JCas jcas = RutaTestUtils.getCAS("a b c d e.").getJCas();
+ Assert.assertEquals("a b c d e.", Ruta.select(jcas, "\"a\" W[0,5]? @PERIOD;").get(0).getCoveredText());
+ Assert.assertEquals("b c d e.", Ruta.select(jcas, "\"b\" W[0,5]? @PERIOD;").get(0).getCoveredText());
+ Assert.assertEquals("c d e.", Ruta.select(jcas, "\"c\" W[0,5]? @PERIOD;").get(0).getCoveredText());
+ Assert.assertEquals("d e.", Ruta.select(jcas, "\"d\" W[0,5]? @PERIOD;").get(0).getCoveredText());
+ Assert.assertEquals("e.", Ruta.select(jcas, "\"e\" W[0,5]? @PERIOD;").get(0).getCoveredText());
+
+ jcas.release();
+ }
+
+ @Test
+ public void testRightToLeftMinMaxGreedyToLiteral() throws CASException, ResourceInitializationException, InvalidXMLException,
+ IOException, AnalysisEngineProcessException {
+
+ JCas jcas = RutaTestUtils.getCAS("a b c d e.").getJCas();
+ Assert.assertEquals("a b c d e.", Ruta.select(jcas, "\"a\" W[0,4] @PERIOD;").get(0).getCoveredText());
+ Assert.assertEquals("b c d e.", Ruta.select(jcas, "\"b\" W[0,3] @PERIOD;").get(0).getCoveredText());
+ Assert.assertEquals("c d e.", Ruta.select(jcas, "\"c\" W[0,2] @PERIOD;").get(0).getCoveredText());
+ Assert.assertEquals("d e.", Ruta.select(jcas, "\"d\" W[0,1] @PERIOD;").get(0).getCoveredText());
+ Assert.assertEquals("e.", Ruta.select(jcas, "\"e\" W[0,0] @PERIOD;").get(0).getCoveredText());
+
+ jcas.release();
+ }
+
+
+}
diff --git a/ruta-core/src/test/java/org/apache/uima/ruta/condition/ContainsTest.java b/ruta-core/src/test/java/org/apache/uima/ruta/condition/ContainsTest.java
index 9e3eb99..582e6dd 100644
--- a/ruta-core/src/test/java/org/apache/uima/ruta/condition/ContainsTest.java
+++ b/ruta-core/src/test/java/org/apache/uima/ruta/condition/ContainsTest.java
@@ -19,13 +19,25 @@
package org.apache.uima.ruta.condition;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.util.Map;
+import java.util.TreeMap;
+
+import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
import org.apache.uima.cas.CAS;
+import org.apache.uima.resource.ResourceConfigurationException;
+import org.apache.uima.resource.ResourceInitializationException;
+import org.apache.uima.ruta.engine.Ruta;
import org.apache.uima.ruta.engine.RutaTestUtils;
+import org.apache.uima.util.InvalidXMLException;
+import org.junit.Ignore;
import org.junit.Test;
public class ContainsTest {
@Test
+ @Ignore
public void test() {
CAS cas = RutaTestUtils.processTestScript(this.getClass());
@@ -37,8 +49,30 @@
RutaTestUtils.assertAnnotationsEquals(cas, 3, 1, "Testing the CONTAINS condition of Ruta");
RutaTestUtils.assertAnnotationsEquals(cas, 4, 2, "A single sentence", "Testing the CONTAINS condition of Ruta");
- // TODO CONTAINS with RutaExpression?
-
cas.release();
}
+
+ @Test
+ public void testAlias() throws ResourceInitializationException, InvalidXMLException, IOException, AnalysisEngineProcessException, ResourceConfigurationException, URISyntaxException {
+ String document = "1 some text; 2 some text; 3 some text;";
+
+ String script = "IMPORT PACKAGE * FROM org.apache.uima.ruta.ImportStatementsTestTypeSystemWithManyPackages AS ruta;";
+ script += "(NUM # PM){-> ruta.Type1, T1};";
+ script += "Document{CONTAINS(ruta.Type1) -> T2};";
+
+ Map<String, String> typeMap = new TreeMap<String, String>();
+ String typeName = "org.apache.uima.ruta.other3.Type1";
+ typeMap.put(typeName, "uima.tcas.Annotation");
+ typeName = "org.apache.uima.ruta.other4.Type2";
+ typeMap.put(typeName, "uima.tcas.Annotation");
+
+ CAS cas = RutaTestUtils.getCAS(document, typeMap, null);
+ Ruta.apply(cas, script);
+
+ RutaTestUtils.assertAnnotationsEquals(cas, 1, 3, "1 some text;", "2 some text;", "3 some text;");
+ RutaTestUtils.assertAnnotationsEquals(cas, 2, 1, document);
+
+ }
+
+
}
diff --git a/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/LanguageCheckerVisitor.java b/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/LanguageCheckerVisitor.java
index b3dce8a..4740465 100644
--- a/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/LanguageCheckerVisitor.java
+++ b/ruta-ep-ide-ui/src/main/java/org/apache/uima/ruta/ide/validator/LanguageCheckerVisitor.java
@@ -599,6 +599,10 @@
if (allLongTypeNames.contains(featText)) {
return true;
}
+ if(namespaces.keySet().contains(featText)) {
+ // wrong ast elements, alias interpreted as feature expression
+ return false;
+ }
checkTypeOfFeatureMatch(featText, fme);
return true;
}