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 2017/07/10 09:13:24 UTC
svn commit: r1801432 - in /uima/ruta/trunk/ruta-core/src:
main/java/org/apache/uima/ruta/RutaStream.java
test/java/org/apache/uima/ruta/rule/RegExpRuleTest.java
Author: pkluegl
Date: Mon Jul 10 09:13:23 2017
New Revision: 1801432
URL: http://svn.apache.org/viewvc?rev=1801432&view=rev
Log:
UIMA-5448
- fixed indexing
- added test
Modified:
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java
uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/rule/RegExpRuleTest.java
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java?rev=1801432&r1=1801431&r2=1801432&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java Mon Jul 10 09:13:23 2017
@@ -288,18 +288,19 @@ public class RutaStream extends FSIterat
}
}
- private Collection<Type> removeSubsumedTypes(Collection<String> typeNames, TypeSystem typeSystem) {
+ private Collection<Type> removeSubsumedTypes(Collection<String> typeNames,
+ TypeSystem typeSystem) {
Collection<Type> allTypes = new HashSet<>();
for (String each : typeNames) {
Type type = typeSystem.getType(each);
- if(type != null) {
+ if (type != null) {
allTypes.add(type);
}
}
List<Type> rootTypes = new ArrayList<>(allTypes);
for (Type type1 : allTypes) {
for (Type type2 : allTypes) {
- if(type1!= type2 && typeSystem.subsumes(type1, type2)) {
+ if (type1 != type2 && typeSystem.subsumes(type1, type2)) {
rootTypes.remove(type2);
}
}
@@ -409,8 +410,8 @@ public class RutaStream extends FSIterat
toSplit.setEnd(anchor);
RutaBasic newRB = new RutaBasic(getJCas(), anchor, newEnd);
newRB.setLowMemoryProfile(lowMemoryProfile);
- newRB.setEndMap(toSplit.getEndMap());
- newRB.setPartOf(toSplit.getPartOf());
+ newRB.setEndMap(toSplit.getEndMap().clone());
+ newRB.setPartOf(toSplit.getPartOf().clone());
toSplit.clearEndMap();
cas.addFsToIndexes(toSplit);
cas.addFsToIndexes(newRB);
@@ -1232,7 +1233,7 @@ public class RutaStream extends FSIterat
double v = ((INumberExpression) expression).getDoubleValue(context, this);
environment.setVariableValue(var, v);
} else if (clazz.equals(Float.class) && expression instanceof INumberExpression) {
- float v = (float)((INumberExpression) expression).getDoubleValue(context, this);
+ float v = (float) ((INumberExpression) expression).getDoubleValue(context, this);
environment.setVariableValue(var, v);
} else if (clazz.equals(Integer.class) && expression instanceof INumberExpression) {
int v = ((INumberExpression) expression).getIntegerValue(context, this);
Modified: uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/rule/RegExpRuleTest.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/rule/RegExpRuleTest.java?rev=1801432&r1=1801431&r2=1801432&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/rule/RegExpRuleTest.java (original)
+++ uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/rule/RegExpRuleTest.java Mon Jul 10 09:13:23 2017
@@ -32,6 +32,7 @@ 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.engine.Ruta;
import org.apache.uima.ruta.engine.RutaEngine;
import org.apache.uima.ruta.engine.RutaTestUtils;
import org.apache.uima.ruta.engine.RutaTestUtils.TestFeature;
@@ -40,10 +41,10 @@ import org.junit.Test;
public class RegExpRuleTest {
@Test
- public void test() {
+ public void test() throws Exception {
String name = this.getClass().getSimpleName();
String namespace = this.getClass().getPackage().getName().replaceAll("\\.", "/");
- CAS cas = null;
+
Map<String, String> complexTypes = new HashMap<String, String>();
Map<String, List<TestFeature>> features = new TreeMap<String, List<TestFeature>>();
String typeName = "org.apache.uima.Complex";
@@ -56,14 +57,9 @@ public class RegExpRuleTest {
list.add(new TestFeature(fn2, "", "uima.cas.Boolean"));
String fn3 = "s";
list.add(new TestFeature(fn3, "", "uima.cas.String"));
-
- try {
- cas = RutaTestUtils.process(namespace + "/" + name + RutaEngine.SCRIPT_FILE_EXTENSION, namespace + "/" + name
- + ".txt", 50, false,false,complexTypes,features, null);
- } catch (Exception e) {
- e.printStackTrace();
- assert (false);
- }
+
+ CAS cas = RutaTestUtils.process(namespace + "/" + name + RutaEngine.SCRIPT_FILE_EXTENSION,
+ namespace + "/" + name + ".txt", 50, false, false, complexTypes, features, null);
Type t = null;
AnnotationIndex<AnnotationFS> ai = null;
FSIterator<AnnotationFS> iterator = null;
@@ -73,7 +69,7 @@ public class RegExpRuleTest {
assertEquals(1, ai.size());
iterator = ai.iterator();
assertEquals(28, iterator.next().getCoveredText().length());
-
+
t = RutaTestUtils.getTestType(cas, 2);
ai = cas.getAnnotationIndex(t);
iterator = ai.iterator();
@@ -94,7 +90,7 @@ public class RegExpRuleTest {
String stringValue = null;
Boolean booleanValue = null;
AnnotationFS afs = null;
-
+
next = iterator.next();
assertEquals("y", next.getCoveredText());
stringValue = next.getStringValue(t.getFeatureByBaseName(fn3));
@@ -103,7 +99,7 @@ public class RegExpRuleTest {
assertEquals(true, booleanValue);
afs = (AnnotationFS) next.getFeatureValue(t.getFeatureByBaseName(fn1));
assertEquals("B", afs.getCoveredText());
-
+
next = iterator.next();
assertEquals("B", next.getCoveredText());
stringValue = next.getStringValue(t.getFeatureByBaseName(fn3));
@@ -112,7 +108,7 @@ public class RegExpRuleTest {
assertEquals(false, booleanValue);
afs = (AnnotationFS) next.getFeatureValue(t.getFeatureByBaseName(fn1));
assertEquals("y", afs.getCoveredText());
-
+
next = iterator.next();
assertEquals("z", next.getCoveredText());
stringValue = next.getStringValue(t.getFeatureByBaseName(fn3));
@@ -121,7 +117,7 @@ public class RegExpRuleTest {
assertEquals(true, booleanValue);
afs = (AnnotationFS) next.getFeatureValue(t.getFeatureByBaseName(fn1));
assertEquals("B", afs.getCoveredText());
-
+
next = iterator.next();
assertEquals("B", next.getCoveredText());
stringValue = next.getStringValue(t.getFeatureByBaseName(fn3));
@@ -130,7 +126,7 @@ public class RegExpRuleTest {
assertEquals(false, booleanValue);
afs = (AnnotationFS) next.getFeatureValue(t.getFeatureByBaseName(fn1));
assertEquals("z", afs.getCoveredText());
-
+
next = iterator.next();
assertEquals("B", next.getCoveredText());
stringValue = next.getStringValue(t.getFeatureByBaseName(fn3));
@@ -140,4 +136,15 @@ public class RegExpRuleTest {
cas.release();
}
+
+ @Test
+ public void testSegments() throws Exception {
+ String document = "bla concepta bla";
+ String script = "\"(concept)([a-z])\"-> 1 = T1, 2 = T2;\n";
+ script += "T1{-PARTOF(T2)-> T2};";
+ CAS cas = RutaTestUtils.getCAS(document);
+ Ruta.apply(cas, script);
+ RutaTestUtils.assertAnnotationsEquals(cas, 2, 2, "concept", "a");
+ }
+
}