You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by jo...@apache.org on 2011/08/01 17:25:50 UTC
svn commit: r1152824 [21/21] - in
/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker:
./ action/ batch/ condition/ engine/ kernel/ kernel/constraint/
kernel/expression/ kernel/expression/bool...
Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/verbalize/ConditionVerbalizer.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/verbalize/ConditionVerbalizer.java?rev=1152824&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/verbalize/ConditionVerbalizer.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/verbalize/ConditionVerbalizer.java Mon Aug 1 15:24:44 2011
@@ -0,0 +1,420 @@
+package org.apache.uima.tm.textmarker.verbalize;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.uima.tm.textmarker.condition.AbstractTextMarkerCondition;
+import org.apache.uima.tm.textmarker.condition.AfterCondition;
+import org.apache.uima.tm.textmarker.condition.AndCondition;
+import org.apache.uima.tm.textmarker.condition.BeforeCondition;
+import org.apache.uima.tm.textmarker.condition.ContainsCondition;
+import org.apache.uima.tm.textmarker.condition.ContextCountCondition;
+import org.apache.uima.tm.textmarker.condition.CountCondition;
+import org.apache.uima.tm.textmarker.condition.CurrentCountCondition;
+import org.apache.uima.tm.textmarker.condition.EndsWithCondition;
+import org.apache.uima.tm.textmarker.condition.FeatureCondition;
+import org.apache.uima.tm.textmarker.condition.IfCondition;
+import org.apache.uima.tm.textmarker.condition.InListCondition;
+import org.apache.uima.tm.textmarker.condition.IsCondition;
+import org.apache.uima.tm.textmarker.condition.IsInTagCondition;
+import org.apache.uima.tm.textmarker.condition.LastCondition;
+import org.apache.uima.tm.textmarker.condition.MOfNCondition;
+import org.apache.uima.tm.textmarker.condition.NearCondition;
+import org.apache.uima.tm.textmarker.condition.NotCondition;
+import org.apache.uima.tm.textmarker.condition.OrCondition;
+import org.apache.uima.tm.textmarker.condition.ParseCondition;
+import org.apache.uima.tm.textmarker.condition.PartOfCondition;
+import org.apache.uima.tm.textmarker.condition.PartOfNeqCondition;
+import org.apache.uima.tm.textmarker.condition.PositionCondition;
+import org.apache.uima.tm.textmarker.condition.RegExpCondition;
+import org.apache.uima.tm.textmarker.condition.ScoreCondition;
+import org.apache.uima.tm.textmarker.condition.SizeCondition;
+import org.apache.uima.tm.textmarker.condition.StartsWithCondition;
+import org.apache.uima.tm.textmarker.condition.TotalCountCondition;
+import org.apache.uima.tm.textmarker.condition.VoteCondition;
+import org.apache.uima.tm.textmarker.kernel.expression.number.NumberExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.number.SimpleNumberExpression;
+
+
+public class ConditionVerbalizer {
+
+ private TextMarkerVerbalizer verbalizer;
+
+ public ConditionVerbalizer(TextMarkerVerbalizer verbalizer) {
+ super();
+ this.verbalizer = verbalizer;
+ }
+
+ public String verbalizeName(AbstractTextMarkerCondition condition) {
+ if (condition instanceof AndCondition) {
+ return "AND";
+ } else if (condition instanceof ContainsCondition) {
+ String name = "CONTAINS";
+ return name;
+ } else if (condition instanceof ContextCountCondition) {
+ String name = "CONTEXTCOUNT";
+ return name;
+ } else if (condition instanceof CountCondition) {
+ String name = "COUNT";
+ return name;
+ } else if (condition instanceof CurrentCountCondition) {
+ String name = "CURRENTCOUNT";
+ return name;
+ } else if (condition instanceof IfCondition) {
+ String name = "IF";
+ return name;
+ } else if (condition instanceof InListCondition) {
+ return "INLIST";
+ } else if (condition instanceof IsInTagCondition) {
+ return "ISINTAG";
+ } else if (condition instanceof LastCondition) {
+ return "LAST";
+ } else if (condition instanceof MOfNCondition) {
+ return "MOFN";
+ } else if (condition instanceof NearCondition) {
+ String name = "NEAR";
+ return name;
+ } else if (condition instanceof NotCondition) {
+ return "NOT";
+ } else if (condition instanceof OrCondition) {
+ return "OR";
+ } else if (condition instanceof PartOfCondition) {
+ return "PARTOF";
+ } else if (condition instanceof PartOfNeqCondition) {
+ return "PARTOFNEQ";
+ } else if (condition instanceof PositionCondition) {
+ return "POSITION";
+ } else if (condition instanceof RegExpCondition) {
+ return "REGEXP";
+ } else if (condition instanceof ScoreCondition) {
+ String name = "SCORE";
+ return name;
+ } else if (condition instanceof TotalCountCondition) {
+ String name = "TOTALCOUNT";
+ return name;
+ } else if (condition instanceof VoteCondition) {
+ String name = "VOTE";
+ return name;
+ } else if (condition instanceof FeatureCondition) {
+ String name = "FEATURE";
+ return name;
+ } else if (condition instanceof ParseCondition) {
+ String name = "PARSE";
+ return name;
+ } else if (condition instanceof IsCondition) {
+ String name = "IS";
+ return name;
+ } else if (condition instanceof BeforeCondition) {
+ String name = "BEFORE";
+ return name;
+ } else if (condition instanceof AfterCondition) {
+ String name = "AFTER";
+ return name;
+ } else if (condition instanceof StartsWithCondition) {
+ String name = "STARTSWITH";
+ return name;
+ } else if (condition instanceof EndsWithCondition) {
+ String name = "ENDSWITH";
+ return name;
+ } else if (condition instanceof SizeCondition) {
+ String name = "SIZE";
+ return name;
+ }
+
+ return condition.getClass().getSimpleName();
+ }
+
+ public String verbalize(AbstractTextMarkerCondition condition) {
+ if (condition instanceof AndCondition) {
+ AndCondition c = (AndCondition) condition;
+ List<AbstractTextMarkerCondition> conditions = c.getConditions();
+ StringBuilder sb = new StringBuilder();
+ sb.append("AND(");
+ Iterator<AbstractTextMarkerCondition> it = conditions.iterator();
+ while (it.hasNext()) {
+ AbstractTextMarkerCondition each = (AbstractTextMarkerCondition) it.next();
+ sb.append(verbalize(each));
+ if (it.hasNext()) {
+ sb.append(",");
+ }
+ }
+ sb.append(")");
+ return sb.toString();
+ } else if (condition instanceof ContainsCondition) {
+ ContainsCondition c = (ContainsCondition) condition;
+ String name = "CONTAINS(";
+ NumberExpression minE = c.getMin();
+ String min = verbalizeMin(minE, 1);
+ NumberExpression maxE = c.getMax();
+ String max = verbalizeMax(maxE, Integer.MAX_VALUE);
+ String percent = verbalizer.verbalize(c.getPercent());
+ percent = !percent.equals("false") ? "," + percent : "";
+ if (c.getType() != null) {
+ String type = verbalizer.verbalize(c.getType());
+ return name + type + min + max + percent + ")";
+ } else {
+ return name + verbalizer.verbalize(c.getArgList()) + "," + verbalizer.verbalize(c.getArg())
+ + min + max + percent + ")";
+ }
+ } else if (condition instanceof ContextCountCondition) {
+ ContextCountCondition c = (ContextCountCondition) condition;
+ String name = "CONTEXTCOUNT(";
+ String type = verbalizer.verbalize(c.getType());
+ NumberExpression minE = c.getMin();
+ String min = verbalizeMin(minE, Integer.MIN_VALUE);
+ NumberExpression maxE = c.getMax();
+ String max = verbalizeMax(maxE, Integer.MAX_VALUE);
+ String var = c.getVar() == null ? "" : "," + c.getVar();
+ return name + type + min + max + var + ")";
+ } else if (condition instanceof CountCondition) {
+ CountCondition c = (CountCondition) condition;
+ if (c.getArg() == null) {
+ String name = "COUNT(";
+ String type = verbalizer.verbalize(c.getType());
+ NumberExpression minE = c.getMin();
+ String min = verbalizeMin(minE, Integer.MIN_VALUE);
+ NumberExpression maxE = c.getMax();
+ String max = verbalizeMax(maxE, Integer.MAX_VALUE);
+ String var = c.getVar() == null ? "" : "," + c.getVar();
+ return name + type + min + max + var + ")";
+ } else {
+ String name = "COUNT(";
+ String list = verbalizer.verbalize(c.getList());
+ String arg = verbalizer.verbalize(c.getArg());
+ NumberExpression minE = c.getMin();
+ String min = verbalizeMin(minE, Integer.MIN_VALUE);
+ NumberExpression maxE = c.getMax();
+ String max = verbalizeMax(maxE, Integer.MAX_VALUE);
+ String var = c.getVar() == null ? "" : "," + c.getVar();
+ return name + list + "," + arg + min + max + var + ")";
+ }
+ } else if (condition instanceof CurrentCountCondition) {
+ CurrentCountCondition c = (CurrentCountCondition) condition;
+ String name = "CURRENTCOUNT(";
+ String type = verbalizer.verbalize(c.getType());
+ NumberExpression minE = c.getMin();
+ String min = verbalizeMin(minE, Integer.MIN_VALUE);
+ NumberExpression maxE = c.getMax();
+ String max = verbalizeMax(maxE, Integer.MAX_VALUE);
+ String var = c.getVar() == null ? "" : "," + c.getVar();
+ return name + type + min + max + var + ")";
+ } else if (condition instanceof IfCondition) {
+ IfCondition c = (IfCondition) condition;
+ return "IF(" + verbalizer.verbalize(c.getExpression()) + ")";
+ } else if (condition instanceof InListCondition) {
+ InListCondition c = (InListCondition) condition;
+ String name = "INLIST";
+ String list = "";
+ if (c.getListExpression() != null) {
+ list = verbalizer.verbalize(c.getListExpression());
+ } else {
+ list = verbalizer.verbalize(c.getStringList());
+ list = "[" + list + "]";
+ }
+ NumberExpression distE = c.getDistance();
+ String dist = "";
+ String rel = "";
+ if (distE != null) {
+ dist = "," + verbalizer.verbalize(distE);
+ }
+ if (c.getRelative() != null) {
+ rel = "," + verbalizer.verbalize(c.getRelative());
+ }
+ return name + "(" + list + dist + rel + ")";
+ } else if (condition instanceof IsInTagCondition) {
+ IsInTagCondition c = (IsInTagCondition) condition;
+ return "ISINTAG(" + verbalizer.verbalize(c.getTag()) + ")";
+ } else if (condition instanceof LastCondition) {
+ LastCondition c = (LastCondition) condition;
+ return "LAST(" + verbalizer.verbalize(c.getType()) + ")";
+ } else if (condition instanceof MOfNCondition) {
+ MOfNCondition c = (MOfNCondition) condition;
+ StringBuilder sb = new StringBuilder();
+ sb.append("MOFN(");
+
+ NumberExpression minE = c.getMin();
+ String min = verbalizeMin(minE, Integer.MIN_VALUE);
+ NumberExpression maxE = c.getMax();
+ String max = verbalizeMax(maxE, Integer.MAX_VALUE);
+ sb.append(min.substring(1, min.length()));
+ sb.append(max);
+ List<AbstractTextMarkerCondition> conditions = c.getConditions();
+ if (!conditions.isEmpty()) {
+ sb.append(",");
+ }
+ Iterator<AbstractTextMarkerCondition> it = conditions.iterator();
+ while (it.hasNext()) {
+ AbstractTextMarkerCondition each = (AbstractTextMarkerCondition) it.next();
+ sb.append(verbalize(each));
+ if (it.hasNext()) {
+ sb.append(",");
+ }
+ }
+ sb.append(")");
+ return sb.toString();
+ } else if (condition instanceof NearCondition) {
+ NearCondition c = (NearCondition) condition;
+ String name = "NEAR(";
+ String type = verbalizer.verbalize(c.getType());
+ String var = verbalizer.verbalize(c.getForward());
+ NumberExpression minE = c.getMin();
+ String min = verbalizeMin(minE, Integer.MIN_VALUE);
+ NumberExpression maxE = c.getMax();
+ String max = verbalizeMax(maxE, Integer.MAX_VALUE);
+ return name + type + min + max + "," + var + ")";
+ } else if (condition instanceof NotCondition) {
+ NotCondition c = (NotCondition) condition;
+ List<AbstractTextMarkerCondition> conditions = c.getConditions();
+ if (conditions.size() != 1) {
+ StringBuilder sb = new StringBuilder();
+ sb.append("NOT(");
+ Iterator<AbstractTextMarkerCondition> it = conditions.iterator();
+ while (it.hasNext()) {
+ AbstractTextMarkerCondition each = (AbstractTextMarkerCondition) it.next();
+ sb.append(verbalize(each));
+ if (it.hasNext()) {
+ sb.append(",");
+ }
+ }
+ sb.append(")");
+ return sb.toString();
+ } else {
+ return "-" + verbalize(conditions.get(0));
+ }
+ } else if (condition instanceof OrCondition) {
+ OrCondition c = (OrCondition) condition;
+ List<AbstractTextMarkerCondition> conditions = c.getConditions();
+ StringBuilder sb = new StringBuilder();
+ sb.append("OR(");
+ Iterator<AbstractTextMarkerCondition> it = conditions.iterator();
+ while (it.hasNext()) {
+ AbstractTextMarkerCondition each = (AbstractTextMarkerCondition) it.next();
+ sb.append(verbalize(each));
+ if (it.hasNext()) {
+ sb.append(",");
+ }
+ }
+ sb.append(")");
+ return sb.toString();
+ } else if (condition instanceof PartOfCondition) {
+ PartOfCondition c = (PartOfCondition) condition;
+ if (c.getType() == null) {
+ return "PARTOF(" + verbalizer.verbalize(c.getList()) + ")";
+ } else {
+ return "PARTOF(" + verbalizer.verbalize(c.getType()) + ")";
+ }
+ } else if (condition instanceof PartOfNeqCondition) {
+ PartOfNeqCondition c = (PartOfNeqCondition) condition;
+ return "PARTOFNEQ(" + verbalizer.verbalize(c.getType()) + ")";
+ } else if (condition instanceof PositionCondition) {
+ PositionCondition c = (PositionCondition) condition;
+ return "POSITION(" + verbalizer.verbalize(c.getType()) + ","
+ + verbalizer.verbalize(c.getPosition()) + ")";
+ } else if (condition instanceof RegExpCondition) {
+ RegExpCondition c = (RegExpCondition) condition;
+ return "REGEXP(" + verbalizer.verbalize(c.getPattern()) + ")";
+ } else if (condition instanceof ScoreCondition) {
+ ScoreCondition c = (ScoreCondition) condition;
+ String name = "SCORE(";
+ // String type = verbalizer.verbalize(c.getType());
+ NumberExpression minE = c.getMin();
+ String min = verbalizeMin(minE, Integer.MIN_VALUE);
+ NumberExpression maxE = c.getMax();
+ String max = verbalizeMax(maxE, Integer.MAX_VALUE);
+ String var = c.getVar() == null ? "" : "," + c.getVar();
+ return name + min.replaceFirst("[,]", "") + max + var + ")";
+ } else if (condition instanceof TotalCountCondition) {
+ TotalCountCondition c = (TotalCountCondition) condition;
+ String name = "TOTALCOUNT(";
+ String type = verbalizer.verbalize(c.getType());
+ NumberExpression minE = c.getMin();
+ String min = verbalizeMin(minE, Integer.MIN_VALUE);
+ NumberExpression maxE = c.getMax();
+ String max = verbalizeMax(maxE, Integer.MAX_VALUE);
+ String var = c.getVar() == null ? "" : "," + c.getVar();
+ return name + type + min + max + var + ")";
+ } else if (condition instanceof VoteCondition) {
+ VoteCondition c = (VoteCondition) condition;
+ String name = "VOTE(";
+ String type1 = verbalizer.verbalize(c.getType1());
+ String type2 = verbalizer.verbalize(c.getType2());
+ return name + type1 + "," + type2 + ")";
+ } else if (condition instanceof FeatureCondition) {
+ FeatureCondition c = (FeatureCondition) condition;
+ String e1 = verbalizer.verbalize(c.getFeatureStringExpression());
+ String name = "";
+ String e2 = "";
+ if (c.getBooleanExpr() != null) {
+ name = "FEATURE(";
+ e2 = verbalizer.verbalize(c.getBooleanExpr());
+ } else if (c.getNumberExpr() != null) {
+ name = "FEATURE(";
+ e2 = verbalizer.verbalize(c.getNumberExpr());
+ } else if (c.getStringExpr() != null) {
+ name = "FEATURE(";
+ e2 = verbalizer.verbalize(c.getStringExpr());
+ }
+ return name + e1 + "," + e2 + ")";
+ } else if (condition instanceof ParseCondition) {
+ ParseCondition c = (ParseCondition) condition;
+ String name = "PARSE(";
+ String var = c.getVar();
+ return name + var + ")";
+ } else if (condition instanceof IsCondition) {
+ IsCondition c = (IsCondition) condition;
+ String name = "IS(";
+ String type = verbalizer.verbalize(c.getType());
+ return name + type + ")";
+ } else if (condition instanceof BeforeCondition) {
+ BeforeCondition c = (BeforeCondition) condition;
+ String name = "BEFORE(";
+ String type = verbalizer.verbalize(c.getType());
+ return name + type + ")";
+ } else if (condition instanceof AfterCondition) {
+ AfterCondition c = (AfterCondition) condition;
+ String name = "AFTER(";
+ String type = verbalizer.verbalize(c.getType());
+ return name + type + ")";
+ } else if (condition instanceof StartsWithCondition) {
+ StartsWithCondition c = (StartsWithCondition) condition;
+ String name = "STARTSWITH(";
+ String type = verbalizer.verbalize(c.getType());
+ return name + type + ")";
+ } else if (condition instanceof EndsWithCondition) {
+ EndsWithCondition c = (EndsWithCondition) condition;
+ String name = "ENDSWITH(";
+ String type = verbalizer.verbalize(c.getType());
+ return name + type + ")";
+ } else if (condition instanceof SizeCondition) {
+ SizeCondition c = (SizeCondition) condition;
+ String name = "SIZE(";
+ NumberExpression minE = c.getMinExpr();
+ String min = verbalizeMin(minE, Integer.MIN_VALUE);
+ NumberExpression maxE = c.getMaxExpr();
+ String max = verbalizeMax(maxE, Integer.MAX_VALUE);
+ String var = c.getVarExpr() == null ? "" : "," + c.getVarExpr();
+ return name + min + max + var + ")";
+ }
+
+ return condition.getClass().getSimpleName();
+ }
+
+ private String verbalizeMax(NumberExpression maxE, int def) {
+ String max = "";
+ if (!(maxE instanceof SimpleNumberExpression && ((SimpleNumberExpression) maxE).getNumber()
+ .equals(def))) {
+ max = "," + verbalizer.verbalize(maxE);
+ }
+ return max;
+ }
+
+ private String verbalizeMin(NumberExpression minE, int def) {
+ String min = "";
+ if (!(minE instanceof SimpleNumberExpression && ((SimpleNumberExpression) minE).getNumber()
+ .equals(def))) {
+ min = "," + verbalizer.verbalize(minE);
+ }
+ return min;
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/verbalize/ConditionVerbalizer.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/verbalize/ConditionVerbalizer.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/verbalize/ExpressionVerbalizer.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/verbalize/ExpressionVerbalizer.java?rev=1152824&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/verbalize/ExpressionVerbalizer.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/verbalize/ExpressionVerbalizer.java Mon Aug 1 15:24:44 2011
@@ -0,0 +1,238 @@
+package org.apache.uima.tm.textmarker.verbalize;
+
+import java.util.Iterator;
+
+import org.apache.uima.cas.Type;
+import org.apache.uima.tm.textmarker.kernel.expression.TextMarkerExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.bool.BooleanExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.bool.BooleanNumberExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.bool.BooleanTypeExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.bool.ReferenceBooleanExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.bool.SimpleBooleanExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.list.ListExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.list.ReferenceBooleanListExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.list.ReferenceNumberListExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.list.ReferenceStringListExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.list.ReferenceTypeListExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.list.SimpleBooleanListExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.list.SimpleNumberListExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.list.SimpleStringListExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.list.SimpleTypeListExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.number.ComposedDoubleExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.number.ComposedIntegerExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.number.NegativeNumberExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.number.NumberExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.number.ReferenceDoubleExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.number.ReferenceIntegerExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.number.SimpleNumberExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.resource.ReferenceWordListExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.resource.ReferenceWordTableExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.resource.WordListExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.resource.WordTableExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.string.ComposedStringExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.string.LiteralStringExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.string.ReferenceStringExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.string.SimpleStringExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.string.StringExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.type.ReferenceTypeExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.type.SimpleTypeExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.type.TypeExpression;
+
+
+public class ExpressionVerbalizer {
+
+ private TextMarkerVerbalizer verbalizer;
+
+ public ExpressionVerbalizer(TextMarkerVerbalizer verbalizer) {
+ super();
+ this.verbalizer = verbalizer;
+ }
+
+ public String verbalize(TextMarkerExpression expression) {
+ if (expression instanceof TypeExpression) {
+ return verbalize((TypeExpression) expression);
+ } else if (expression instanceof BooleanExpression) {
+ return verbalize((BooleanExpression) expression);
+ } else if (expression instanceof NumberExpression) {
+ return verbalize((NumberExpression) expression);
+ } else if (expression instanceof WordListExpression) {
+ return verbalize((WordListExpression) expression);
+ } else if (expression instanceof WordTableExpression) {
+ return verbalize((WordTableExpression) expression);
+ } else if (expression instanceof ListExpression<?>) {
+ return verbalize((ListExpression<?>) expression);
+ } else if (expression instanceof StringExpression) {
+ return verbalize((StringExpression) expression);
+ }
+ return expression.getClass().getSimpleName();
+ }
+
+ public String verbalize(WordTableExpression expression) {
+ if (expression instanceof ReferenceWordTableExpression) {
+ ReferenceWordTableExpression e = (ReferenceWordTableExpression) expression;
+ return e.getRef();
+ }
+ return expression.getClass().getSimpleName();
+ }
+
+ public String verbalize(WordListExpression expression) {
+ if (expression instanceof ReferenceWordListExpression) {
+ ReferenceWordListExpression e = (ReferenceWordListExpression) expression;
+ return e.getRef();
+ }
+ return expression.getClass().getSimpleName();
+ }
+
+ public String verbalize(ListExpression<?> expression) {
+ if (expression instanceof SimpleBooleanListExpression) {
+ SimpleBooleanListExpression e = (SimpleBooleanListExpression) expression;
+ return "{" + verbalizer.verbalizeExpressionList(e.getList()) + "}";
+ } else if (expression instanceof ReferenceBooleanListExpression) {
+ ReferenceBooleanListExpression e = (ReferenceBooleanListExpression) expression;
+ return e.getVar();
+ } else if (expression instanceof SimpleNumberListExpression) {
+ SimpleNumberListExpression e = (SimpleNumberListExpression) expression;
+ return "{" + verbalizer.verbalizeExpressionList(e.getList()) + "}";
+ } else if (expression instanceof ReferenceNumberListExpression) {
+ ReferenceNumberListExpression e = (ReferenceNumberListExpression) expression;
+ return e.getVar();
+ } else if (expression instanceof SimpleStringListExpression) {
+ SimpleStringListExpression e = (SimpleStringListExpression) expression;
+ return "{" + verbalizer.verbalizeExpressionList(e.getList()) + "}";
+ } else if (expression instanceof ReferenceStringListExpression) {
+ ReferenceStringListExpression e = (ReferenceStringListExpression) expression;
+ return e.getVar();
+ } else if (expression instanceof SimpleTypeListExpression) {
+ SimpleTypeListExpression e = (SimpleTypeListExpression) expression;
+ return "{" + verbalizer.verbalizeExpressionList(e.getList()) + "}";
+ } else if (expression instanceof ReferenceTypeListExpression) {
+ ReferenceTypeListExpression e = (ReferenceTypeListExpression) expression;
+ return e.getVar();
+ }
+ return expression.getClass().getSimpleName();
+ }
+
+ public String verbalize(NumberExpression expression) {
+ if (expression == null) {
+ return "";
+ } else if (expression instanceof NegativeNumberExpression) {
+ NegativeNumberExpression e = (NegativeNumberExpression) expression;
+ return "-(" + e.getExpression() + ")";
+ } else if (expression instanceof ReferenceDoubleExpression) {
+ ReferenceDoubleExpression e = (ReferenceDoubleExpression) expression;
+ return e.getVar();
+ } else if (expression instanceof ReferenceIntegerExpression) {
+ ReferenceIntegerExpression e = (ReferenceIntegerExpression) expression;
+ return e.getVar();
+ } else if (expression instanceof SimpleNumberExpression) {
+ SimpleNumberExpression e = (SimpleNumberExpression) expression;
+ return e.getNumber().toString();
+ } else if (expression instanceof ComposedDoubleExpression) {
+ ComposedDoubleExpression e = (ComposedDoubleExpression) expression;
+ NumberExpression ne = e.getExpressions().get(0);
+ if (ne == null) {
+ return "";
+ }
+ StringBuilder result = new StringBuilder(verbalize(ne));
+ for (int i = 0; i < e.getOperators().size(); i++) {
+ result.append(e.getOperators().get(i));
+ if (e.getExpressions().size() > i + 1) {
+ result.append(verbalize(e.getExpressions().get(i + 1)));
+ }
+ }
+ return result.toString();
+ } else if (expression instanceof ComposedIntegerExpression) {
+ ComposedIntegerExpression e = (ComposedIntegerExpression) expression;
+ NumberExpression ne = e.getExpressions().get(0);
+ if (ne == null) {
+ return "";
+ }
+ String result = verbalize(ne);
+ for (int i = 0; i < e.getOperators().size(); i++) {
+ result += e.getOperators().get(i) + verbalize(e.getExpressions().get(i + 1));
+ }
+ return result;
+ }
+ return expression.getClass().getSimpleName();
+ }
+
+ public String verbalize(BooleanExpression expression) {
+ if (expression == null) {
+ return "";
+ } else if (expression instanceof BooleanNumberExpression) {
+ BooleanNumberExpression e = (BooleanNumberExpression) expression;
+ return verbalize(e.getFristExpression()) + e.getOperator()
+ + verbalize(e.getSecondExpression());
+ } else if (expression instanceof BooleanTypeExpression) {
+ BooleanTypeExpression e = (BooleanTypeExpression) expression;
+ return verbalize(e.getFristExpression()) + e.getOperator()
+ + verbalize(e.getSecondExpression());
+ } else if (expression instanceof ReferenceBooleanExpression) {
+ ReferenceBooleanExpression e = (ReferenceBooleanExpression) expression;
+ return e.getVar();
+ } else if (expression instanceof SimpleBooleanExpression) {
+ SimpleBooleanExpression e = (SimpleBooleanExpression) expression;
+ return e.getPrimitiveValue() ? "true" : "false";
+ }
+ return expression.getClass().getSimpleName();
+ }
+
+ public String verbalize(StringExpression expression) {
+ if (expression == null) {
+ return "";
+ } else if (expression instanceof NumberExpression) {
+ return verbalize((NumberExpression) expression);
+ } else if (expression instanceof TypeExpression) {
+ return verbalize((TypeExpression) expression);
+ } else if (expression instanceof BooleanExpression) {
+ return verbalize((BooleanExpression) expression);
+ } else if (expression instanceof ListExpression) {
+ return verbalize((ListExpression) expression);
+ } else if (expression instanceof LiteralStringExpression) {
+ return verbalize((LiteralStringExpression) expression);
+ }
+ return expression.getClass().getSimpleName();
+ }
+
+ public String verbalize(LiteralStringExpression expression) {
+ if (expression == null) {
+ return "";
+ } else if (expression instanceof ComposedStringExpression) {
+ ComposedStringExpression e = (ComposedStringExpression) expression;
+ StringBuilder sb = new StringBuilder();
+ Iterator<StringExpression> it = e.getExpressions().iterator();
+ while (it.hasNext()) {
+ StringExpression each = it.next();
+ sb.append(verbalize(each));
+ if (it.hasNext()) {
+ sb.append("+");
+ }
+ }
+ return sb.toString();
+ } else if (expression instanceof ReferenceStringExpression) {
+ ReferenceStringExpression e = (ReferenceStringExpression) expression;
+ return e.getVar();
+ } else if (expression instanceof SimpleStringExpression) {
+ SimpleStringExpression e = (SimpleStringExpression) expression;
+ return "\"" + e.getValue() + "\"";
+ }
+ return expression.getClass().getSimpleName();
+ }
+
+ public String verbalize(TypeExpression expression) {
+ if (expression instanceof SimpleTypeExpression) {
+ SimpleTypeExpression e = (SimpleTypeExpression) expression;
+ Type type = e.getType(null);
+ String shortName = type.getShortName();
+ if (shortName.equals("DocumentAnnotation")) {
+ shortName = "Document";
+ }
+ return shortName;
+ } else if (expression instanceof ReferenceTypeExpression) {
+ ReferenceTypeExpression e = (ReferenceTypeExpression) expression;
+ return e.getVar();
+ }
+ return expression.getClass().getSimpleName();
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/verbalize/ExpressionVerbalizer.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/verbalize/ExpressionVerbalizer.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/verbalize/ScriptVerbalizer.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/verbalize/ScriptVerbalizer.java?rev=1152824&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/verbalize/ScriptVerbalizer.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/verbalize/ScriptVerbalizer.java Mon Aug 1 15:24:44 2011
@@ -0,0 +1,165 @@
+package org.apache.uima.tm.textmarker.verbalize;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.uima.tm.textmarker.action.AbstractTextMarkerAction;
+import org.apache.uima.tm.textmarker.condition.AbstractTextMarkerCondition;
+import org.apache.uima.tm.textmarker.kernel.TextMarkerBlock;
+import org.apache.uima.tm.textmarker.kernel.TextMarkerElement;
+import org.apache.uima.tm.textmarker.kernel.TextMarkerStatement;
+import org.apache.uima.tm.textmarker.kernel.rule.ComposedRuleElement;
+import org.apache.uima.tm.textmarker.kernel.rule.RuleElement;
+import org.apache.uima.tm.textmarker.kernel.rule.TextMarkerMatcher;
+import org.apache.uima.tm.textmarker.kernel.rule.TextMarkerRule;
+import org.apache.uima.tm.textmarker.kernel.rule.TextMarkerRuleElement;
+import org.apache.uima.tm.textmarker.kernel.rule.quantifier.MinMaxGreedy;
+import org.apache.uima.tm.textmarker.kernel.rule.quantifier.MinMaxReluctant;
+import org.apache.uima.tm.textmarker.kernel.rule.quantifier.NormalQuantifier;
+import org.apache.uima.tm.textmarker.kernel.rule.quantifier.PlusGreedy;
+import org.apache.uima.tm.textmarker.kernel.rule.quantifier.PlusReluctant;
+import org.apache.uima.tm.textmarker.kernel.rule.quantifier.QuestionGreedy;
+import org.apache.uima.tm.textmarker.kernel.rule.quantifier.QuestionReluctant;
+import org.apache.uima.tm.textmarker.kernel.rule.quantifier.RuleElementQuantifier;
+import org.apache.uima.tm.textmarker.kernel.rule.quantifier.StarGreedy;
+import org.apache.uima.tm.textmarker.kernel.rule.quantifier.StarReluctant;
+
+
+public class ScriptVerbalizer {
+
+ private TextMarkerVerbalizer verbalizer;
+
+ public ScriptVerbalizer(TextMarkerVerbalizer verbalizer) {
+ super();
+ this.verbalizer = verbalizer;
+ }
+
+ public String verbalizeBlock(TextMarkerBlock block, boolean withElements) {
+ StringBuilder result = new StringBuilder();
+ TextMarkerRule rule = block.getRule();
+ List<TextMarkerStatement> elements = block.getElements();
+ result.append("BLOCK(");
+ result.append(block.getId());
+ result.append(")");
+ result.append(" ");
+ if (rule != null) {
+ result.append(verbalizeRule(rule));
+ }
+ if (withElements) {
+ result.append(" {\n");
+ for (TextMarkerStatement each : elements) {
+ if (each instanceof TextMarkerBlock) {
+ result.append(verbalizeBlock((TextMarkerBlock) each, withElements));
+ } else if (each instanceof TextMarkerRule) {
+ result.append(verbalizeRule((TextMarkerRule) each));
+ }
+ result.append(";");
+ result.append("\n");
+ }
+ result.append(" }\n");
+ }
+ return result.toString();
+ }
+
+ public String verbalizeRule(TextMarkerRule rule) {
+ List<RuleElement> elements = rule.getElements();
+ StringBuilder result = new StringBuilder();
+ for (RuleElement each : elements) {
+ result.append(verbalizeRuleElement(each));
+ result.append(" ");
+ }
+ return result.toString();
+ }
+
+ public String verbalizeRuleElement(RuleElement re) {
+ if (re instanceof TextMarkerRuleElement) {
+ TextMarkerRuleElement element = (TextMarkerRuleElement) re;
+ TextMarkerMatcher matcher = element.getMatcher();
+ List<AbstractTextMarkerCondition> conditions = element.getConditions();
+ List<AbstractTextMarkerAction> actions = element.getActions();
+ RuleElementQuantifier quantifier = element.getQuantifier();
+ StringBuilder result = new StringBuilder();
+ result.append(verbalizer.verbalize(matcher.getExpression()));
+ result.append(verbalizeQuantifier(quantifier));
+
+ if (!conditions.isEmpty() || !actions.isEmpty()) {
+ result.append("{");
+ Iterator<AbstractTextMarkerCondition> cit = conditions.iterator();
+ while (cit.hasNext()) {
+ AbstractTextMarkerCondition each = cit.next();
+ result.append(verbalizer.verbalize(each));
+ if (cit.hasNext()) {
+ result.append(",");
+ }
+ }
+ if (!actions.isEmpty()) {
+ result.append(" -> ");
+ Iterator<AbstractTextMarkerAction> ait = actions.iterator();
+ while (ait.hasNext()) {
+ AbstractTextMarkerAction each = ait.next();
+ result.append(verbalizer.verbalize(each));
+ if (ait.hasNext()) {
+ result.append(",");
+ }
+ }
+ }
+ result.append("}");
+ }
+ return result.toString();
+ } else if (re instanceof ComposedRuleElement) {
+ ComposedRuleElement cre = (ComposedRuleElement) re;
+ StringBuilder result = new StringBuilder("(");
+ for (RuleElement each : cre.getElements()) {
+ if (cre.getElements().indexOf(each) != 0) {
+ result.append(" ");
+ }
+ result.append(verbalizeRuleElement(each));
+ }
+ result.append(")");
+ result.append(verbalizeQuantifier(cre.getQuantifier()));
+ return result.toString();
+ }
+ return "";
+ }
+
+ public String verbalizeQuantifier(RuleElementQuantifier quantifier) {
+ if (quantifier instanceof NormalQuantifier) {
+ return "";
+ } else if (quantifier instanceof MinMaxGreedy) {
+ MinMaxGreedy mmg = (MinMaxGreedy) quantifier;
+ return "[" + verbalizer.verbalize(mmg.getMin()) + "," + verbalizer.verbalize(mmg.getMax())
+ + "]";
+ } else if (quantifier instanceof MinMaxReluctant) {
+ MinMaxReluctant mmr = (MinMaxReluctant) quantifier;
+ return "[" + verbalizer.verbalize(mmr.getMin()) + "," + verbalizer.verbalize(mmr.getMax())
+ + "]?";
+ } else if (quantifier instanceof PlusGreedy) {
+ return "+";
+ } else if (quantifier instanceof PlusReluctant) {
+ return "+?";
+ } else if (quantifier instanceof QuestionGreedy) {
+ return "?";
+ } else if (quantifier instanceof QuestionReluctant) {
+ return "??";
+ } else if (quantifier instanceof StarGreedy) {
+ return "*";
+ } else if (quantifier instanceof StarReluctant) {
+ return "*?";
+ }
+ return null;
+ }
+
+ public String verbalize(TextMarkerElement element) {
+ if (element instanceof TextMarkerBlock) {
+ return verbalizeBlock((TextMarkerBlock) element, false);
+ } else if (element instanceof RuleElementQuantifier) {
+ return verbalizeQuantifier((RuleElementQuantifier) element);
+ } else if (element instanceof TextMarkerRule) {
+ return verbalizeRule((TextMarkerRule) element);
+ } else if (element instanceof TextMarkerRuleElement) {
+ return verbalizeRuleElement((TextMarkerRuleElement) element);
+ }
+ return null;
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/verbalize/ScriptVerbalizer.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/verbalize/ScriptVerbalizer.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/verbalize/TextMarkerVerbalizer.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/verbalize/TextMarkerVerbalizer.java?rev=1152824&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/verbalize/TextMarkerVerbalizer.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/verbalize/TextMarkerVerbalizer.java Mon Aug 1 15:24:44 2011
@@ -0,0 +1,100 @@
+package org.apache.uima.tm.textmarker.verbalize;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.uima.cas.Type;
+import org.apache.uima.tm.textmarker.action.AbstractTextMarkerAction;
+import org.apache.uima.tm.textmarker.condition.AbstractTextMarkerCondition;
+import org.apache.uima.tm.textmarker.kernel.TextMarkerBlock;
+import org.apache.uima.tm.textmarker.kernel.TextMarkerElement;
+import org.apache.uima.tm.textmarker.kernel.expression.TextMarkerExpression;
+import org.apache.uima.tm.textmarker.kernel.extensions.ITextMarkerExtension;
+import org.apache.uima.tm.textmarker.kernel.rule.RuleElement;
+
+
+public class TextMarkerVerbalizer {
+
+ private Map<Class<?>, ITextMarkerExtension> externalVerbalizers = new HashMap<Class<?>, ITextMarkerExtension>();
+
+ private ActionVerbalizer actionVerbalizer;
+
+ private ConditionVerbalizer conditionVerbalizer;
+
+ private ExpressionVerbalizer expressionVerbalizer;
+
+ private ScriptVerbalizer scriptVerbalizer;
+
+ private VerbalizerUtils verbalizerUtils;
+
+ public TextMarkerVerbalizer() {
+ super();
+ actionVerbalizer = new ActionVerbalizer(this);
+ conditionVerbalizer = new ConditionVerbalizer(this);
+ expressionVerbalizer = new ExpressionVerbalizer(this);
+ scriptVerbalizer = new ScriptVerbalizer(this);
+ verbalizerUtils = new VerbalizerUtils(this);
+ }
+
+ public void addExternalVerbalizers(ITextMarkerExtension verbalizer) {
+ Class<?>[] extensions = verbalizer.extensions();
+ for (Class<?> eachClass : extensions) {
+ externalVerbalizers.put(eachClass, verbalizer);
+ }
+ }
+
+ public String verbalize(TextMarkerElement element) {
+ if (externalVerbalizers.keySet().contains(element.getClass())) {
+ return externalVerbalizers.get(element.getClass()).verbalize(element, this);
+ } else if (element instanceof AbstractTextMarkerAction) {
+ return actionVerbalizer.verbalize((AbstractTextMarkerAction) element);
+ } else if (element instanceof AbstractTextMarkerCondition) {
+ return conditionVerbalizer.verbalize((AbstractTextMarkerCondition) element);
+ } else if (element instanceof TextMarkerExpression) {
+ return expressionVerbalizer.verbalize((TextMarkerExpression) element);
+ } else {
+ return scriptVerbalizer.verbalize(element);
+ }
+ }
+
+ public String verbalizeName(TextMarkerElement element) {
+ if (externalVerbalizers.keySet().contains(element.getClass())) {
+ return externalVerbalizers.get(element.getClass()).verbalizeName(element);
+ } else if (element instanceof AbstractTextMarkerAction) {
+ return actionVerbalizer.verbalizeName((AbstractTextMarkerAction) element);
+ } else if (element instanceof AbstractTextMarkerCondition) {
+ return conditionVerbalizer.verbalizeName((AbstractTextMarkerCondition) element);
+ }
+ return element.getClass().getSimpleName();
+ }
+
+ public String verbalize(TextMarkerBlock block, boolean withElements) {
+ return scriptVerbalizer.verbalizeBlock(block, withElements);
+ }
+
+ public String verbalize(RuleElement element) {
+ return scriptVerbalizer.verbalizeRuleElement(element);
+ }
+
+ public String verbalizeType(Type type) {
+ if (type.getName().equals("uima.tcas.DocumentAnnotation")) {
+ return "Document";
+ } else {
+ return type.getShortName();
+ }
+ }
+
+ public String verbalizeList(List<?> list) {
+ return verbalizerUtils.verbalizeList(list);
+ }
+
+ public String verbalizeTypeList(List<Type> list) {
+ return verbalizerUtils.verbalizeTypeList(list);
+ }
+
+ public String verbalizeExpressionList(List<? extends TextMarkerExpression> list) {
+ return verbalizerUtils.verbalizeExpressionList(list);
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/verbalize/TextMarkerVerbalizer.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/verbalize/TextMarkerVerbalizer.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/verbalize/VerbalizerUtils.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/verbalize/VerbalizerUtils.java?rev=1152824&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/verbalize/VerbalizerUtils.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/verbalize/VerbalizerUtils.java Mon Aug 1 15:24:44 2011
@@ -0,0 +1,58 @@
+package org.apache.uima.tm.textmarker.verbalize;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.uima.cas.Type;
+import org.apache.uima.tm.textmarker.kernel.expression.TextMarkerExpression;
+
+
+public class VerbalizerUtils {
+
+ private TextMarkerVerbalizer verbalizer;
+
+ public VerbalizerUtils(TextMarkerVerbalizer verbalizer) {
+ super();
+ this.verbalizer = verbalizer;
+ }
+
+ public String verbalizeList(List<?> list) {
+ StringBuilder result = new StringBuilder();
+ Iterator<?> it = list.iterator();
+ while (it.hasNext()) {
+ Object obj = it.next();
+ result.append(obj.toString());
+ if (it.hasNext()) {
+ result.append(", ");
+ }
+ }
+ return result.toString();
+ }
+
+ public String verbalizeTypeList(List<Type> list) {
+ StringBuilder result = new StringBuilder();
+ Iterator<Type> it = list.iterator();
+ while (it.hasNext()) {
+ Type type = it.next();
+ result.append(verbalizer.verbalizeType(type));
+ if (it.hasNext()) {
+ result.append(", ");
+ }
+ }
+ return result.toString();
+ }
+
+ public String verbalizeExpressionList(List<? extends TextMarkerExpression> list) {
+ StringBuilder result = new StringBuilder();
+ Iterator<? extends TextMarkerExpression> it = list.iterator();
+ while (it.hasNext()) {
+ TextMarkerExpression e = it.next();
+ result.append(verbalizer.verbalize(e));
+ if (it.hasNext()) {
+ result.append(", ");
+ }
+ }
+ return result.toString();
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/verbalize/VerbalizerUtils.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/verbalize/VerbalizerUtils.java
------------------------------------------------------------------------------
svn:mime-type = text/plain