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/12/17 22:41:01 UTC
svn commit: r1720670 - in /uima/ruta/trunk/ruta-core/src:
main/java/org/apache/uima/ruta/rule/RutaTypeMatcher.java
test/java/org/apache/uima/ruta/BlockTest.java
Author: pkluegl
Date: Thu Dec 17 21:41:01 2015
New Revision: 1720670
URL: http://svn.apache.org/viewvc?rev=1720670&view=rev
Log:
UIMA-4714
- do not resolve type to early
- added test
Added:
uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/BlockTest.java
Modified:
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaTypeMatcher.java
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaTypeMatcher.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaTypeMatcher.java?rev=1720670&r1=1720669&r2=1720670&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaTypeMatcher.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaTypeMatcher.java Thu Dec 17 21:41:01 2015
@@ -60,15 +60,12 @@ public class RutaTypeMatcher implements
if (type == null) {
continue;
}
- Type currentDAType = stream.getCas().getDocumentAnnotation().getType();
+ Type overallDAType = stream.getCas().getDocumentAnnotation().getType();
String name = type.getName();
- RutaBasic firstBasicOfAll = stream.getFirstBasicOfAll();
if ("uima.tcas.DocumentAnnotation".equals(name)
|| "org.apache.uima.ruta.type.Document".equals(name)
- || currentDAType.equals(type)
-// || (stream.getDocumentAnnotationType().getName().equals(name) && (firstBasicOfAll != null && firstBasicOfAll
-// .beginsWith(type)))
- ) {
+ || overallDAType.equals(type)
+ ) {
// TODO what about dynamic windowing?
annotations.add(stream.getDocumentAnnotation());
} else {
@@ -247,9 +244,9 @@ public class RutaTypeMatcher implements
return mr;
}
- protected Type getType(TypeExpression expression, RutaBlock parent, RutaStream stream) {
+ protected Type getType(TypeExpression expression, RutaBlock parent, RutaStream stream, boolean resolveDocumentAnnotation) {
Type type = expression.getType(parent);
- if (type != null && "uima.tcas.DocumentAnnotation".equals(type.getName())) {
+ if (resolveDocumentAnnotation && type != null && "uima.tcas.DocumentAnnotation".equals(type.getName())) {
return stream.getDocumentAnnotationType();
}
return type;
@@ -257,13 +254,13 @@ public class RutaTypeMatcher implements
public long estimateAnchors(RutaBlock parent, RutaStream stream) {
TypeExpression typeExpression = mr.getTypeExpression(parent);
- return stream.getHistogram(getType(typeExpression, parent, stream));
+ return stream.getHistogram(getType(typeExpression, parent, stream, true));
}
public List<Type> getTypes(RutaBlock parent, RutaStream stream) {
List<Type> result = new ArrayList<Type>(1);
TypeExpression typeExpression = mr.getTypeExpression(parent);
- Type type = getType(typeExpression, parent, stream);
+ Type type = getType(typeExpression, parent, stream, false);
result.add(type);
return result;
}
Added: uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/BlockTest.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/BlockTest.java?rev=1720670&view=auto
==============================================================================
--- uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/BlockTest.java (added)
+++ uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/BlockTest.java Thu Dec 17 21:41:01 2015
@@ -0,0 +1,56 @@
+/*
+ * 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 BlockTest {
+
+ @Test
+ public void testInnerDocumentMatch() {
+ String document = "Some text";
+ String script = "";
+ script += "CW{ -> CREATE(RutaAnnotation, \"score\"=1)};";
+ script += "CW{ -> CREATE(RutaAnnotation, \"score\"=2)};";
+ script += "BLOCK(forEach) RutaAnnotation.score==1{}{";
+ script += "Document{-> T1};";
+ script += "MARK(T2);";
+ script += "RutaAnnotation{-> T3};";
+ script += "}";
+
+ CAS cas = null;
+ try {
+ cas = RutaTestUtils.getCAS(document);
+ Ruta.apply(cas, script);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ RutaTestUtils.assertAnnotationsEquals(cas, 1, 1, "Some");
+ RutaTestUtils.assertAnnotationsEquals(cas, 2, 1, "Some");
+ RutaTestUtils.assertAnnotationsEquals(cas, 3, 2, "Some", "Some");
+
+ cas.release();
+ }
+
+}