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 [3/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/action/MarkTableAction.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/action/MarkTableAction.java?rev=1152824&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/MarkTableAction.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/MarkTableAction.java Mon Aug 1 15:24:44 2011
@@ -0,0 +1,110 @@
+package org.apache.uima.tm.textmarker.action;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.uima.cas.Feature;
+import org.apache.uima.cas.FeatureStructure;
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.jcas.cas.TOP;
+import org.apache.uima.jcas.tcas.Annotation;
+import org.apache.uima.tm.textmarker.kernel.TextMarkerBlock;
+import org.apache.uima.tm.textmarker.kernel.TextMarkerStream;
+import org.apache.uima.tm.textmarker.kernel.expression.number.NumberExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.resource.WordTableExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.string.StringExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.type.TypeExpression;
+import org.apache.uima.tm.textmarker.kernel.rule.RuleMatch;
+import org.apache.uima.tm.textmarker.kernel.rule.TextMarkerRuleElement;
+import org.apache.uima.tm.textmarker.kernel.type.TextMarkerBasic;
+import org.apache.uima.tm.textmarker.kernel.visitor.InferenceCrowd;
+import org.apache.uima.tm.textmarker.resource.TextMarkerTable;
+import org.apache.uima.tm.textmarker.resource.TextMarkerWordList;
+
+
+public class MarkTableAction extends AbstractTextMarkerAction {
+
+ private final TypeExpression typeExpr;
+
+ private final WordTableExpression tableExpr;
+
+ private final Map<StringExpression, NumberExpression> featureMap;
+
+ private final NumberExpression indexExpr;
+
+ public MarkTableAction(TypeExpression typeExpr, NumberExpression indexExpr,
+ WordTableExpression tableExpr, Map<StringExpression, NumberExpression> featureMap) {
+ super();
+ this.typeExpr = typeExpr;
+ this.indexExpr = indexExpr;
+ this.tableExpr = tableExpr;
+ this.featureMap = featureMap;
+ }
+
+ @Override
+ public void execute(RuleMatch match, TextMarkerRuleElement element, TextMarkerStream stream,
+ InferenceCrowd crowd) {
+ TextMarkerBlock block = element.getParent();
+ TextMarkerTable table = tableExpr.getTable(block);
+ int index = indexExpr.getIntegerValue(block);
+ Type type = typeExpr.getType(block);
+ Map<String, Integer> map = new HashMap<String, Integer>();
+ for (StringExpression each : featureMap.keySet()) {
+ map.put(each.getStringValue(block), featureMap.get(each).getIntegerValue(block));
+ }
+ TextMarkerWordList wordList = table.getWordList(index);
+ Collection<AnnotationFS> found = wordList.find(stream, false, 0, new char[] {}, 0);
+ for (AnnotationFS annotationFS : found) {
+ List<String> rowWhere = table.getRowWhere(index - 1, annotationFS.getCoveredText());
+ FeatureStructure newFS = stream.getCas().createFS(type);
+ if (newFS instanceof Annotation) {
+ Annotation a = (Annotation) newFS;
+ a.setBegin(annotationFS.getBegin());
+ a.setEnd(annotationFS.getEnd());
+ TextMarkerBasic first = stream.getFirstBasicInWindow(annotationFS);
+ if (first == null) {
+ first = match.getFirstBasic();
+ }
+ stream.addAnnotation(first, a);
+ }
+ TOP newStructure = null;
+ if (newFS instanceof TOP) {
+ newStructure = (TOP) newFS;
+ fillFeatures(newStructure, map, annotationFS, element, rowWhere, stream);
+ newStructure.addToIndexes();
+ }
+ }
+ }
+
+ private void fillFeatures(TOP structure, Map<String, Integer> map, AnnotationFS annotationFS,
+ TextMarkerRuleElement element, List<String> row, TextMarkerStream stream) {
+ List<?> featuresList = structure.getType().getFeatures();
+ for (int i = 0; i < featuresList.size(); i++) {
+ Feature targetFeature = (Feature) featuresList.get(i);
+ String name = targetFeature.getName();
+ String shortFName = name.substring(name.indexOf(":") + 1, name.length());
+ Integer entryIndex = map.get(shortFName);
+ Type range = targetFeature.getRange();
+ if (entryIndex != null && row.size() >= entryIndex) {
+ String value = row.get(entryIndex - 1);
+ if (range.getName().equals("uima.cas.String")) {
+ structure.setStringValue(targetFeature, value);
+ } else if (range.getName().equals("uima.cas.Integer")) {
+ Integer integer = Integer.parseInt(value);
+ structure.setIntValue(targetFeature, integer);
+ } else if (range.getName().equals("uima.cas.Double")) {
+ Double d = Double.parseDouble(value);
+ structure.setDoubleValue(targetFeature, d);
+ } else if (range.getName().equals("uima.cas.Boolean")) {
+ Boolean b = Boolean.parseBoolean(value);
+ structure.setBooleanValue(targetFeature, b);
+ } else {
+ }
+ }
+
+ }
+ }
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/MarkTableAction.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/MarkTableAction.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/action/MatchedTextAction.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/action/MatchedTextAction.java?rev=1152824&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/MatchedTextAction.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/MatchedTextAction.java Mon Aug 1 15:24:44 2011
@@ -0,0 +1,59 @@
+package org.apache.uima.tm.textmarker.action;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.tm.textmarker.kernel.TextMarkerStream;
+import org.apache.uima.tm.textmarker.kernel.expression.number.NumberExpression;
+import org.apache.uima.tm.textmarker.kernel.rule.RuleMatch;
+import org.apache.uima.tm.textmarker.kernel.rule.TextMarkerRuleElement;
+import org.apache.uima.tm.textmarker.kernel.visitor.InferenceCrowd;
+
+
+public class MatchedTextAction extends AbstractTextMarkerAction {
+
+ private final String var;
+
+ private final List<NumberExpression> list;
+
+ public MatchedTextAction(String var, List<NumberExpression> list) {
+ super();
+ this.var = var;
+ this.list = list;
+ }
+
+ @Override
+ public void execute(RuleMatch match, TextMarkerRuleElement element, TextMarkerStream stream,
+ InferenceCrowd crowd) {
+ List<Integer> indexList = getIndexList(match, element);
+ AnnotationFS matchedAnnotation = match.getMatchedAnnotation(stream, indexList);
+ element.getParent().getEnvironment().setVariableValue(var, matchedAnnotation.getCoveredText());
+ }
+
+ public String getVar() {
+ return var;
+ }
+
+ public List<NumberExpression> getList() {
+ return list;
+ }
+
+ protected List<Integer> getIndexList(RuleMatch match, TextMarkerRuleElement element) {
+ List<Integer> indexList = new ArrayList<Integer>();
+ if (list == null || list.isEmpty()) {
+ int self = match.getRule().getElements().indexOf(element) + 1;
+ indexList.add(self);
+ return indexList;
+ }
+ int last = Integer.MAX_VALUE - 1;
+ for (NumberExpression each : list) {
+ int value = each.getIntegerValue(element.getParent());
+ for (int i = Math.min(value, last + 1); i < value; i++) {
+ indexList.add(i);
+ }
+ indexList.add(value);
+ }
+ return indexList;
+ }
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/MatchedTextAction.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/MatchedTextAction.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/action/MergeAction.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/action/MergeAction.java?rev=1152824&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/MergeAction.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/MergeAction.java Mon Aug 1 15:24:44 2011
@@ -0,0 +1,69 @@
+package org.apache.uima.tm.textmarker.action;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.collections.ListUtils;
+import org.apache.uima.tm.textmarker.kernel.TextMarkerStream;
+import org.apache.uima.tm.textmarker.kernel.expression.bool.BooleanExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.list.ListExpression;
+import org.apache.uima.tm.textmarker.kernel.rule.RuleMatch;
+import org.apache.uima.tm.textmarker.kernel.rule.TextMarkerRuleElement;
+import org.apache.uima.tm.textmarker.kernel.visitor.InferenceCrowd;
+
+
+public class MergeAction extends AbstractTextMarkerAction {
+
+ private List<ListExpression> lists;
+
+ private BooleanExpression unionExpr;
+
+ private String target;
+
+ public MergeAction(BooleanExpression union, String target, List<ListExpression> list) {
+ super();
+ this.unionExpr = union;
+ this.target = target;
+ this.lists = list;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public void execute(RuleMatch match, TextMarkerRuleElement element, TextMarkerStream stream,
+ InferenceCrowd crowd) {
+ boolean union = unionExpr.getBooleanValue(element.getParent());
+ List<Object> list = new ArrayList<Object>();
+ if (union) {
+ for (ListExpression<Object> each : lists) {
+ list.addAll(each.getList(element.getParent()));
+ }
+ } else {
+ List<Object> lastList = null;
+ for (int i = 1; i < lists.size(); i++) {
+ if (lastList != null) {
+ lastList = ListUtils.intersection(lastList, lists.get(i).getList(element.getParent()));
+ } else {
+ lastList = ListUtils.intersection(lists.get(i - 1).getList(element.getParent()), lists
+ .get(i).getList(element.getParent()));
+ }
+ }
+ list = lastList;
+ }
+ if (list != null) {
+ element.getParent().getEnvironment().setVariableValue(target, list);
+ }
+ }
+
+ public BooleanExpression getUnion() {
+ return unionExpr;
+ }
+
+ public List<ListExpression> getLists() {
+ return lists;
+ }
+
+ public String getTarget() {
+ return target;
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/MergeAction.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/MergeAction.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/action/RemoveAction.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/action/RemoveAction.java?rev=1152824&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/RemoveAction.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/RemoveAction.java Mon Aug 1 15:24:44 2011
@@ -0,0 +1,48 @@
+package org.apache.uima.tm.textmarker.action;
+
+import java.util.List;
+
+import org.apache.uima.tm.textmarker.kernel.TextMarkerStream;
+import org.apache.uima.tm.textmarker.kernel.expression.TextMarkerExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.list.ListExpression;
+import org.apache.uima.tm.textmarker.kernel.rule.RuleMatch;
+import org.apache.uima.tm.textmarker.kernel.rule.TextMarkerRuleElement;
+import org.apache.uima.tm.textmarker.kernel.visitor.InferenceCrowd;
+
+
+public class RemoveAction extends AbstractTextMarkerAction {
+
+ private String var;
+
+ private List<TextMarkerExpression> elements;
+
+ public RemoveAction(String var, List<TextMarkerExpression> list) {
+ super();
+ this.var = var;
+ this.elements = list;
+ }
+
+ public String getListExpr() {
+ return var;
+ }
+
+ public List<TextMarkerExpression> getElements() {
+ return elements;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public void execute(RuleMatch match, TextMarkerRuleElement element, TextMarkerStream stream,
+ InferenceCrowd crowd) {
+ List list = element.getParent().getEnvironment().getVariableValue(var, List.class);
+ for (TextMarkerExpression each : elements) {
+ if (each instanceof ListExpression) {
+ ListExpression l = (ListExpression) each;
+ list.removeAll(l.getList(element.getParent()));
+ } else {
+ list.remove(each);
+ }
+ }
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/RemoveAction.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/RemoveAction.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/action/RemoveDuplicateAction.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/action/RemoveDuplicateAction.java?rev=1152824&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/RemoveDuplicateAction.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/RemoveDuplicateAction.java Mon Aug 1 15:24:44 2011
@@ -0,0 +1,36 @@
+package org.apache.uima.tm.textmarker.action;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.uima.tm.textmarker.kernel.TextMarkerStream;
+import org.apache.uima.tm.textmarker.kernel.rule.RuleMatch;
+import org.apache.uima.tm.textmarker.kernel.rule.TextMarkerRuleElement;
+import org.apache.uima.tm.textmarker.kernel.visitor.InferenceCrowd;
+
+
+public class RemoveDuplicateAction extends AbstractTextMarkerAction {
+
+ private String var;
+
+ public RemoveDuplicateAction(String var) {
+ super();
+ this.var = var;
+ }
+
+ public String getListExpr() {
+ return var;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public void execute(RuleMatch match, TextMarkerRuleElement element, TextMarkerStream stream,
+ InferenceCrowd crowd) {
+ List list = element.getParent().getEnvironment().getVariableValue(var, List.class);
+ Set<Object> set = new HashSet<Object>(list);
+ element.getParent().getEnvironment().setVariableValue(var, new ArrayList<Object>(set));
+
+ }
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/RemoveDuplicateAction.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/RemoveDuplicateAction.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/action/ReplaceAction.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/action/ReplaceAction.java?rev=1152824&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/ReplaceAction.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/ReplaceAction.java Mon Aug 1 15:24:44 2011
@@ -0,0 +1,40 @@
+package org.apache.uima.tm.textmarker.action;
+
+import java.util.List;
+
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.tm.textmarker.kernel.TextMarkerStream;
+import org.apache.uima.tm.textmarker.kernel.expression.string.StringExpression;
+import org.apache.uima.tm.textmarker.kernel.rule.RuleMatch;
+import org.apache.uima.tm.textmarker.kernel.rule.TextMarkerRuleElement;
+import org.apache.uima.tm.textmarker.kernel.type.TextMarkerBasic;
+import org.apache.uima.tm.textmarker.kernel.visitor.InferenceCrowd;
+
+
+public class ReplaceAction extends AbstractTextMarkerAction {
+
+ public StringExpression getReplacement() {
+ return replacement;
+ }
+
+ private final StringExpression replacement;
+
+ public ReplaceAction(StringExpression replacement) {
+ super();
+ this.replacement = replacement;
+ }
+
+ @Override
+ public void execute(RuleMatch match, TextMarkerRuleElement element, TextMarkerStream stream,
+ InferenceCrowd crowd) {
+ AnnotationFS matchedAnnotation = match.getMatchedAnnotation(stream, null);
+ List<TextMarkerBasic> annotationsInWindow = stream.getBasicsInWindow(matchedAnnotation);
+ boolean replaced = false;
+ for (TextMarkerBasic textMarkerBasic : annotationsInWindow) {
+ textMarkerBasic.setReplacement(replaced ? "" : replacement
+ .getStringValue(element.getParent()));
+ replaced = true;
+ }
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/ReplaceAction.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/ReplaceAction.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/action/RetainMarkupAction.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/action/RetainMarkupAction.java?rev=1152824&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/RetainMarkupAction.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/RetainMarkupAction.java Mon Aug 1 15:24:44 2011
@@ -0,0 +1,35 @@
+package org.apache.uima.tm.textmarker.action;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.uima.tm.textmarker.kernel.TextMarkerStream;
+import org.apache.uima.tm.textmarker.kernel.expression.string.StringExpression;
+import org.apache.uima.tm.textmarker.kernel.rule.RuleMatch;
+import org.apache.uima.tm.textmarker.kernel.rule.TextMarkerRuleElement;
+import org.apache.uima.tm.textmarker.kernel.visitor.InferenceCrowd;
+
+
+public class RetainMarkupAction extends AbstractTextMarkerAction {
+
+ private List<StringExpression> markup;
+
+ public RetainMarkupAction(List<StringExpression> markup) {
+ super();
+ this.markup = markup;
+ }
+
+ @Override
+ public void execute(RuleMatch match, TextMarkerRuleElement element, TextMarkerStream stream,
+ InferenceCrowd crowd) {
+ List<String> list = new ArrayList<String>();
+ for (StringExpression each : markup) {
+ list.add(each.getStringValue(element.getParent()));
+ }
+ stream.retainTags(list);
+ }
+
+ public List<StringExpression> getMarkup() {
+ return markup;
+ }
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/RetainMarkupAction.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/RetainMarkupAction.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/action/RetainTypeAction.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/action/RetainTypeAction.java?rev=1152824&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/RetainTypeAction.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/RetainTypeAction.java Mon Aug 1 15:24:44 2011
@@ -0,0 +1,37 @@
+package org.apache.uima.tm.textmarker.action;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.uima.cas.Type;
+import org.apache.uima.tm.textmarker.kernel.TextMarkerStream;
+import org.apache.uima.tm.textmarker.kernel.expression.type.TypeExpression;
+import org.apache.uima.tm.textmarker.kernel.rule.RuleMatch;
+import org.apache.uima.tm.textmarker.kernel.rule.TextMarkerRuleElement;
+import org.apache.uima.tm.textmarker.kernel.visitor.InferenceCrowd;
+
+
+public class RetainTypeAction extends AbstractTextMarkerAction {
+
+ public List<TypeExpression> getList() {
+ return list;
+ }
+
+ private List<TypeExpression> list;
+
+ public RetainTypeAction(List<TypeExpression> list) {
+ super();
+ this.list = list;
+ }
+
+ @Override
+ public void execute(RuleMatch match, TextMarkerRuleElement element, TextMarkerStream stream,
+ InferenceCrowd crowd) {
+ List<Type> types = new ArrayList<Type>();
+ for (TypeExpression each : list) {
+ types.add(each.getType(element.getParent()));
+ }
+ stream.retainTypes(types);
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/RetainTypeAction.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/RetainTypeAction.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/action/SetFeatureAction.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/action/SetFeatureAction.java?rev=1152824&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/SetFeatureAction.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/SetFeatureAction.java Mon Aug 1 15:24:44 2011
@@ -0,0 +1,121 @@
+package org.apache.uima.tm.textmarker.action;
+
+import java.util.List;
+
+import org.apache.uima.cas.Feature;
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.jcas.tcas.Annotation;
+import org.apache.uima.tm.textmarker.kernel.TextMarkerStream;
+import org.apache.uima.tm.textmarker.kernel.expression.bool.BooleanExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.number.NumberExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.string.StringExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.type.TypeExpression;
+import org.apache.uima.tm.textmarker.kernel.rule.RuleMatch;
+import org.apache.uima.tm.textmarker.kernel.rule.TextMarkerRuleElement;
+import org.apache.uima.tm.textmarker.kernel.visitor.InferenceCrowd;
+import org.apache.uima.tm.textmarker.utils.UIMAUtils;
+
+
+public class SetFeatureAction extends AbstractTextMarkerAction {
+
+ private final StringExpression featureStringExpression;
+
+ private StringExpression stringExpr;
+
+ private NumberExpression numberExpr;
+
+ private BooleanExpression booleanExpr;
+
+ private TypeExpression typeExpr;
+
+ protected SetFeatureAction(StringExpression feature) {
+ super();
+ this.featureStringExpression = feature;
+ }
+
+ public SetFeatureAction(StringExpression feature, StringExpression stringExpr) {
+ this(feature);
+ this.stringExpr = stringExpr;
+ }
+
+ public SetFeatureAction(StringExpression feature, NumberExpression numberExpr) {
+ this(feature);
+ this.numberExpr = numberExpr;
+ }
+
+ public SetFeatureAction(StringExpression feature, BooleanExpression booleanExpr) {
+ this(feature);
+ this.booleanExpr = booleanExpr;
+ }
+
+ public SetFeatureAction(StringExpression feature, TypeExpression typeExpr) {
+ this(feature);
+ this.typeExpr = typeExpr;
+ }
+
+ public StringExpression getFeatureStringExpression() {
+ return featureStringExpression;
+ }
+
+ public StringExpression getStringExpr() {
+ return stringExpr;
+ }
+
+ public NumberExpression getNumberExpr() {
+ return numberExpr;
+ }
+
+ public BooleanExpression getBooleanExpr() {
+ return booleanExpr;
+ }
+
+ public TypeExpression getTypeExpr() {
+ return typeExpr;
+ }
+
+ @Override
+ public void execute(RuleMatch match, TextMarkerRuleElement element, TextMarkerStream stream,
+ InferenceCrowd crowd) {
+ Type type = element.getMatcher().getType(element.getParent(), stream);
+ if (type == null)
+ return;
+ String featureString = featureStringExpression.getStringValue(element.getParent());
+ Feature featureByBaseName = type.getFeatureByBaseName(featureString);
+ Annotation expandAnchor = (Annotation) stream.expandAnchor(match.getFirstBasic(), type);
+ if (expandAnchor.getType().getFeatureByBaseName(featureString) == null) {
+ System.out.println("Can't access feature " + featureString
+ + ", because it's not defined in the matched type: " + expandAnchor.getType());
+ return;
+ }
+ expandAnchor.removeFromIndexes();
+ if (stringExpr != null) {
+ String string = stringExpr.getStringValue(element.getParent());
+ expandAnchor.setStringValue(featureByBaseName, string);
+ } else if (numberExpr != null) {
+ String range = featureByBaseName.getRange().getName();
+ if (range.equals("uima.cas.Integer")) {
+ int v = numberExpr.getIntegerValue(element.getParent());
+ expandAnchor.setIntValue(featureByBaseName, v);
+ } else if (range.equals("uima.cas.Double")) {
+ double v = numberExpr.getDoubleValue(element.getParent());
+ expandAnchor.setDoubleValue(featureByBaseName, v);
+ }
+ } else if (booleanExpr != null) {
+ boolean v = booleanExpr.getBooleanValue(element.getParent());
+ expandAnchor.setBooleanValue(featureByBaseName, v);
+ } else if (typeExpr != null) {
+ Type t = typeExpr.getType(element.getParent());
+ List<AnnotationFS> inWindow = stream.getAnnotationsInWindow(expandAnchor, t);
+ if (featureByBaseName.getRange().isArray()) {
+ expandAnchor.setFeatureValue(featureByBaseName, UIMAUtils.toFSArray(stream.getJCas(),
+ inWindow));
+ } else {
+ AnnotationFS annotation = inWindow.get(0);
+ expandAnchor.setFeatureValue(featureByBaseName, annotation);
+ }
+ }
+ expandAnchor.addToIndexes();
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/SetFeatureAction.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/SetFeatureAction.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/action/TransferAction.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/action/TransferAction.java?rev=1152824&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/TransferAction.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/TransferAction.java Mon Aug 1 15:24:44 2011
@@ -0,0 +1,65 @@
+package org.apache.uima.tm.textmarker.action;
+
+import java.util.List;
+
+import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.Feature;
+import org.apache.uima.cas.FeatureStructure;
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.tm.textmarker.kernel.TextMarkerStream;
+import org.apache.uima.tm.textmarker.kernel.expression.type.TypeExpression;
+import org.apache.uima.tm.textmarker.kernel.rule.RuleElementMatch;
+import org.apache.uima.tm.textmarker.kernel.rule.RuleMatch;
+import org.apache.uima.tm.textmarker.kernel.rule.TextMarkerRuleElement;
+import org.apache.uima.tm.textmarker.kernel.type.TextMarkerBasic;
+import org.apache.uima.tm.textmarker.kernel.visitor.InferenceCrowd;
+
+
+public class TransferAction extends TypeSensitiveAction {
+
+ public TransferAction(TypeExpression type) {
+ super(type);
+ }
+
+ @Override
+ public void execute(RuleMatch match, TextMarkerRuleElement element, TextMarkerStream stream,
+ InferenceCrowd crowd) {
+ List<RuleElementMatch> list = match.getMatchInfos().get(element);
+ CAS cas = stream.getCas();
+ Type t = type.getType(element.getParent());
+ for (RuleElementMatch each : list) {
+ List<AnnotationFS> matched = each.getTextsMatched();
+ for (AnnotationFS annotationFS : matched) {
+ FeatureStructure createFS = cas.createFS(t);
+ copyFeatures(annotationFS, createFS, cas);
+ if (createFS instanceof AnnotationFS) {
+ TextMarkerBasic basic = stream.getFirstBasicInWindow(annotationFS);
+ stream.addAnnotation(basic, (AnnotationFS) createFS);
+ }
+ cas.addFsToIndexes(createFS);
+ }
+ }
+
+ }
+
+ private void copyFeatures(AnnotationFS oldFS, FeatureStructure newFS, CAS cas) {
+ List<?> features = oldFS.getType().getFeatures();
+ Type newType = newFS.getType();
+ for (Object object : features) {
+ Feature feature = (Feature) object;
+ String shortName = feature.getShortName();
+ Feature newFeature = newType.getFeatureByBaseName(shortName);
+ if (newFeature != null) {
+ if (feature.getRange().isPrimitive()) {
+ String value = oldFS.getFeatureValueAsString(newFeature);
+ newFS.setFeatureValueFromString(newFeature, value);
+ } else {
+ FeatureStructure value = oldFS.getFeatureValue(feature);
+ newFS.setFeatureValue(newFeature, value);
+ }
+ }
+ }
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/TransferAction.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/TransferAction.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/action/TrieAction.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/action/TrieAction.java?rev=1152824&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/TrieAction.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/TrieAction.java Mon Aug 1 15:24:44 2011
@@ -0,0 +1,111 @@
+package org.apache.uima.tm.textmarker.action;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.tm.textmarker.kernel.TextMarkerStream;
+import org.apache.uima.tm.textmarker.kernel.expression.bool.BooleanExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.number.NumberExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.resource.WordListExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.string.StringExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.type.TypeExpression;
+import org.apache.uima.tm.textmarker.kernel.rule.RuleMatch;
+import org.apache.uima.tm.textmarker.kernel.rule.TextMarkerRuleElement;
+import org.apache.uima.tm.textmarker.kernel.type.TextMarkerBasic;
+import org.apache.uima.tm.textmarker.kernel.visitor.InferenceCrowd;
+import org.apache.uima.tm.textmarker.resource.TextMarkerWordList;
+
+
+public class TrieAction extends AbstractTextMarkerAction {
+
+ private final WordListExpression list;
+
+ private final Map<StringExpression, TypeExpression> map;
+
+ private final BooleanExpression ignoreCase;
+
+ private final NumberExpression ignoreLength;
+
+ private final BooleanExpression edit;
+
+ private final NumberExpression distance;
+
+ private final StringExpression ignoreChar;
+
+ public TrieAction(WordListExpression list, Map<StringExpression, TypeExpression> map,
+ BooleanExpression ignoreCase, NumberExpression ignoreLength, BooleanExpression edit,
+ NumberExpression distance, StringExpression ignoreChar) {
+ this.list = list;
+ this.map = map;
+ this.ignoreCase = ignoreCase;
+ this.ignoreLength = ignoreLength;
+ this.edit = edit;
+ this.distance = distance;
+ this.ignoreChar = ignoreChar;
+ }
+
+ @Override
+ public void execute(RuleMatch match, TextMarkerRuleElement element, TextMarkerStream stream,
+ InferenceCrowd crowd) {
+
+ Map<String, Type> typeMap = new HashMap<String, Type>();
+ for (StringExpression eachKey : map.keySet()) {
+ String stringValue = eachKey.getStringValue(element.getParent());
+ TypeExpression typeExpression = map.get(eachKey);
+ if (typeExpression != null) {
+ Type typeValue = typeExpression.getType(element.getParent());
+ typeMap.put(stringValue, typeValue);
+ }
+ }
+ boolean ignoreCaseValue = ignoreCase.getBooleanValue(element.getParent());
+ int ignoreLengthValue = ignoreLength.getIntegerValue(element.getParent());
+ boolean editValue = edit.getBooleanValue(element.getParent());
+ double distanceValue = distance.getDoubleValue(element.getParent());
+ String ignoreCharValue = ignoreChar.getStringValue(element.getParent());
+
+ TextMarkerWordList wl = list.getList(element.getParent());
+ Collection<AnnotationFS> found = wl.find(stream, typeMap, ignoreCaseValue, ignoreLengthValue,
+ editValue, distanceValue, ignoreCharValue);
+
+ if (found != null) {
+ for (AnnotationFS annotation : found) {
+ TextMarkerBasic anchor = stream.getFirstBasicInWindow(annotation);
+ stream.addAnnotation(anchor, annotation);
+ stream.getCas().addFsToIndexes(annotation);
+ }
+ }
+
+ }
+
+ public WordListExpression getList() {
+ return list;
+ }
+
+ public Map<StringExpression, TypeExpression> getMap() {
+ return map;
+ }
+
+ public BooleanExpression getIgnoreCase() {
+ return ignoreCase;
+ }
+
+ public NumberExpression getIgnoreLength() {
+ return ignoreLength;
+ }
+
+ public BooleanExpression getEdit() {
+ return edit;
+ }
+
+ public NumberExpression getDistance() {
+ return distance;
+ }
+
+ public StringExpression getIgnoreChar() {
+ return ignoreChar;
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/TrieAction.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/TrieAction.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/action/TypeSensitiveAction.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/action/TypeSensitiveAction.java?rev=1152824&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/TypeSensitiveAction.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/TypeSensitiveAction.java Mon Aug 1 15:24:44 2011
@@ -0,0 +1,18 @@
+package org.apache.uima.tm.textmarker.action;
+
+import org.apache.uima.tm.textmarker.kernel.expression.type.TypeExpression;
+
+public abstract class TypeSensitiveAction extends AbstractTextMarkerAction {
+
+ protected TypeExpression type;
+
+ public TypeExpression getType() {
+ return type;
+ }
+
+ public TypeSensitiveAction(TypeExpression type) {
+ super();
+ this.type = type;
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/TypeSensitiveAction.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/TypeSensitiveAction.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/action/UnmarkAction.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/action/UnmarkAction.java?rev=1152824&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/UnmarkAction.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/UnmarkAction.java Mon Aug 1 15:24:44 2011
@@ -0,0 +1,37 @@
+package org.apache.uima.tm.textmarker.action;
+
+import java.util.List;
+
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.tm.textmarker.kernel.TextMarkerStream;
+import org.apache.uima.tm.textmarker.kernel.expression.type.TypeExpression;
+import org.apache.uima.tm.textmarker.kernel.rule.RuleElementMatch;
+import org.apache.uima.tm.textmarker.kernel.rule.RuleMatch;
+import org.apache.uima.tm.textmarker.kernel.rule.TextMarkerRuleElement;
+import org.apache.uima.tm.textmarker.kernel.type.TextMarkerBasic;
+import org.apache.uima.tm.textmarker.kernel.visitor.InferenceCrowd;
+
+
+public class UnmarkAction extends TypeSensitiveAction {
+
+ public UnmarkAction(TypeExpression type) {
+ super(type);
+ }
+
+ @Override
+ public void execute(RuleMatch match, TextMarkerRuleElement element, TextMarkerStream stream,
+ InferenceCrowd crowd) {
+ List<RuleElementMatch> matchInfo = match.getMatchInfo(element);
+ if (matchInfo == null || matchInfo.isEmpty()) {
+ return;
+ }
+ RuleElementMatch ruleElementMatch = matchInfo.get(0);
+ List<AnnotationFS> textsMatched = ruleElementMatch.getTextsMatched();
+ AnnotationFS first = textsMatched.get(0);
+ TextMarkerBasic firstBasicInWindow = stream.getFirstBasicInWindow(first);
+ Type t = type.getType(element.getParent());
+ stream.removeAnnotation(firstBasicInWindow, t);
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/UnmarkAction.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/UnmarkAction.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/action/UnmarkAllAction.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/action/UnmarkAllAction.java?rev=1152824&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/UnmarkAllAction.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/UnmarkAllAction.java Mon Aug 1 15:24:44 2011
@@ -0,0 +1,62 @@
+package org.apache.uima.tm.textmarker.action;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.TypeSystem;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.tm.textmarker.kernel.TextMarkerStream;
+import org.apache.uima.tm.textmarker.kernel.expression.list.TypeListExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.type.TypeExpression;
+import org.apache.uima.tm.textmarker.kernel.rule.RuleElementMatch;
+import org.apache.uima.tm.textmarker.kernel.rule.RuleMatch;
+import org.apache.uima.tm.textmarker.kernel.rule.TextMarkerRuleElement;
+import org.apache.uima.tm.textmarker.kernel.type.TextMarkerBasic;
+import org.apache.uima.tm.textmarker.kernel.visitor.InferenceCrowd;
+
+
+public class UnmarkAllAction extends TypeSensitiveAction {
+
+ private TypeListExpression list;
+
+ public UnmarkAllAction(TypeExpression type, TypeListExpression list) {
+ super(type);
+ this.list = list;
+ }
+
+ @Override
+ public void execute(RuleMatch match, TextMarkerRuleElement element, TextMarkerStream stream,
+ InferenceCrowd crowd) {
+ List<RuleElementMatch> matchInfo = match.getMatchInfo(element);
+ if (matchInfo == null || matchInfo.isEmpty()) {
+ return;
+ }
+ RuleElementMatch ruleElementMatch = matchInfo.get(0);
+ List<AnnotationFS> textsMatched = ruleElementMatch.getTextsMatched();
+ AnnotationFS first = textsMatched.get(0);
+ TextMarkerBasic firstBasicInWindow = stream.getFirstBasicInWindow(first);
+ Type t = type.getType(element.getParent());
+ TypeSystem typeSystem = stream.getCas().getTypeSystem();
+ List<Type> properlySubsumedTypes = typeSystem.getProperlySubsumedTypes(t);
+ List<Type> retainList = new ArrayList<Type>();
+
+ if (list != null) {
+ retainList = list.getList(element.getParent());
+ }
+
+ for (Type type : properlySubsumedTypes) {
+ boolean keep = false;
+ for (Type retainType : retainList) {
+ if (typeSystem.subsumes(retainType, type)) {
+ keep = true;
+ break;
+ }
+ }
+ if (!keep) {
+ stream.removeAnnotation(firstBasicInWindow, type);
+ }
+ }
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/UnmarkAllAction.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/UnmarkAllAction.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/action/VariableAction.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/action/VariableAction.java?rev=1152824&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/VariableAction.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/VariableAction.java Mon Aug 1 15:24:44 2011
@@ -0,0 +1,27 @@
+package org.apache.uima.tm.textmarker.action;
+
+import org.apache.uima.tm.textmarker.kernel.TextMarkerStream;
+import org.apache.uima.tm.textmarker.kernel.rule.RuleMatch;
+import org.apache.uima.tm.textmarker.kernel.rule.TextMarkerRuleElement;
+import org.apache.uima.tm.textmarker.kernel.visitor.InferenceCrowd;
+
+public class VariableAction extends AbstractTextMarkerAction {
+
+ private final String var;
+
+ public VariableAction(String var) {
+ super();
+ this.var = var;
+ }
+
+ @Override
+ public void execute(RuleMatch match, TextMarkerRuleElement element, TextMarkerStream stream,
+ InferenceCrowd crowd) {
+
+ }
+
+ public String getVar() {
+ return var;
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/VariableAction.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/action/VariableAction.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/batch/TextMarkerEngineTest.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/batch/TextMarkerEngineTest.java?rev=1152824&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/batch/TextMarkerEngineTest.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/batch/TextMarkerEngineTest.java Mon Aug 1 15:24:44 2011
@@ -0,0 +1,38 @@
+package org.apache.uima.tm.textmarker.batch;
+
+import org.apache.uima.UIMAFramework;
+import org.apache.uima.analysis_engine.AnalysisEngine;
+import org.apache.uima.cas.CAS;
+import org.apache.uima.resource.ResourceSpecifier;
+import org.apache.uima.util.XMLInputSource;
+
+public class TextMarkerEngineTest {
+
+ private XMLInputSource in;
+
+ private ResourceSpecifier specifier;
+
+ private AnalysisEngine ae;
+
+ private String text = "Der Hund jagt die Katze. Die Katze ist <b>fett</b>.";
+
+ public static void main(String[] args) {
+ try {
+ new TextMarkerEngineTest().test();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ private void test() throws Exception {
+ in = new XMLInputSource(getClass().getResource("/TextMarkerEngineDescriptor.xml"));
+ specifier = UIMAFramework.getXMLParser().parseResourceSpecifier(in);
+ ae = UIMAFramework.produceAnalysisEngine(specifier);
+ CAS cas = ae.newCAS();
+ cas.setDocumentText(text);
+ ae.setConfigParameterValue("ScriptLocation",
+ "C:/work/runtime-EclipseApplication/test/scripts/test.tm");
+ ae.process(cas);
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/batch/TextMarkerEngineTest.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/batch/TextMarkerEngineTest.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/batch/TextMarkerVersionConverter.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/batch/TextMarkerVersionConverter.java?rev=1152824&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/batch/TextMarkerVersionConverter.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/batch/TextMarkerVersionConverter.java Mon Aug 1 15:24:44 2011
@@ -0,0 +1,75 @@
+package org.apache.uima.tm.textmarker.batch;
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.FilenameFilter;
+import java.io.IOException;
+
+public class TextMarkerVersionConverter {
+
+ public static void main(String[] args) {
+ File dir = new File(args[0]);
+ TextMarkerVersionConverter converter = new TextMarkerVersionConverter();
+ for (File file : dir.listFiles(new FilenameFilter() {
+
+ public boolean accept(File dir, String name) {
+ return !name.endsWith("tm");
+ }
+
+ })) {
+ File output = new File(file.getParentFile(), file.getName() + ".tm");
+ try {
+ converter.convertOldToNew(file, output);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ public void convertOldToNew(File inputFile, File outputFile) throws IOException {
+ BufferedReader in = new BufferedReader(new FileReader(inputFile));
+ BufferedWriter out = new BufferedWriter(new FileWriter(outputFile));
+
+ String line = null;
+ while ((line = in.readLine()) != null) {
+ line = line.replaceAll("DUMMY", "Document");
+ line = line.replaceAll("CAPLETTERS", "CAP");
+ if (line.startsWith("/**")) {
+ continue;
+ }
+ if (!line.startsWith("//") && !line.startsWith("/*") && !"".equals(line.trim())) {
+ // if(line.startsWith("BASEDIR")) {
+ // continue;
+ // }
+ if (line.startsWith("DECLARE")) {
+ line = line.replaceAll(" ", ", ");
+ line = line.replaceFirst(", ", " ");
+ if (line.endsWith(", ")) {
+ line = line.substring(0, line.length() - 2);
+ }
+ } else {
+
+ }
+ if (line.indexOf("//") == -1) {
+ line = line + ";";
+ } else {
+ line = line.replaceAll("//", ";//");
+ }
+ line = line.replaceAll("\'", "\"");
+ if (line.contains("BASEDIR") || line.contains("FILLOBJECT")) {
+ line = "//" + line;
+ }
+ }
+ if (!line.endsWith("\n")) {
+ line = line + "\n";
+ }
+ out.write(line);
+ }
+ out.close();
+ in.close();
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/batch/TextMarkerVersionConverter.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/batch/TextMarkerVersionConverter.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/batch/TextMarkerXMLConverter.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/batch/TextMarkerXMLConverter.java?rev=1152824&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/batch/TextMarkerXMLConverter.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/batch/TextMarkerXMLConverter.java Mon Aug 1 15:24:44 2011
@@ -0,0 +1,47 @@
+package org.apache.uima.tm.textmarker.batch;
+
+import java.io.File;
+
+import org.apache.uima.tm.textmarker.resource.TreeWordList;
+
+
+public class TextMarkerXMLConverter {
+
+ public static void main(String[] args) {
+ if (args.length == 0) {
+ System.out.println("Please add paths");
+ } else {
+ File dir = new File(args[0]);
+ // TextMarkerVersionConverter converter = new
+ // TextMarkerVersionConverter();
+ // for (File file : dir.listFiles(new FilenameFilter() {
+ //
+ // @Override
+ // public boolean accept(File dir, String name) {
+ // return !name.endsWith("tm");
+ // }
+ //
+ // })) {
+ // File output = new File(file.getParentFile(), file.getName() +
+ // ".tm");
+ // try {
+ // converter.convertOldToNew(file, output);
+ // } catch (IOException e) {
+ // e.printStackTrace();
+ // }
+ // }
+
+ for (File file : dir.listFiles()) {
+
+ String path = file.getAbsolutePath();
+
+ if (path.endsWith("txt")) {
+ TreeWordList list = new TreeWordList(file.getAbsolutePath());
+ String newFilePath = path.substring(0, path.length() - 3) + "twl";
+ System.out.println(newFilePath);
+ list.createXMLFile(newFilePath, "UTF-8");
+ }
+ }
+ }
+ }
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/batch/TextMarkerXMLConverter.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/batch/TextMarkerXMLConverter.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/condition/AbstractTextMarkerCondition.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/condition/AbstractTextMarkerCondition.java?rev=1152824&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/condition/AbstractTextMarkerCondition.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/condition/AbstractTextMarkerCondition.java Mon Aug 1 15:24:44 2011
@@ -0,0 +1,21 @@
+package org.apache.uima.tm.textmarker.condition;
+
+import org.apache.uima.cas.Type;
+import org.apache.uima.tm.textmarker.kernel.TextMarkerElement;
+import org.apache.uima.tm.textmarker.kernel.TextMarkerStream;
+import org.apache.uima.tm.textmarker.kernel.rule.EvaluatedCondition;
+import org.apache.uima.tm.textmarker.kernel.rule.TextMarkerRuleElement;
+import org.apache.uima.tm.textmarker.kernel.type.TextMarkerBasic;
+import org.apache.uima.tm.textmarker.kernel.visitor.InferenceCrowd;
+
+
+public abstract class AbstractTextMarkerCondition extends TextMarkerElement {
+
+ public abstract EvaluatedCondition eval(TextMarkerBasic basic, Type matchedType,
+ TextMarkerRuleElement element, TextMarkerStream stream, InferenceCrowd crowd);
+
+ @Override
+ public String toString() {
+ return getClass().getSimpleName();
+ }
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/condition/AbstractTextMarkerCondition.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/condition/AbstractTextMarkerCondition.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/condition/AfterCondition.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/condition/AfterCondition.java?rev=1152824&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/condition/AfterCondition.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/condition/AfterCondition.java Mon Aug 1 15:24:44 2011
@@ -0,0 +1,64 @@
+package org.apache.uima.tm.textmarker.condition;
+
+import java.util.List;
+
+import org.apache.uima.cas.FSIterator;
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.tm.textmarker.kernel.TextMarkerStream;
+import org.apache.uima.tm.textmarker.kernel.expression.list.TypeListExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.type.TypeExpression;
+import org.apache.uima.tm.textmarker.kernel.rule.EvaluatedCondition;
+import org.apache.uima.tm.textmarker.kernel.rule.TextMarkerRuleElement;
+import org.apache.uima.tm.textmarker.kernel.type.TextMarkerBasic;
+import org.apache.uima.tm.textmarker.kernel.visitor.InferenceCrowd;
+
+
+public class AfterCondition extends TypeSentiveCondition {
+
+ public AfterCondition(TypeExpression type) {
+ super(type);
+ }
+
+ public AfterCondition(TypeListExpression list) {
+ super(list);
+ }
+
+ @Override
+ public EvaluatedCondition eval(TextMarkerBasic basic, Type matchedType,
+ TextMarkerRuleElement element, TextMarkerStream stream, InferenceCrowd crowd) {
+ if (!isWorkingOnList()) {
+ Type t = type.getType(element.getParent());
+ boolean result = check(basic, stream, t);
+ return new EvaluatedCondition(this, result);
+ } else {
+ boolean result = false;
+ List<Type> types = getList().getList(element.getParent());
+ for (Type t : types) {
+ result |= check(basic, stream, t);
+ if (result == true) {
+ break;
+ }
+ }
+ return new EvaluatedCondition(this, result);
+ }
+ }
+
+ private boolean check(TextMarkerBasic basic, TextMarkerStream stream, Type t) {
+ boolean result = false;
+ FSIterator<AnnotationFS> it = stream.getCas().getAnnotationIndex(t).iterator(basic);
+ if (!it.isValid()) {
+ it.moveToLast();
+ }
+ while (it.isValid()) {
+ AnnotationFS a = (AnnotationFS) it.get();
+ if (a.getBegin() <= basic.getBegin()) {
+ result = true;
+ break;
+ }
+ it.moveToPrevious();
+ }
+ return result;
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/condition/AfterCondition.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/condition/AfterCondition.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/condition/AndCondition.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/condition/AndCondition.java?rev=1152824&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/condition/AndCondition.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/condition/AndCondition.java Mon Aug 1 15:24:44 2011
@@ -0,0 +1,35 @@
+package org.apache.uima.tm.textmarker.condition;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.uima.cas.Type;
+import org.apache.uima.tm.textmarker.kernel.TextMarkerStream;
+import org.apache.uima.tm.textmarker.kernel.rule.EvaluatedCondition;
+import org.apache.uima.tm.textmarker.kernel.rule.TextMarkerRuleElement;
+import org.apache.uima.tm.textmarker.kernel.type.TextMarkerBasic;
+import org.apache.uima.tm.textmarker.kernel.visitor.InferenceCrowd;
+
+
+public class AndCondition extends ComposedTextMarkerCondition {
+
+ public AndCondition(List<AbstractTextMarkerCondition> conditions) {
+ super(conditions);
+ }
+
+ @Override
+ public EvaluatedCondition eval(TextMarkerBasic currentSymbol, Type matchedType,
+ TextMarkerRuleElement element, TextMarkerStream symbolStream, InferenceCrowd crowd) {
+ boolean result = true;
+ List<EvaluatedCondition> evals = new ArrayList<EvaluatedCondition>();
+ for (AbstractTextMarkerCondition each : conditions) {
+ crowd.beginVisit(each, null);
+ EvaluatedCondition eval = each.eval(currentSymbol, matchedType, element, symbolStream, crowd);
+ crowd.endVisit(each, null);
+ result &= eval.isValue();
+ evals.add(eval);
+ }
+ return new EvaluatedCondition(this, result, evals);
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/condition/AndCondition.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/condition/AndCondition.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/condition/BeforeCondition.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/condition/BeforeCondition.java?rev=1152824&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/condition/BeforeCondition.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/condition/BeforeCondition.java Mon Aug 1 15:24:44 2011
@@ -0,0 +1,61 @@
+package org.apache.uima.tm.textmarker.condition;
+
+import java.util.List;
+
+import org.apache.uima.cas.FSIterator;
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.tm.textmarker.kernel.TextMarkerStream;
+import org.apache.uima.tm.textmarker.kernel.expression.list.TypeListExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.type.TypeExpression;
+import org.apache.uima.tm.textmarker.kernel.rule.EvaluatedCondition;
+import org.apache.uima.tm.textmarker.kernel.rule.TextMarkerRuleElement;
+import org.apache.uima.tm.textmarker.kernel.type.TextMarkerBasic;
+import org.apache.uima.tm.textmarker.kernel.visitor.InferenceCrowd;
+
+
+public class BeforeCondition extends TypeSentiveCondition {
+
+ public BeforeCondition(TypeExpression type) {
+ super(type);
+ }
+
+ public BeforeCondition(TypeListExpression list) {
+ super(list);
+ }
+
+ @Override
+ public EvaluatedCondition eval(TextMarkerBasic basic, Type matchedType,
+ TextMarkerRuleElement element, TextMarkerStream stream, InferenceCrowd crowd) {
+ if (!isWorkingOnList()) {
+ Type t = type.getType(element.getParent());
+ boolean result = check(basic, stream, t);
+ return new EvaluatedCondition(this, result);
+ } else {
+ boolean result = false;
+ List<Type> types = getList().getList(element.getParent());
+ for (Type t : types) {
+ result |= check(basic, stream, t);
+ if (result == true) {
+ break;
+ }
+ }
+ return new EvaluatedCondition(this, result);
+ }
+ }
+
+ private boolean check(TextMarkerBasic basic, TextMarkerStream stream, Type t) {
+ boolean result = false;
+ FSIterator<AnnotationFS> it = stream.getCas().getAnnotationIndex(t).iterator(basic);
+ while (it.isValid()) {
+ AnnotationFS a = (AnnotationFS) it.get();
+ if (a.getEnd() >= basic.getBegin()) {
+ result = true;
+ break;
+ }
+ it.moveToNext();
+ }
+ return result;
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/condition/BeforeCondition.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/condition/BeforeCondition.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/condition/ComposedTextMarkerCondition.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/condition/ComposedTextMarkerCondition.java?rev=1152824&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/condition/ComposedTextMarkerCondition.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/condition/ComposedTextMarkerCondition.java Mon Aug 1 15:24:44 2011
@@ -0,0 +1,24 @@
+package org.apache.uima.tm.textmarker.condition;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public abstract class ComposedTextMarkerCondition extends AbstractTextMarkerCondition {
+
+ protected List<AbstractTextMarkerCondition> conditions;
+
+ public ComposedTextMarkerCondition(List<AbstractTextMarkerCondition> conditions) {
+ super();
+ this.conditions = conditions;
+ }
+
+ public ComposedTextMarkerCondition(AbstractTextMarkerCondition condition) {
+ super();
+ this.conditions = new ArrayList<AbstractTextMarkerCondition>();
+ this.conditions.add(condition);
+ }
+
+ public List<AbstractTextMarkerCondition> getConditions() {
+ return conditions;
+ }
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/condition/ComposedTextMarkerCondition.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/condition/ComposedTextMarkerCondition.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/condition/ConditionFactory.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/condition/ConditionFactory.java?rev=1152824&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/condition/ConditionFactory.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/condition/ConditionFactory.java Mon Aug 1 15:24:44 2011
@@ -0,0 +1,242 @@
+package org.apache.uima.tm.textmarker.condition;
+
+import java.util.List;
+
+import org.antlr.runtime.Token;
+import org.apache.uima.tm.textmarker.kernel.TextMarkerBlock;
+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.list.ListExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.list.StringListExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.list.TypeListExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.number.NumberExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.resource.WordListExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.string.StringExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.type.TypeExpression;
+
+
+public class ConditionFactory {
+
+ private ConditionFactory() {
+ }
+
+ public static AbstractTextMarkerCondition createConditionAnd(
+ List<AbstractTextMarkerCondition> conds, TextMarkerBlock parent) {
+ return new AndCondition(conds);
+ }
+
+ public static AbstractTextMarkerCondition createConditionOr(
+ List<AbstractTextMarkerCondition> conds, TextMarkerBlock parent) {
+ return new OrCondition(conds);
+ }
+
+ public static AbstractTextMarkerCondition createConditionNot(AbstractTextMarkerCondition cond,
+ TextMarkerBlock parent) {
+ return new NotCondition(cond);
+ }
+
+ public static AbstractTextMarkerCondition createConditionContains(TypeExpression typeExpr,
+ NumberExpression min, NumberExpression max, BooleanExpression percent,
+ TextMarkerBlock parent) {
+ return new ContainsCondition(typeExpr, min, max, percent);
+ }
+
+ public static AbstractTextMarkerCondition createConditionContextCount(TypeExpression typeExpr,
+ NumberExpression min, NumberExpression max, Token var, TextMarkerBlock parent) {
+ String varString = null;
+ if (var != null) {
+ varString = var.getText();
+ }
+ return new ContextCountCondition(typeExpr, min, max, varString);
+ }
+
+ public static AbstractTextMarkerCondition createConditionCurrentCount(TypeExpression typeExpr,
+ NumberExpression min, NumberExpression max, Token var, TextMarkerBlock parent) {
+ String varString = null;
+ if (var != null) {
+ varString = var.getText();
+ }
+ return new CurrentCountCondition(typeExpr, min, max, varString);
+ }
+
+ public static AbstractTextMarkerCondition createConditionCount(TypeExpression typeExpr,
+ NumberExpression min, NumberExpression max, Token var, TextMarkerBlock parent) {
+ String varString = null;
+ if (var != null) {
+ varString = var.getText();
+ }
+ return new CountCondition(typeExpr, min, max, varString);
+ }
+
+ public static AbstractTextMarkerCondition createConditionTotalCount(TypeExpression typeExpr,
+ NumberExpression min, NumberExpression max, Token var, TextMarkerBlock parent) {
+ String varString = null;
+ if (var != null) {
+ varString = var.getText();
+ }
+ return new TotalCountCondition(typeExpr, min, max, varString);
+ }
+
+ public static AbstractTextMarkerCondition createConditionInList(WordListExpression listExpr,
+ NumberExpression dist, BooleanExpression rel, TextMarkerBlock parent) {
+ return new InListCondition(listExpr, dist, rel);
+ }
+
+ public static AbstractTextMarkerCondition createConditionIsInTag(StringExpression id,
+ List<StringExpression> list1, List<StringExpression> list2, TextMarkerBlock parent) {
+ return new IsInTagCondition(id, list1, list2);
+ }
+
+ public static AbstractTextMarkerCondition createConditionMOfN(
+ List<AbstractTextMarkerCondition> conds, NumberExpression min, NumberExpression max,
+ TextMarkerBlock parent) {
+ return new MOfNCondition(conds, min, max);
+ }
+
+ public static AbstractTextMarkerCondition createConditionNear(TypeExpression typeExpr,
+ NumberExpression min, NumberExpression max, BooleanExpression direction,
+ BooleanExpression filtered, TextMarkerBlock parent) {
+ return new NearCondition(typeExpr, min, max, direction, filtered);
+ }
+
+ public static AbstractTextMarkerCondition createConditionPartOf(TypeExpression type,
+ TypeListExpression list, TextMarkerBlock parent) {
+ if (type != null) {
+ return new PartOfCondition(type);
+ } else {
+ return new PartOfCondition(list);
+ }
+ }
+
+ public static AbstractTextMarkerCondition createConditionPosition(TypeExpression typeExpr,
+ NumberExpression pos, TextMarkerBlock parent) {
+ return new PositionCondition(typeExpr, pos);
+ }
+
+ public static AbstractTextMarkerCondition createConditionRegExp(StringExpression patternExpr,
+ BooleanExpression ignoreCase, TextMarkerBlock parent) {
+ return new RegExpCondition(patternExpr, ignoreCase);
+ }
+
+ public static AbstractTextMarkerCondition createConditionScore(NumberExpression min,
+ NumberExpression max, Token var, TextMarkerBlock parent) {
+ String varString = null;
+ if (var != null) {
+ varString = var.getText();
+ }
+ return new ScoreCondition(min, max, varString);
+ }
+
+ public static AbstractTextMarkerCondition createConditionVote(TypeExpression type1Expr,
+ TypeExpression type2Expr, TextMarkerBlock parent) {
+ return new VoteCondition(type1Expr, type2Expr);
+ }
+
+ public static AbstractTextMarkerCondition createConditionLast(TypeExpression typeExpr,
+ TextMarkerBlock parent) {
+ return new LastCondition(typeExpr);
+ }
+
+ public static AbstractTextMarkerCondition createConditionIf(BooleanExpression e,
+ TextMarkerBlock parent) {
+ return new IfCondition(e);
+ }
+
+ public static AbstractTextMarkerCondition createConditionFeature(StringExpression se, Object v,
+ TextMarkerBlock parent) {
+ if (v instanceof NumberExpression) {
+ return new FeatureCondition(se, (NumberExpression) v);
+ } else if (v instanceof StringExpression) {
+ return new FeatureCondition(se, (StringExpression) v);
+ } else if (v instanceof BooleanExpression) {
+ return new FeatureCondition(se, (BooleanExpression) v);
+ }
+ return null;
+ }
+
+ public static AbstractTextMarkerCondition createConditionParse(Token id, TextMarkerBlock env) {
+ String var = id == null ? "" : id.getText();
+ return new ParseCondition(var);
+ }
+
+ public static AbstractTextMarkerCondition createConditionVariable(Token id) {
+ return new VariableCondition(id.getText());
+ }
+
+ public static AbstractTextMarkerCondition createConditionIs(TypeExpression type,
+ TypeListExpression list, TextMarkerBlock env) {
+ if (type != null) {
+ return new IsCondition(type);
+ } else {
+ return new IsCondition(list);
+ }
+ }
+
+ public static AbstractTextMarkerCondition createConditionAfter(TypeExpression type,
+ TypeListExpression list, TextMarkerBlock env) {
+ if (type != null) {
+ return new AfterCondition(type);
+ } else {
+ return new AfterCondition(list);
+ }
+ }
+
+ public static AbstractTextMarkerCondition createConditionBefore(TypeExpression type,
+ TypeListExpression list, TextMarkerBlock env) {
+ if (type != null) {
+ return new BeforeCondition(type);
+ } else {
+ return new BeforeCondition(list);
+ }
+ }
+
+ public static AbstractTextMarkerCondition createConditionEndsWith(TypeExpression type,
+ TypeListExpression list, TextMarkerBlock env) {
+ if (type != null) {
+ return new EndsWithCondition(type);
+ } else {
+ return new EndsWithCondition(list);
+ }
+ }
+
+ public static AbstractTextMarkerCondition createConditionStartsWith(TypeExpression type,
+ TypeListExpression list, TextMarkerBlock env) {
+ if (type != null) {
+ return new StartsWithCondition(type);
+ } else {
+ return new StartsWithCondition(list);
+ }
+ }
+
+ public static AbstractTextMarkerCondition createConditionPartOfNeq(TypeExpression type,
+ TypeListExpression list, TextMarkerBlock env) {
+ if (type != null) {
+ return new PartOfNeqCondition(type);
+ } else {
+ return new PartOfNeqCondition(list);
+ }
+ }
+
+ public static AbstractTextMarkerCondition createConditionSize(ListExpression<?> list,
+ NumberExpression min, NumberExpression max, Token var, TextMarkerBlock env) {
+ return new SizeCondition(list, min, max, var == null ? null : var.getText());
+ }
+
+ public static AbstractTextMarkerCondition createConditionInList(StringListExpression list,
+ NumberExpression dist, BooleanExpression rel, TextMarkerBlock env) {
+ return new InListCondition(list, dist, rel);
+ }
+
+ public static AbstractTextMarkerCondition createConditionCount(ListExpression<Object> type,
+ TextMarkerExpression a, NumberExpression min, NumberExpression max, Token var,
+ TextMarkerBlock env) {
+ return new CountCondition(type, a, min, max, var == null ? null : var.getText());
+ }
+
+ public static AbstractTextMarkerCondition createConditionContains(ListExpression list,
+ TextMarkerExpression a, NumberExpression min, NumberExpression max,
+ BooleanExpression percent, TextMarkerBlock env) {
+ return new ContainsCondition(list, a, min, max, percent);
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/condition/ConditionFactory.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/condition/ConditionFactory.java
------------------------------------------------------------------------------
svn:mime-type = text/plain