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/18 18:30:38 UTC
svn commit: r1725309 - in /uima/ruta/trunk/ruta-core/src:
main/java/org/apache/uima/ruta/engine/Ruta.java
main/java/org/apache/uima/ruta/verbalize/ScriptVerbalizer.java
test/java/org/apache/uima/ruta/verbalizer/ScriptVerbalizerTest.java
Author: pkluegl
Date: Mon Jan 18 17:30:37 2016
New Revision: 1725309
URL: http://svn.apache.org/viewvc?rev=1725309&view=rev
Log:
UIMA-4760
- fixed type verbalization in type matcher
- added test
Added:
uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/verbalizer/ScriptVerbalizerTest.java (with props)
Modified:
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/Ruta.java
uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/verbalize/ScriptVerbalizer.java
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/Ruta.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/Ruta.java?rev=1725309&r1=1725308&r2=1725309&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/Ruta.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/engine/Ruta.java Mon Jan 18 17:30:37 2016
@@ -172,7 +172,12 @@ public class Ruta {
}
}
- private static void removeDebugInformationFromIndex(JCas jcas) {
+ /**
+ * Removes all debug annotations from the index.
+ *
+ * @param jcas - the current document
+ */
+ public static void removeDebugInformation(JCas jcas) {
jcas.removeAllIncludingSubtypes(DebugBlockApply.type);
jcas.removeAllIncludingSubtypes(DebugRuleApply.type);
jcas.removeAllIncludingSubtypes(DebugRuleMatch.type);
@@ -246,7 +251,7 @@ public class Ruta {
RutaEngine.PARAM_DEBUG_WITH_MATCHES, true);
applyRule(jcas, rule, config);
List<Annotation> ruleMatches = getRuleMatches(jcas);
- removeDebugInformationFromIndex(jcas);
+ removeDebugInformation(jcas);
return ruleMatches;
}
@@ -266,7 +271,7 @@ public class Ruta {
Object[] config = ArrayUtils.addAll(configurationData, RutaEngine.PARAM_DEBUG, true);
applyRule(jcas, rule, config);
int applies = countRuleApplies(jcas);
- removeDebugInformationFromIndex(jcas);
+ removeDebugInformation(jcas);
return applies > 0;
}
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/verbalize/ScriptVerbalizer.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/verbalize/ScriptVerbalizer.java?rev=1725309&r1=1725308&r2=1725309&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/verbalize/ScriptVerbalizer.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/verbalize/ScriptVerbalizer.java Mon Jan 18 17:30:37 2016
@@ -63,9 +63,9 @@ public class ScriptVerbalizer {
private static final String CBOPEN = "{";
- private static final String THEN = " -> ";
+ private static final String THEN = "->";
- private static final String THEN2 = " <- ";
+ private static final String THEN2 = "<-";
private RutaVerbalizer verbalizer;
@@ -108,10 +108,16 @@ public class ScriptVerbalizer {
public String verbalizeRule(RutaRule rule) {
List<RuleElement> elements = rule.getRuleElements();
StringBuilder result = new StringBuilder();
- for (RuleElement each : elements) {
+ Iterator<RuleElement> iterator = elements.iterator();
+ while (iterator.hasNext()) {
+ RuleElement each = iterator.next();
result.append(verbalizeRuleElement(each));
- result.append(" ");
+ if(iterator.hasNext()) {
+ result.append(" ");
+ }
+
}
+ result.append(";");
return result.toString();
}
@@ -149,8 +155,9 @@ public class ScriptVerbalizer {
}
}
}
+ } else {
+ result.append(verbalizeMatcher(tmre));
}
- result.append(verbalizeMatcher(tmre));
} else if (re instanceof WildCardRuleElement) {
result.append("#");
}
@@ -187,8 +194,8 @@ public class ScriptVerbalizer {
result.append(CBOPEN);
for (RutaStatement rutaStatement : inlinedConditionRules) {
result.append(verbalize(rutaStatement));
- result.append(";");
}
+ result.append(CBCLOSE);
}
List<RutaStatement> inlinedActionRules = are.getInlinedActionRules();
if (inlinedActionRules != null && !inlinedActionRules.isEmpty()) {
@@ -196,8 +203,8 @@ public class ScriptVerbalizer {
result.append(CBOPEN);
for (RutaStatement rutaStatement : inlinedActionRules) {
result.append(verbalize(rutaStatement));
- result.append(";");
}
+ result.append(CBCLOSE);
}
}
return result.toString();
Added: uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/verbalizer/ScriptVerbalizerTest.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/verbalizer/ScriptVerbalizerTest.java?rev=1725309&view=auto
==============================================================================
--- uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/verbalizer/ScriptVerbalizerTest.java (added)
+++ uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/verbalizer/ScriptVerbalizerTest.java Mon Jan 18 17:30:37 2016
@@ -0,0 +1,67 @@
+/*
+ * 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.verbalizer;
+
+import java.util.Collection;
+
+import junit.framework.Assert;
+
+import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
+import org.apache.uima.fit.util.JCasUtil;
+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.RutaEngine;
+import org.apache.uima.ruta.engine.RutaTestUtils;
+import org.apache.uima.ruta.type.DebugBlockApply;
+import org.apache.uima.ruta.type.DebugRuleApply;
+import org.junit.Test;
+
+public class ScriptVerbalizerTest {
+
+ @Test
+ public void testRuleVerbalization() throws Exception{
+ JCas jcas = RutaTestUtils.getCAS("Some text.").getJCas();
+
+ assertRuleVerbalization(jcas, "W{->T1} W{->T2};");
+ assertRuleVerbalization(jcas, "MARK(T1);", "Document{->MARK(T1)};");
+ assertRuleVerbalization(jcas, "T1<-{W PERIOD;};");
+ assertRuleVerbalization(jcas, "T1->{W{->T1} PERIOD;};");
+ assertRuleVerbalization(jcas, "T1<-{W PERIOD;}->{W{->T1} PERIOD;};");
+ assertRuleVerbalization(jcas, "W W? W?? W+ W+? W* W*? W[1,2] W[1,2]? #;");
+
+ jcas.release();
+ }
+
+ private void assertRuleVerbalization(JCas jcas, String rule) throws AnalysisEngineProcessException, ResourceInitializationException {
+ assertRuleVerbalization(jcas, rule, rule);
+ }
+
+ private void assertRuleVerbalization(JCas jcas, String rule, String expected) throws AnalysisEngineProcessException, ResourceInitializationException {
+ Ruta.applyRule(jcas, rule, RutaEngine.PARAM_DEBUG, true, RutaEngine.PARAM_DEBUG_WITH_MATCHES, true);
+ Collection<DebugBlockApply> blockApplies = JCasUtil.select(jcas, DebugBlockApply.class);
+ Assert.assertEquals(1, blockApplies.size());
+ DebugBlockApply blockApply = blockApplies.iterator().next();
+ Assert.assertEquals(1, blockApply.getInnerApply().size());
+ DebugRuleApply ruleApply = (DebugRuleApply) blockApply.getInnerApply(0);
+ Assert.assertEquals(expected, ruleApply.getElement());
+ Ruta.removeDebugInformation(jcas);
+ }
+}
Propchange: uima/ruta/trunk/ruta-core/src/test/java/org/apache/uima/ruta/verbalizer/ScriptVerbalizerTest.java
------------------------------------------------------------------------------
svn:eol-style = native