You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by pk...@apache.org on 2012/02/13 18:45:05 UTC
svn commit: r1243619 [24/25] - in /uima/sandbox/trunk/TextMarker:
uimaj-ep-textmarker-addons/
uimaj-ep-textmarker-addons/src/main/java/org/apache/uima/textmarker/addons/
uimaj-ep-textmarker-addons/src/main/java/org/apache/uima/textmarker/explain/apply/...
Added: uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/visitor/DebugInfoFactory.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/visitor/DebugInfoFactory.java?rev=1243619&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/visitor/DebugInfoFactory.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/visitor/DebugInfoFactory.java Mon Feb 13 17:44:52 2012
@@ -0,0 +1,376 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.textmarker.visitor;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.jcas.JCas;
+import org.apache.uima.jcas.cas.FSArray;
+import org.apache.uima.textmarker.BlockApply;
+import org.apache.uima.textmarker.ScriptApply;
+import org.apache.uima.textmarker.TextMarkerBlock;
+import org.apache.uima.textmarker.TextMarkerElement;
+import org.apache.uima.textmarker.TextMarkerStream;
+import org.apache.uima.textmarker.rule.ComposedRuleElement;
+import org.apache.uima.textmarker.rule.ComposedRuleElementMatch;
+import org.apache.uima.textmarker.rule.EvaluatedCondition;
+import org.apache.uima.textmarker.rule.RuleApply;
+import org.apache.uima.textmarker.rule.RuleElement;
+import org.apache.uima.textmarker.rule.RuleElementMatch;
+import org.apache.uima.textmarker.rule.RuleMatch;
+import org.apache.uima.textmarker.rule.TextMarkerRuleElement;
+import org.apache.uima.textmarker.type.DebugBlockApply;
+import org.apache.uima.textmarker.type.DebugEvaluatedCondition;
+import org.apache.uima.textmarker.type.DebugFailedRuleMatch;
+import org.apache.uima.textmarker.type.DebugMatchedRuleMatch;
+import org.apache.uima.textmarker.type.DebugRuleApply;
+import org.apache.uima.textmarker.type.DebugRuleElementMatch;
+import org.apache.uima.textmarker.type.DebugRuleElementMatches;
+import org.apache.uima.textmarker.type.DebugRuleMatch;
+import org.apache.uima.textmarker.type.DebugScriptApply;
+import org.apache.uima.textmarker.utils.UIMAUtils;
+import org.apache.uima.textmarker.verbalize.TextMarkerVerbalizer;
+
+public class DebugInfoFactory {
+
+ private TextMarkerVerbalizer verbalizer;
+
+ public DebugInfoFactory(TextMarkerVerbalizer verbalizer) {
+ super();
+ this.verbalizer = verbalizer;
+ }
+
+ public DebugBlockApply createDummyBlockApply(RuleMatch ruleMatch, TextMarkerStream stream,
+ boolean addToIndex, boolean withMatches, Map<TextMarkerElement, Long> timeInfo) {
+ JCas cas = stream.getJCas();
+ DebugBlockApply dba = new DebugBlockApply(cas);
+ AnnotationFS matchedAnnotation = ruleMatch.getMatchedAnnotationsOf(
+ ruleMatch.getRule().getRoot(), stream).get(0);
+ dba.setElement(matchedAnnotation.getCoveredText());
+ dba.setBegin(matchedAnnotation.getBegin());
+ dba.setEnd(matchedAnnotation.getEnd());
+ return dba;
+ }
+
+ public DebugBlockApply createDebugBlockApply(BlockApply blockApply, TextMarkerStream stream,
+ boolean addToIndex, boolean withMatches, Map<TextMarkerElement, Long> timeInfo) {
+ JCas cas = stream.getJCas();
+ DebugBlockApply dba = new DebugBlockApply(cas);
+ List<DebugScriptApply> innerApply = new ArrayList<DebugScriptApply>();
+ // TODO refactor and remove counting hotfix
+ int applied = blockApply.getRuleApply().getApplied();
+ if (applied > 1) {
+ List<ScriptApply> innerApplies = blockApply.getInnerApplies();
+ List<List<ScriptApply>> loops = new ArrayList<List<ScriptApply>>();
+ for (int i = 0; i < applied; i++) {
+ loops.add(new ArrayList<ScriptApply>());
+ }
+ int counter = 0;
+ int size = innerApplies.size();
+ int parts = size / applied;
+ for (ScriptApply each : innerApplies) {
+ int listIndex = Math.max(0, counter / parts);
+ List<ScriptApply> list = loops.get(listIndex);
+ list.add(each);
+ counter++;
+ }
+ counter = 0;
+ for (List<ScriptApply> list : loops) {
+ RuleMatch ruleMatch = blockApply.getRuleApply().getList().get(counter);
+ DebugBlockApply dummyBlockApply = createDummyBlockApply(ruleMatch, stream, addToIndex,
+ withMatches, timeInfo);
+ List<DebugRuleMatch> ruleMatches = new ArrayList<DebugRuleMatch>();
+ ruleMatches.add(createDebugRuleMatch(ruleMatch, stream, addToIndex, withMatches, timeInfo));
+ dummyBlockApply.setApplied(1);
+ dummyBlockApply.setTried(1);
+ dummyBlockApply.setRules(UIMAUtils.toFSArray(cas, ruleMatches));
+ List<DebugScriptApply> innerInnerApply = new ArrayList<DebugScriptApply>();
+ for (ScriptApply each : list) {
+ DebugScriptApply eachInnerInner = createDebugScriptApply(each, stream, addToIndex,
+ withMatches, timeInfo);
+ innerInnerApply.add(eachInnerInner);
+ }
+ dummyBlockApply.setInnerApply(UIMAUtils.toFSArray(cas, innerInnerApply));
+ innerApply.add(dummyBlockApply);
+ counter++;
+ }
+ dba.setInnerApply(UIMAUtils.toFSArray(cas, innerApply));
+ dba.setElement(verbalizer.verbalize((TextMarkerBlock) blockApply.getElement(), false));
+ DebugRuleApply ruleApply = createDebugRuleApply(blockApply.getRuleApply(), stream,
+ addToIndex, withMatches, timeInfo);
+ dba.setApplied(ruleApply.getApplied());
+ dba.setTried(ruleApply.getTried());
+ dba.setRules(ruleApply.getRules());
+ dba.setBegin(ruleApply.getBegin());
+ dba.setEnd(ruleApply.getEnd());
+ if (timeInfo != null) {
+ long time = timeInfo.get(blockApply.getElement());
+ dba.setTime(time);
+ }
+ if (addToIndex)
+ dba.addToIndexes();
+ return dba;
+ } else {
+
+ for (ScriptApply each : blockApply.getInnerApplies()) {
+ innerApply.add(createDebugScriptApply(each, stream, addToIndex, withMatches, timeInfo));
+ }
+ dba.setInnerApply(UIMAUtils.toFSArray(cas, innerApply));
+ dba.setElement(verbalizer.verbalize((TextMarkerBlock) blockApply.getElement(), false));
+ DebugRuleApply ruleApply = createDebugRuleApply(blockApply.getRuleApply(), stream,
+ addToIndex, withMatches, timeInfo);
+ dba.setApplied(ruleApply.getApplied());
+ dba.setTried(ruleApply.getTried());
+ dba.setRules(ruleApply.getRules());
+ dba.setBegin(ruleApply.getBegin());
+ dba.setEnd(ruleApply.getEnd());
+ if (timeInfo != null) {
+ long time = timeInfo.get(blockApply.getElement());
+ dba.setTime(time);
+ }
+ if (addToIndex)
+ dba.addToIndexes();
+ return dba;
+ }
+ }
+
+ public DebugRuleApply createDebugRuleApply(RuleApply ruleApply, TextMarkerStream stream,
+ boolean addToIndex, boolean withMatches, Map<TextMarkerElement, Long> timeInfo) {
+ JCas cas = stream.getJCas();
+ DebugRuleApply dra = new DebugRuleApply(cas);
+ List<DebugRuleMatch> ruleMatches = new ArrayList<DebugRuleMatch>();
+ int begin = Integer.MAX_VALUE;
+ int end = 0;
+ if (withMatches) {
+ for (RuleMatch match : ruleApply.getList()) {
+ DebugRuleMatch debugRuleMatch = createDebugRuleMatch(match, stream, addToIndex,
+ withMatches, timeInfo);
+ begin = Math.min(begin, debugRuleMatch.getBegin());
+ end = Math.max(end, debugRuleMatch.getEnd());
+ ruleMatches.add(debugRuleMatch);
+ }
+ }
+ if (begin >= end) {
+ begin = end;
+ }
+ dra.setRules(UIMAUtils.toFSArray(cas, ruleMatches));
+ dra.setElement(verbalizer.verbalize(ruleApply.getElement()));
+ dra.setApplied(ruleApply.getApplied());
+ dra.setTried(ruleApply.getTried());
+ dra.setBegin(begin);
+ dra.setEnd(end);
+ if (timeInfo != null) {
+ long time = timeInfo.get(ruleApply.getElement());
+ dra.setTime(time);
+ }
+ if (addToIndex)
+ dra.addToIndexes();
+ return dra;
+ }
+
+ public DebugRuleMatch createDebugRuleMatch(RuleMatch match, TextMarkerStream stream,
+ boolean addToIndex, boolean withMatches, Map<TextMarkerElement, Long> timeInfo) {
+ JCas cas = stream.getJCas();
+ DebugRuleMatch drm = null;
+ if (match.matchedCompletely()) {
+ drm = new DebugMatchedRuleMatch(cas);
+ } else {
+ drm = new DebugFailedRuleMatch(cas);
+ }
+ ComposedRuleElementMatch rootMatch = match.getRootMatch();
+ setInnerMatches(stream, addToIndex, cas, drm, rootMatch);
+ drm.setMatched(match.matchedCompletely());
+ if (match.matched()) {
+ List<DebugScriptApply> delegates = new ArrayList<DebugScriptApply>();
+ for (ScriptApply rem : match.getDelegateApply().values()) {
+ delegates.add(createDebugScriptApply(rem, stream, addToIndex, withMatches, timeInfo));
+ }
+ drm.setDelegates(UIMAUtils.toFSArray(cas, delegates));
+ }
+ if (timeInfo != null) {
+ long time = timeInfo.get(match.getRule());
+ drm.setTime(time);
+ }
+ AnnotationFS matchedAnnotation = match.getMatchedAnnotationsOf(match.getRule().getRoot(),
+ stream).get(0);
+ if (matchedAnnotation != null) {
+ drm.setBegin(matchedAnnotation.getBegin());
+ drm.setEnd(matchedAnnotation.getEnd());
+ if (addToIndex || withMatches)
+ drm.addToIndexes();
+ }
+ return drm;
+ }
+
+ private void setInnerMatches(TextMarkerStream stream, boolean addToIndex, JCas cas,
+ DebugRuleMatch drm, ComposedRuleElementMatch rootMatch) {
+ Set<Entry<RuleElement, List<RuleElementMatch>>> entrySet = rootMatch.getInnerMatches()
+ .entrySet();
+ List<DebugRuleElementMatches> ruleElementMatches = new ArrayList<DebugRuleElementMatches>();
+ for (Entry<RuleElement, List<RuleElementMatch>> entry : entrySet) {
+ RuleElement re = entry.getKey();
+ List<RuleElementMatch> rems = entry.getValue();
+ ruleElementMatches.add(createDebugRuleElementMatches(re, rems, stream, addToIndex));
+ }
+
+ drm.setElements(UIMAUtils.toFSArray(cas, ruleElementMatches));
+ }
+
+ private void setInnerMatches(TextMarkerStream stream, boolean addToIndex, JCas cas,
+ DebugRuleElementMatch drm, ComposedRuleElementMatch rootMatch) {
+ Set<Entry<RuleElement, List<RuleElementMatch>>> entrySet = rootMatch.getInnerMatches()
+ .entrySet();
+ List<DebugRuleElementMatches> ruleElementMatches = new ArrayList<DebugRuleElementMatches>();
+ for (Entry<RuleElement, List<RuleElementMatch>> entry : entrySet) {
+ RuleElement re = entry.getKey();
+ List<RuleElementMatch> rems = entry.getValue();
+ ruleElementMatches.add(createDebugRuleElementMatches(re, rems, stream, addToIndex));
+ }
+ drm.setElements(UIMAUtils.toFSArray(cas, ruleElementMatches));
+ }
+
+ public DebugRuleElementMatches createDebugRuleElementMatches(RuleElement re,
+ List<RuleElementMatch> rems, TextMarkerStream stream, boolean addToIndex) {
+ JCas cas = stream.getJCas();
+ DebugRuleElementMatches drems = new DebugRuleElementMatches(cas);
+ drems.setElement(verbalizer.verbalize(re));
+ List<DebugRuleElementMatch> remList = new ArrayList<DebugRuleElementMatch>();
+ if (rems != null) {
+ for (RuleElementMatch each : rems) {
+ if (each instanceof ComposedRuleElementMatch) {
+ remList.add(createDebugComposedRuleElementMatch((ComposedRuleElementMatch) each, stream,
+ addToIndex));
+ } else {
+ remList.add(createDebugRuleElementMatch(each, stream, addToIndex));
+ }
+ }
+ }
+ if (rems != null && !rems.isEmpty()) {
+ drems.setRuleAnchor(rems.get(0).isRuleAnchor());
+ }
+ drems.setMatches(UIMAUtils.toFSArray(cas, remList));
+ if (addToIndex)
+ drems.addToIndexes();
+ return drems;
+ }
+
+ public DebugRuleElementMatch createDebugComposedRuleElementMatch(ComposedRuleElementMatch rem,
+ TextMarkerStream stream, boolean addToIndex) {
+ JCas cas = stream.getJCas();
+ DebugRuleElementMatch drem = new DebugRuleElementMatch(cas);
+
+ DebugEvaluatedCondition base = new DebugEvaluatedCondition(cas);
+ base.setValue(rem.isBaseConditionMatched());
+
+ setInnerMatches(stream, addToIndex, cas, drem, rem);
+
+ String baseString = verbalizer.verbalize(rem.getRuleElement());
+ base.setElement(baseString);
+ drem.setBaseCondition(base);
+ drem.setConditions(createEvaluatedConditions(rem, stream, addToIndex));
+ List<AnnotationFS> annotations = rem.getTextsMatched();
+ if (!annotations.isEmpty()) {
+ drem.setBegin(annotations.get(0).getBegin());
+ drem.setEnd(annotations.get(annotations.size() - 1).getEnd());
+ }
+ if (addToIndex)
+ drem.addToIndexes();
+ return drem;
+ }
+
+ public DebugRuleElementMatch createDebugRuleElementMatch(RuleElementMatch rem,
+ TextMarkerStream stream, boolean addToIndex) {
+ JCas cas = stream.getJCas();
+ DebugRuleElementMatch drem = new DebugRuleElementMatch(cas);
+
+ DebugEvaluatedCondition base = new DebugEvaluatedCondition(cas);
+ base.setValue(rem.isBaseConditionMatched());
+ RuleElement ruleElement = rem.getRuleElement();
+ String baseString = "";
+ if (ruleElement instanceof TextMarkerRuleElement) {
+ baseString = verbalizer.verbalizeMatcher((TextMarkerRuleElement) ruleElement);
+ } else if (ruleElement instanceof ComposedRuleElement) {
+ baseString = verbalizer.verbalizeComposed((ComposedRuleElement) ruleElement);
+ }
+ base.setElement(baseString);
+ drem.setBaseCondition(base);
+
+ drem.setConditions(createEvaluatedConditions(rem, stream, addToIndex));
+ List<AnnotationFS> annotations = rem.getTextsMatched();
+ if (!annotations.isEmpty()) {
+ drem.setBegin(annotations.get(0).getBegin());
+ drem.setEnd(annotations.get(annotations.size() - 1).getEnd());
+ }
+ if (addToIndex)
+ drem.addToIndexes();
+ return drem;
+ }
+
+ private FSArray createEvaluatedConditions(RuleElementMatch rem, TextMarkerStream stream,
+ boolean addToIndex) {
+ JCas cas = stream.getJCas();
+ List<DebugEvaluatedCondition> ecs = new ArrayList<DebugEvaluatedCondition>();
+ if (rem.getConditions() != null) {
+ for (EvaluatedCondition each : rem.getConditions()) {
+ DebugEvaluatedCondition ec = new DebugEvaluatedCondition(cas);
+ ec.setValue(each.isValue());
+ ec.setElement(verbalizer.verbalize(each.getCondition()));
+ ec.setConditions(createEvaluatedConditions(each, stream, addToIndex));
+ ecs.add(ec);
+ }
+ }
+ FSArray result = UIMAUtils.toFSArray(cas, ecs);
+ return result;
+ }
+
+ private FSArray createEvaluatedConditions(EvaluatedCondition eval, TextMarkerStream stream,
+ boolean addToIndex) {
+ JCas cas = stream.getJCas();
+ List<DebugEvaluatedCondition> ecs = new ArrayList<DebugEvaluatedCondition>();
+ for (EvaluatedCondition each : eval.getConditions()) {
+ DebugEvaluatedCondition ec = new DebugEvaluatedCondition(cas);
+ ec.setValue(each.isValue());
+ ec.setElement(verbalizer.verbalize(each.getCondition()));
+ ec.setConditions(createEvaluatedConditions(each, stream, addToIndex));
+ ecs.add(ec);
+ }
+ FSArray result = UIMAUtils.toFSArray(cas, ecs);
+ return result;
+ }
+
+ public DebugScriptApply createDebugScriptApply(ScriptApply apply, TextMarkerStream stream,
+ boolean addToIndex, boolean withMatches, Map<TextMarkerElement, Long> timeInfo) {
+ DebugScriptApply debug = null;
+ if (apply instanceof BlockApply) {
+ debug = createDebugBlockApply((BlockApply) apply, stream, addToIndex, withMatches, timeInfo);
+ } else if (apply instanceof RuleApply) {
+ debug = createDebugRuleApply((RuleApply) apply, stream, addToIndex, withMatches, timeInfo);
+ }
+ if (addToIndex)
+ debug.addToIndexes();
+ return debug;
+ }
+
+}
Added: uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/visitor/InferenceCrowd.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/visitor/InferenceCrowd.java?rev=1243619&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/visitor/InferenceCrowd.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/visitor/InferenceCrowd.java Mon Feb 13 17:44:52 2012
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+*/
+
+package org.apache.uima.textmarker.visitor;
+
+import java.util.List;
+
+import org.apache.uima.textmarker.ScriptApply;
+import org.apache.uima.textmarker.TextMarkerElement;
+import org.apache.uima.textmarker.TextMarkerStream;
+
+
+public class InferenceCrowd implements TextMarkerInferenceVisitor {
+
+ private final List<TextMarkerInferenceVisitor> visitors;
+
+ public InferenceCrowd(List<TextMarkerInferenceVisitor> visitors) {
+ super();
+ this.visitors = visitors;
+ }
+
+ public void beginVisit(TextMarkerElement element, ScriptApply result) {
+ for (TextMarkerInferenceVisitor each : visitors) {
+ each.beginVisit(element, result);
+ }
+ }
+
+ public void endVisit(TextMarkerElement element, ScriptApply result) {
+ for (TextMarkerInferenceVisitor each : visitors) {
+ each.endVisit(element, result);
+ }
+ }
+
+ public void finished(TextMarkerStream stream) {
+ for (TextMarkerInferenceVisitor each : visitors) {
+ each.finished(stream, visitors);
+ }
+ }
+
+ public void finished(TextMarkerStream stream, List<TextMarkerInferenceVisitor> visitors) {
+ finished(stream);
+ }
+
+}
Added: uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/visitor/StatisticsVisitor.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/visitor/StatisticsVisitor.java?rev=1243619&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/visitor/StatisticsVisitor.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/visitor/StatisticsVisitor.java Mon Feb 13 17:44:52 2012
@@ -0,0 +1,199 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.textmarker.visitor;
+
+import java.util.ArrayList;
+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.jcas.JCas;
+import org.apache.uima.jcas.cas.DoubleArray;
+import org.apache.uima.jcas.cas.IntegerArray;
+import org.apache.uima.jcas.cas.StringArray;
+import org.apache.uima.textmarker.ScriptApply;
+import org.apache.uima.textmarker.TextMarkerElement;
+import org.apache.uima.textmarker.TextMarkerStream;
+import org.apache.uima.textmarker.action.AbstractTextMarkerAction;
+import org.apache.uima.textmarker.condition.AbstractTextMarkerCondition;
+import org.apache.uima.textmarker.type.Statistics;
+import org.apache.uima.textmarker.utils.UIMAUtils;
+import org.apache.uima.textmarker.verbalize.TextMarkerVerbalizer;
+
+public class StatisticsVisitor implements TextMarkerInferenceVisitor {
+
+ private Map<String, Long> conditionTime;
+
+ private Map<String, Long> actionTime;
+
+ private Map<String, Integer> conditionAmount;
+
+ private Map<String, Integer> actionAmount;
+
+ private Map<String, Long> conditionDelta;
+
+ private Map<String, Long> actionDelta;
+
+ private TextMarkerVerbalizer verbalizer;
+
+ public StatisticsVisitor(TextMarkerVerbalizer verbalizer) {
+ super();
+ this.verbalizer = verbalizer;
+ conditionTime = new HashMap<String, Long>();
+ actionTime = new HashMap<String, Long>();
+ conditionAmount = new HashMap<String, Integer>();
+ actionAmount = new HashMap<String, Integer>();
+ conditionDelta = new HashMap<String, Long>();
+ actionDelta = new HashMap<String, Long>();
+ }
+
+ public void beginVisit(TextMarkerElement element, ScriptApply result) {
+ if (element instanceof AbstractTextMarkerCondition) {
+ AbstractTextMarkerCondition c = (AbstractTextMarkerCondition) element;
+ String name = verbalizer.verbalizeName(c);
+ Integer amount = conditionAmount.get(name);
+ if (amount == null)
+ amount = 0;
+ amount++;
+ conditionAmount.put(name, amount);
+ conditionDelta.put(name, System.currentTimeMillis());
+ } else if (element instanceof AbstractTextMarkerAction) {
+ AbstractTextMarkerAction a = (AbstractTextMarkerAction) element;
+ String name = verbalizer.verbalizeName(a);
+ Integer amount = actionAmount.get(name);
+ if (amount == null)
+ amount = 0;
+ amount++;
+ actionAmount.put(name, amount);
+ actionDelta.put(name, System.currentTimeMillis());
+ }
+ }
+
+ public void endVisit(TextMarkerElement element, ScriptApply result) {
+ if (element instanceof AbstractTextMarkerCondition) {
+ AbstractTextMarkerCondition c = (AbstractTextMarkerCondition) element;
+ String name = verbalizer.verbalizeName(c);
+ Long start = conditionDelta.get(name);
+ long delta = System.currentTimeMillis() - start;
+ Long total = conditionTime.get(name);
+ if (total == null)
+ total = 0L;
+ total += delta;
+ conditionTime.put(name, total);
+ } else if (element instanceof AbstractTextMarkerAction) {
+ AbstractTextMarkerAction a = (AbstractTextMarkerAction) element;
+ String name = verbalizer.verbalizeName(a);
+ Long start = actionDelta.get(name);
+ long delta = System.currentTimeMillis() - start;
+ Long total = actionTime.get(name);
+ if (total == null)
+ total = 0L;
+ total += delta;
+ actionTime.put(name, total);
+ }
+ }
+
+ public void finished(TextMarkerStream stream, List<TextMarkerInferenceVisitor> visitors) {
+ List<String> names = new ArrayList<String>();
+ List<Double> totals = new ArrayList<Double>();
+ List<Integer> amounts = new ArrayList<Integer>();
+ List<Double> parts = new ArrayList<Double>();
+ for (String each : conditionTime.keySet()) {
+ double total = conditionTime.get(each);
+ double amount = conditionAmount.get(each);
+ double part = total / amount;
+ part *= 10000;
+ part = Math.round(part);
+ part /= 10000;
+ names.add(each);
+ totals.add(total);
+ amounts.add((int) amount);
+ parts.add(part);
+ }
+
+ for (String each : actionTime.keySet()) {
+ double total = actionTime.get(each);
+ double amount = actionAmount.get(each);
+ double part = total / amount;
+ part *= 10000;
+ part = Math.round(part);
+ part /= 10000;
+ names.add(each);
+ totals.add(total);
+ amounts.add((int) amount);
+ parts.add(part);
+ }
+ JCas jCas = stream.getJCas();
+ StringArray nameArray = UIMAUtils.toStringArray(jCas, names.toArray(new String[] {}));
+ DoubleArray totalArray = UIMAUtils.toDoubleArray(jCas, getDoubleArray(totals));
+ IntegerArray amountArray = UIMAUtils.toIntegerArray(jCas, getIntegerArray(amounts));
+ DoubleArray partArray = UIMAUtils.toDoubleArray(jCas, getDoubleArray(parts));
+
+ Type type = jCas.getCasType(Statistics.type);
+ Feature fname = type.getFeatureByBaseName("name");
+ Feature ftotal = type.getFeatureByBaseName("total");
+ Feature famount = type.getFeatureByBaseName("amount");
+ Feature fparts = type.getFeatureByBaseName("part");
+ FeatureStructure fs = jCas.getCas().createFS(type);
+ fs.setFeatureValue(fname, nameArray);
+ fs.setFeatureValue(ftotal, totalArray);
+ fs.setFeatureValue(famount, amountArray);
+ fs.setFeatureValue(fparts, partArray);
+ jCas.getCas().addFsToIndexes(fs);
+ }
+
+ private int[] getIntegerArray(List<Integer> array) {
+ int[] result = new int[array.size()];
+ int i = 0;
+ for (Integer each : array) {
+ result[i++] = each;
+ }
+ return result;
+ }
+
+ private double[] getDoubleArray(List<Double> array) {
+ double[] result = new double[array.size()];
+ int i = 0;
+ for (Double each : array) {
+ result[i++] = each;
+ }
+ return result;
+ }
+
+ public Map<String, Long> getConditionTime() {
+ return conditionTime;
+ }
+
+ public Map<String, Long> getActionTime() {
+ return actionTime;
+ }
+
+ public Map<String, Integer> getConditionAmount() {
+ return conditionAmount;
+ }
+
+ public Map<String, Integer> getActionAmount() {
+ return actionAmount;
+ }
+
+}
Added: uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/visitor/TextMarkerInferenceVisitor.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/visitor/TextMarkerInferenceVisitor.java?rev=1243619&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/visitor/TextMarkerInferenceVisitor.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/visitor/TextMarkerInferenceVisitor.java Mon Feb 13 17:44:52 2012
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+*/
+
+package org.apache.uima.textmarker.visitor;
+
+import java.util.List;
+
+import org.apache.uima.textmarker.ScriptApply;
+import org.apache.uima.textmarker.TextMarkerElement;
+import org.apache.uima.textmarker.TextMarkerStream;
+
+
+public interface TextMarkerInferenceVisitor {
+
+ void beginVisit(TextMarkerElement element, ScriptApply result);
+
+ void endVisit(TextMarkerElement element, ScriptApply result);
+
+ void finished(TextMarkerStream stream, List<TextMarkerInferenceVisitor> visitors);
+
+}
Added: uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/visitor/TimeProfilerVisitor.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/visitor/TimeProfilerVisitor.java?rev=1243619&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/visitor/TimeProfilerVisitor.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/visitor/TimeProfilerVisitor.java Mon Feb 13 17:44:52 2012
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+*/
+
+package org.apache.uima.textmarker.visitor;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.uima.textmarker.ScriptApply;
+import org.apache.uima.textmarker.TextMarkerElement;
+import org.apache.uima.textmarker.TextMarkerStream;
+
+
+public class TimeProfilerVisitor implements TextMarkerInferenceVisitor {
+
+ private Map<TextMarkerElement, Long> timeInfo;
+
+ public TimeProfilerVisitor() {
+ super();
+ timeInfo = new HashMap<TextMarkerElement, Long>();
+ }
+
+ public void beginVisit(TextMarkerElement element, ScriptApply result) {
+ getTimeInfo().put(element, System.currentTimeMillis());
+ }
+
+ public void endVisit(TextMarkerElement element, ScriptApply result) {
+ Long start = getTimeInfo().get(element);
+ long value = System.currentTimeMillis() - start;
+ getTimeInfo().put(element, value);
+ }
+
+ public void finished(TextMarkerStream stream, List<TextMarkerInferenceVisitor> visitors) {
+ // others do the work
+ }
+
+ public Map<TextMarkerElement, Long> getTimeInfo() {
+ return timeInfo;
+ }
+
+}
Added: uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/AllTests.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/AllTests.java?rev=1243619&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/AllTests.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/AllTests.java Mon Feb 13 17:44:52 2012
@@ -0,0 +1,12 @@
+package org.apache.uima.textmarker;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.junit.runners.Suite.SuiteClasses;
+
+@RunWith(Suite.class)
+@SuiteClasses({ DynamicAnchoringTest.class, DynamicAnchoringTest2.class, FilteringTest.class,
+ QuantifierTest1.class, QuantifierTest2.class, RuleInferenceTest.class, LongGreedyTest.class })
+public class AllTests {
+
+}
Added: uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/DynamicAnchoringTest.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/DynamicAnchoringTest.java?rev=1243619&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/DynamicAnchoringTest.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/DynamicAnchoringTest.java Mon Feb 13 17:44:52 2012
@@ -0,0 +1,215 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.textmarker;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.FSIterator;
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.cas.text.AnnotationIndex;
+import org.junit.Test;
+
+public class DynamicAnchoringTest {
+
+ @Test
+ public void test() {
+ String name = RuleInferenceTest.class.getSimpleName();
+ String namespace = RuleInferenceTest.class.getPackage().getName().replaceAll("\\.", "/");
+ CAS cas = null;
+ try {
+ cas = TextMarkerTestUtils.process(namespace + "/" + name + ".tm", namespace + "/" + name
+ + ".txt", 50);
+ } catch (Exception e) {
+ e.printStackTrace();
+ assert (false);
+ }
+ Type t = null;
+ AnnotationIndex<AnnotationFS> ai = null;
+ FSIterator<AnnotationFS> iterator = null;
+
+ t = TextMarkerTestUtils.getTestType(cas, 1);
+ ai = cas.getAnnotationIndex(t);
+ assertEquals(4, ai.size());
+ iterator = ai.iterator();
+ assertEquals("Peter", iterator.next().getCoveredText());
+ assertEquals("Jochen", iterator.next().getCoveredText());
+ assertEquals("Flo", iterator.next().getCoveredText());
+ assertEquals("Georg", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 2);
+ ai = cas.getAnnotationIndex(t);
+ iterator = ai.iterator();
+ assertEquals(1, ai.size());
+ assertEquals("und", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 3);
+ ai = cas.getAnnotationIndex(t);
+ iterator = ai.iterator();
+ assertEquals(0, ai.size());
+
+ t = TextMarkerTestUtils.getTestType(cas, 4);
+ ai = cas.getAnnotationIndex(t);
+ iterator = ai.iterator();
+ assertEquals(5, ai.size());
+ assertEquals("Peter", iterator.next().getCoveredText());
+ assertEquals("Jochen", iterator.next().getCoveredText());
+ assertEquals("Flo und Georg", iterator.next().getCoveredText());
+ assertEquals("und Georg", iterator.next().getCoveredText());
+ assertEquals("Georg", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 5);
+ ai = cas.getAnnotationIndex(t);
+ iterator = ai.iterator();
+ assertEquals(2, ai.size());
+ assertEquals(",", iterator.next().getCoveredText());
+ assertEquals(",", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 6);
+ ai = cas.getAnnotationIndex(t);
+ iterator = ai.iterator();
+ assertEquals(2, ai.size());
+ assertEquals("Peter, Jochen,", iterator.next().getCoveredText());
+ assertEquals("Jochen,", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 7);
+ ai = cas.getAnnotationIndex(t);
+ iterator = ai.iterator();
+ assertEquals(5, ai.size());
+ assertEquals("Peter", iterator.next().getCoveredText());
+ assertEquals("Jochen", iterator.next().getCoveredText());
+ assertEquals("Flo", iterator.next().getCoveredText());
+ assertEquals("und", iterator.next().getCoveredText());
+ assertEquals("Georg", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 8);
+ ai = cas.getAnnotationIndex(t);
+ iterator = ai.iterator();
+ assertEquals(5, ai.size());
+ assertEquals("Peter", iterator.next().getCoveredText());
+ assertEquals("Jochen", iterator.next().getCoveredText());
+ assertEquals("Flo und Georg", iterator.next().getCoveredText());
+ assertEquals("und Georg", iterator.next().getCoveredText());
+ assertEquals("Georg", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 9);
+ ai = cas.getAnnotationIndex(t);
+ iterator = ai.iterator();
+ assertEquals(2, ai.size());
+ assertEquals("Peter, Jochen, Flo", iterator.next().getCoveredText());
+ assertEquals("Jochen, Flo", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 10);
+ ai = cas.getAnnotationIndex(t);
+ iterator = ai.iterator();
+ assertEquals(3, ai.size());
+ assertEquals("Peter, Jochen, Flo und", iterator.next().getCoveredText());
+ assertEquals("Jochen, Flo und", iterator.next().getCoveredText());
+ assertEquals("Flo und", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 11);
+ ai = cas.getAnnotationIndex(t);
+ iterator = ai.iterator();
+ assertEquals(3, ai.size());
+ assertEquals("Peter, Jochen, Flo und Georg.", iterator.next().getCoveredText());
+ assertEquals("Jochen, Flo und Georg.", iterator.next().getCoveredText());
+ assertEquals("Flo und Georg.", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 12);
+ ai = cas.getAnnotationIndex(t);
+ iterator = ai.iterator();
+ assertEquals(6, ai.size());
+ assertEquals(",", iterator.next().getCoveredText());
+ assertEquals(",", iterator.next().getCoveredText());
+ assertEquals(",", iterator.next().getCoveredText());
+ assertEquals("und", iterator.next().getCoveredText());
+ assertEquals("und", iterator.next().getCoveredText());
+ assertEquals("und", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 13);
+ ai = cas.getAnnotationIndex(t);
+ iterator = ai.iterator();
+ assertEquals(6, ai.size());
+ assertEquals("Peter,", iterator.next().getCoveredText());
+ assertEquals("Jochen,", iterator.next().getCoveredText());
+ assertEquals("Jochen,", iterator.next().getCoveredText());
+ assertEquals("Flo und", iterator.next().getCoveredText());
+ assertEquals("Flo und", iterator.next().getCoveredText());
+ assertEquals("Flo und", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 14);
+ ai = cas.getAnnotationIndex(t);
+ iterator = ai.iterator();
+ assertEquals(3, ai.size());
+ assertEquals("Peter, Jochen, Flo und", iterator.next().getCoveredText());
+ assertEquals("Jochen, Flo und", iterator.next().getCoveredText());
+ assertEquals("Flo und", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 15);
+ ai = cas.getAnnotationIndex(t);
+ iterator = ai.iterator();
+ assertEquals(1, ai.size());
+ assertEquals("Peter, Jochen", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 16);
+ ai = cas.getAnnotationIndex(t);
+ iterator = ai.iterator();
+ assertEquals(1, ai.size());
+ assertEquals("Georg.", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 17);
+ ai = cas.getAnnotationIndex(t);
+ iterator = ai.iterator();
+ assertEquals(1, ai.size());
+ assertEquals("Flo und Georg.", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 18);
+ ai = cas.getAnnotationIndex(t);
+ assertEquals(3, ai.size());
+ iterator = ai.iterator();
+ assertEquals("Peter,", iterator.next().getCoveredText());
+ assertEquals("Jochen,", iterator.next().getCoveredText());
+ assertEquals("Georg.", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 20);
+ ai = cas.getAnnotationIndex(t);
+ iterator = ai.iterator();
+ assertEquals(1, ai.size());
+ assertEquals("Peter, Jochen", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 21);
+ ai = cas.getAnnotationIndex(t);
+ iterator = ai.iterator();
+ assertEquals(1, ai.size());
+ assertEquals("Georg.", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 22);
+ ai = cas.getAnnotationIndex(t);
+ iterator = ai.iterator();
+ assertEquals(1, ai.size());
+ assertEquals("Flo und Georg.", iterator.next().getCoveredText());
+
+ if (cas != null) {
+ cas.release();
+ }
+
+ }
+}
Added: uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/DynamicAnchoringTest2.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/DynamicAnchoringTest2.java?rev=1243619&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/DynamicAnchoringTest2.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/DynamicAnchoringTest2.java Mon Feb 13 17:44:52 2012
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.textmarker;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.FSIterator;
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.cas.text.AnnotationIndex;
+import org.junit.Test;
+
+public class DynamicAnchoringTest2 {
+
+ @Test
+ public void test() {
+ String name = this.getClass().getSimpleName();
+ String namespace = this.getClass().getPackage().getName().replaceAll("\\.", "/");
+ CAS cas = null;
+ try {
+ cas = TextMarkerTestUtils.process(namespace + "/" + name + ".tm", namespace + "/" + name
+ + ".txt", 50, true);
+ } catch (Exception e) {
+ e.printStackTrace();
+ assert (false);
+ }
+ Type t = null;
+ AnnotationIndex<AnnotationFS> ai = null;
+ FSIterator<AnnotationFS> iterator = null;
+
+ t = TextMarkerTestUtils.getTestType(cas, 1);
+ ai = cas.getAnnotationIndex(t);
+ assertEquals(1, ai.size());
+ iterator = ai.iterator();
+ assertEquals("A b", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 2);
+ ai = cas.getAnnotationIndex(t);
+ assertEquals(1, ai.size());
+ iterator = ai.iterator();
+ assertEquals("b A", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 3);
+ ai = cas.getAnnotationIndex(t);
+ assertEquals(1, ai.size());
+ iterator = ai.iterator();
+ assertEquals("A b A", iterator.next().getCoveredText());
+
+ }
+}
Added: uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/FilteringTest.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/FilteringTest.java?rev=1243619&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/FilteringTest.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/FilteringTest.java Mon Feb 13 17:44:52 2012
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.textmarker;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.FSIterator;
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.cas.text.AnnotationIndex;
+import org.junit.Test;
+
+public class FilteringTest {
+
+ @Test
+ public void test() {
+ String name = this.getClass().getSimpleName();
+ String namespace = this.getClass().getPackage().getName().replaceAll("\\.", "/");
+ CAS cas = null;
+ try {
+ cas = TextMarkerTestUtils.process(namespace + "/" + name + ".tm", namespace + "/" + name
+ + ".txt", 50);
+ } catch (Exception e) {
+ e.printStackTrace();
+ assert (false);
+ }
+ Type t = null;
+ AnnotationIndex<AnnotationFS> ai = null;
+ FSIterator<AnnotationFS> iterator = null;
+
+ t = TextMarkerTestUtils.getTestType(cas, 1);
+ ai = cas.getAnnotationIndex(t);
+ assertEquals(0, ai.size());
+
+ t = TextMarkerTestUtils.getTestType(cas, 2);
+ ai = cas.getAnnotationIndex(t);
+ iterator = ai.iterator();
+ assertEquals(2, ai.size());
+ assertEquals("Peter, Jochen", iterator.next().getCoveredText());
+ assertEquals("Jochen, Flo", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 3);
+ ai = cas.getAnnotationIndex(t);
+ iterator = ai.iterator();
+ assertEquals(0, ai.size());
+
+ t = TextMarkerTestUtils.getTestType(cas, 4);
+ ai = cas.getAnnotationIndex(t);
+ iterator = ai.iterator();
+ assertEquals(2, ai.size());
+ assertEquals(", Jochen, ", iterator.next().getCoveredText());
+ assertEquals(", ", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 5);
+ ai = cas.getAnnotationIndex(t);
+ iterator = ai.iterator();
+ assertEquals(4, ai.size());
+ assertEquals("Peter, Jochen, Flo", iterator.next().getCoveredText());
+ assertEquals("Flo und", iterator.next().getCoveredText());
+ assertEquals("und Georg", iterator.next().getCoveredText());
+ assertEquals("Georg.", iterator.next().getCoveredText());
+
+
+ t = TextMarkerTestUtils.getTestType(cas, 15);
+ ai = cas.getAnnotationIndex(t);
+ iterator = ai.iterator();
+ assertEquals(1, ai.size());
+ assertEquals("Peter, Jochen", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 16);
+ ai = cas.getAnnotationIndex(t);
+ iterator = ai.iterator();
+ assertEquals(1, ai.size());
+ assertEquals("Georg.", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 17);
+ ai = cas.getAnnotationIndex(t);
+ iterator = ai.iterator();
+ assertEquals(1, ai.size());
+ assertEquals("Flo und Georg.", iterator.next().getCoveredText());
+
+ if (cas != null) {
+ cas.release();
+ }
+
+ }
+}
Added: uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/LongGreedyTest.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/LongGreedyTest.java?rev=1243619&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/LongGreedyTest.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/LongGreedyTest.java Mon Feb 13 17:44:52 2012
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.textmarker;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.FSIterator;
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.cas.text.AnnotationIndex;
+import org.junit.Test;
+
+public class LongGreedyTest {
+
+ @Test
+ public void test() {
+ String name = this.getClass().getSimpleName();
+ String namespace = this.getClass().getPackage().getName().replaceAll("\\.", "/");
+ CAS cas = null;
+ try {
+ cas = TextMarkerTestUtils.process(namespace + "/" + name + ".tm", namespace + "/" + name
+ + ".txt", 50);
+ } catch (Exception e) {
+ e.printStackTrace();
+ assert (false);
+ }
+ Type t = null;
+ AnnotationIndex<AnnotationFS> ai = null;
+ FSIterator<AnnotationFS> iterator = null;
+
+ t = TextMarkerTestUtils.getTestType(cas, 1);
+ ai = cas.getAnnotationIndex(t);
+ assertEquals(1, ai.size());
+ iterator = ai.iterator();
+ String coveredText = iterator.next().getCoveredText();
+ assertEquals(64998, coveredText.length());
+
+ if (cas != null) {
+ cas.release();
+ }
+
+ }
+}
Added: uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/QuantifierTest1.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/QuantifierTest1.java?rev=1243619&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/QuantifierTest1.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/QuantifierTest1.java Mon Feb 13 17:44:52 2012
@@ -0,0 +1,174 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.textmarker;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.FSIterator;
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.cas.text.AnnotationIndex;
+import org.junit.Test;
+
+public class QuantifierTest1 {
+ @Test
+ public void test() {
+ String name = this.getClass().getSimpleName();
+ String namespace = this.getClass().getPackage().getName().replaceAll("\\.", "/");
+ CAS cas = null;
+ try {
+ cas = TextMarkerTestUtils.process(namespace + "/" + name + ".tm", namespace + "/" + name
+ + ".txt", 50);
+ } catch (Exception e) {
+ e.printStackTrace();
+ assert (false);
+ }
+ Type t = null;
+ AnnotationIndex<AnnotationFS> ai = null;
+ FSIterator<AnnotationFS> iterator = null;
+
+ t = TextMarkerTestUtils.getTestType(cas, 1);
+ ai = cas.getAnnotationIndex(t);
+ assertEquals(3, ai.size());
+ iterator = ai.iterator();
+ assertEquals("A B", iterator.next().getCoveredText());
+ assertEquals("A B", iterator.next().getCoveredText());
+ assertEquals("A", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 2);
+ ai = cas.getAnnotationIndex(t);
+ assertEquals(3, ai.size());
+ iterator = ai.iterator();
+ assertEquals("A", iterator.next().getCoveredText());
+ assertEquals("A", iterator.next().getCoveredText());
+ assertEquals("A", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 3);
+ ai = cas.getAnnotationIndex(t);
+ assertEquals(3, ai.size());
+ iterator = ai.iterator();
+ assertEquals("A B", iterator.next().getCoveredText());
+ assertEquals("A B B", iterator.next().getCoveredText());
+ assertEquals("A", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 4);
+ ai = cas.getAnnotationIndex(t);
+ assertEquals(3, ai.size());
+ iterator = ai.iterator();
+ assertEquals("A", iterator.next().getCoveredText());
+ assertEquals("A", iterator.next().getCoveredText());
+ assertEquals("A", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 5);
+ ai = cas.getAnnotationIndex(t);
+ assertEquals(2, ai.size());
+ iterator = ai.iterator();
+ assertEquals("A B", iterator.next().getCoveredText());
+ assertEquals("A B B", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 6);
+ ai = cas.getAnnotationIndex(t);
+ assertEquals(2, ai.size());
+ iterator = ai.iterator();
+ assertEquals("A B", iterator.next().getCoveredText());
+ assertEquals("A B", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 7);
+ ai = cas.getAnnotationIndex(t);
+ assertEquals(1, ai.size());
+ iterator = ai.iterator();
+ assertEquals("A B B", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 8);
+ ai = cas.getAnnotationIndex(t);
+ assertEquals(1, ai.size());
+ iterator = ai.iterator();
+ assertEquals("A B B", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 9);
+ ai = cas.getAnnotationIndex(t);
+ assertEquals(2, ai.size());
+ iterator = ai.iterator();
+ assertEquals("A B", iterator.next().getCoveredText());
+ assertEquals("A B B", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 10);
+ ai = cas.getAnnotationIndex(t);
+ assertEquals(3, ai.size());
+ iterator = ai.iterator();
+ assertEquals("A B", iterator.next().getCoveredText());
+ assertEquals("A B", iterator.next().getCoveredText());
+ assertEquals("A", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 11);
+ ai = cas.getAnnotationIndex(t);
+ assertEquals(3, ai.size());
+ iterator = ai.iterator();
+ assertEquals("A B", iterator.next().getCoveredText());
+ assertEquals("A B B", iterator.next().getCoveredText());
+ assertEquals("A", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 12);
+ ai = cas.getAnnotationIndex(t);
+ assertEquals(2, ai.size());
+ iterator = ai.iterator();
+ assertEquals("A B C", iterator.next().getCoveredText());
+ assertEquals("A C", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 13);
+ ai = cas.getAnnotationIndex(t);
+ assertEquals(2, ai.size());
+ iterator = ai.iterator();
+ assertEquals("A B C", iterator.next().getCoveredText());
+ assertEquals("A C", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 14);
+ ai = cas.getAnnotationIndex(t);
+ assertEquals(3, ai.size());
+ iterator = ai.iterator();
+ assertEquals("A B C", iterator.next().getCoveredText());
+ assertEquals("A B B C", iterator.next().getCoveredText());
+ assertEquals("A C", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 15);
+ ai = cas.getAnnotationIndex(t);
+ assertEquals(3, ai.size());
+ iterator = ai.iterator();
+ assertEquals("A B C", iterator.next().getCoveredText());
+ assertEquals("A B B C", iterator.next().getCoveredText());
+ assertEquals("A C", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 16);
+ ai = cas.getAnnotationIndex(t);
+ assertEquals(2, ai.size());
+ iterator = ai.iterator();
+ assertEquals("A B C", iterator.next().getCoveredText());
+ assertEquals("A B B C", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 17);
+ ai = cas.getAnnotationIndex(t);
+ assertEquals(2, ai.size());
+ iterator = ai.iterator();
+ assertEquals("A B C", iterator.next().getCoveredText());
+ assertEquals("A B B C", iterator.next().getCoveredText());
+
+ }
+}
Added: uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/QuantifierTest2.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/QuantifierTest2.java?rev=1243619&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/QuantifierTest2.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/QuantifierTest2.java Mon Feb 13 17:44:52 2012
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.textmarker;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.FSIterator;
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.cas.text.AnnotationIndex;
+import org.junit.Test;
+
+public class QuantifierTest2 {
+ @Test
+ public void test() {
+ String name = this.getClass().getSimpleName();
+ String namespace = this.getClass().getPackage().getName().replaceAll("\\.", "/");
+ CAS cas = null;
+ try {
+ cas = TextMarkerTestUtils.process(namespace + "/" + name + ".tm", namespace + "/" + name
+ + ".txt", 50);
+ } catch (Exception e) {
+ e.printStackTrace();
+ assert (false);
+ }
+ Type t = null;
+ AnnotationIndex<AnnotationFS> ai = null;
+ FSIterator<AnnotationFS> iterator = null;
+
+ t = TextMarkerTestUtils.getTestType(cas, 1);
+ ai = cas.getAnnotationIndex(t);
+ assertEquals(3, ai.size());
+ iterator = ai.iterator();
+ assertEquals("A3 A4", iterator.next().getCoveredText());
+ assertEquals("A4 A5", iterator.next().getCoveredText());
+ assertEquals("A6 A7", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 2);
+ ai = cas.getAnnotationIndex(t);
+ assertEquals(1, ai.size());
+ iterator = ai.iterator();
+ assertEquals("A1 B B A2", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 3);
+ ai = cas.getAnnotationIndex(t);
+ assertEquals(0, ai.size());
+
+ t = TextMarkerTestUtils.getTestType(cas, 4);
+ ai = cas.getAnnotationIndex(t);
+ assertEquals(4, ai.size());
+ iterator = ai.iterator();
+ assertEquals("A1 B B A2", iterator.next().getCoveredText());
+ assertEquals("A3 A4", iterator.next().getCoveredText());
+ assertEquals("A4 A5", iterator.next().getCoveredText());
+ assertEquals("A6 A7", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 5);
+ ai = cas.getAnnotationIndex(t);
+ assertEquals(0, ai.size());
+
+ }
+}
Added: uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/RuleInferenceTest.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/RuleInferenceTest.java?rev=1243619&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/RuleInferenceTest.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/RuleInferenceTest.java Mon Feb 13 17:44:52 2012
@@ -0,0 +1,215 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.textmarker;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.FSIterator;
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.cas.text.AnnotationIndex;
+import org.junit.Test;
+
+public class RuleInferenceTest {
+
+ @Test
+ public void test() {
+ String name = this.getClass().getSimpleName();
+ String namespace = this.getClass().getPackage().getName().replaceAll("\\.", "/");
+ CAS cas = null;
+ try {
+ cas = TextMarkerTestUtils.process(namespace + "/" + name + ".tm", namespace + "/" + name
+ + ".txt", 50);
+ } catch (Exception e) {
+ e.printStackTrace();
+ assert (false);
+ }
+ Type t = null;
+ AnnotationIndex<AnnotationFS> ai = null;
+ FSIterator<AnnotationFS> iterator = null;
+
+ t = TextMarkerTestUtils.getTestType(cas, 1);
+ ai = cas.getAnnotationIndex(t);
+ assertEquals(4, ai.size());
+ iterator = ai.iterator();
+ assertEquals("Peter", iterator.next().getCoveredText());
+ assertEquals("Jochen", iterator.next().getCoveredText());
+ assertEquals("Flo", iterator.next().getCoveredText());
+ assertEquals("Georg", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 2);
+ ai = cas.getAnnotationIndex(t);
+ iterator = ai.iterator();
+ assertEquals(1, ai.size());
+ assertEquals("und", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 3);
+ ai = cas.getAnnotationIndex(t);
+ iterator = ai.iterator();
+ assertEquals(0, ai.size());
+
+ t = TextMarkerTestUtils.getTestType(cas, 4);
+ ai = cas.getAnnotationIndex(t);
+ iterator = ai.iterator();
+ assertEquals(5, ai.size());
+ assertEquals("Peter", iterator.next().getCoveredText());
+ assertEquals("Jochen", iterator.next().getCoveredText());
+ assertEquals("Flo und Georg", iterator.next().getCoveredText());
+ assertEquals("und Georg", iterator.next().getCoveredText());
+ assertEquals("Georg", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 5);
+ ai = cas.getAnnotationIndex(t);
+ iterator = ai.iterator();
+ assertEquals(2, ai.size());
+ assertEquals(",", iterator.next().getCoveredText());
+ assertEquals(",", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 6);
+ ai = cas.getAnnotationIndex(t);
+ iterator = ai.iterator();
+ assertEquals(2, ai.size());
+ assertEquals("Peter, Jochen,", iterator.next().getCoveredText());
+ assertEquals("Jochen,", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 7);
+ ai = cas.getAnnotationIndex(t);
+ iterator = ai.iterator();
+ assertEquals(5, ai.size());
+ assertEquals("Peter", iterator.next().getCoveredText());
+ assertEquals("Jochen", iterator.next().getCoveredText());
+ assertEquals("Flo", iterator.next().getCoveredText());
+ assertEquals("und", iterator.next().getCoveredText());
+ assertEquals("Georg", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 8);
+ ai = cas.getAnnotationIndex(t);
+ iterator = ai.iterator();
+ assertEquals(5, ai.size());
+ assertEquals("Peter", iterator.next().getCoveredText());
+ assertEquals("Jochen", iterator.next().getCoveredText());
+ assertEquals("Flo und Georg", iterator.next().getCoveredText());
+ assertEquals("und Georg", iterator.next().getCoveredText());
+ assertEquals("Georg", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 9);
+ ai = cas.getAnnotationIndex(t);
+ iterator = ai.iterator();
+ assertEquals(2, ai.size());
+ assertEquals("Peter, Jochen, Flo", iterator.next().getCoveredText());
+ assertEquals("Jochen, Flo", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 10);
+ ai = cas.getAnnotationIndex(t);
+ iterator = ai.iterator();
+ assertEquals(3, ai.size());
+ assertEquals("Peter, Jochen, Flo und", iterator.next().getCoveredText());
+ assertEquals("Jochen, Flo und", iterator.next().getCoveredText());
+ assertEquals("Flo und", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 11);
+ ai = cas.getAnnotationIndex(t);
+ iterator = ai.iterator();
+ assertEquals(3, ai.size());
+ assertEquals("Peter, Jochen, Flo und Georg.", iterator.next().getCoveredText());
+ assertEquals("Jochen, Flo und Georg.", iterator.next().getCoveredText());
+ assertEquals("Flo und Georg.", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 12);
+ ai = cas.getAnnotationIndex(t);
+ iterator = ai.iterator();
+ assertEquals(6, ai.size());
+ assertEquals(",", iterator.next().getCoveredText());
+ assertEquals(",", iterator.next().getCoveredText());
+ assertEquals(",", iterator.next().getCoveredText());
+ assertEquals("und", iterator.next().getCoveredText());
+ assertEquals("und", iterator.next().getCoveredText());
+ assertEquals("und", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 13);
+ ai = cas.getAnnotationIndex(t);
+ iterator = ai.iterator();
+ assertEquals(6, ai.size());
+ assertEquals("Peter,", iterator.next().getCoveredText());
+ assertEquals("Jochen,", iterator.next().getCoveredText());
+ assertEquals("Jochen,", iterator.next().getCoveredText());
+ assertEquals("Flo und", iterator.next().getCoveredText());
+ assertEquals("Flo und", iterator.next().getCoveredText());
+ assertEquals("Flo und", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 14);
+ ai = cas.getAnnotationIndex(t);
+ iterator = ai.iterator();
+ assertEquals(3, ai.size());
+ assertEquals("Peter, Jochen, Flo und", iterator.next().getCoveredText());
+ assertEquals("Jochen, Flo und", iterator.next().getCoveredText());
+ assertEquals("Flo und", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 15);
+ ai = cas.getAnnotationIndex(t);
+ iterator = ai.iterator();
+ assertEquals(1, ai.size());
+ assertEquals("Peter, Jochen", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 16);
+ ai = cas.getAnnotationIndex(t);
+ iterator = ai.iterator();
+ assertEquals(1, ai.size());
+ assertEquals("Georg.", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 17);
+ ai = cas.getAnnotationIndex(t);
+ iterator = ai.iterator();
+ assertEquals(1, ai.size());
+ assertEquals("Flo und Georg.", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 18);
+ ai = cas.getAnnotationIndex(t);
+ assertEquals(3, ai.size());
+ iterator = ai.iterator();
+ assertEquals("Peter,", iterator.next().getCoveredText());
+ assertEquals("Jochen,", iterator.next().getCoveredText());
+ assertEquals("Georg.", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 20);
+ ai = cas.getAnnotationIndex(t);
+ iterator = ai.iterator();
+ assertEquals(1, ai.size());
+ assertEquals("Peter, Jochen", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 21);
+ ai = cas.getAnnotationIndex(t);
+ iterator = ai.iterator();
+ assertEquals(1, ai.size());
+ assertEquals("Georg.", iterator.next().getCoveredText());
+
+ t = TextMarkerTestUtils.getTestType(cas, 22);
+ ai = cas.getAnnotationIndex(t);
+ iterator = ai.iterator();
+ assertEquals(1, ai.size());
+ assertEquals("Flo und Georg.", iterator.next().getCoveredText());
+
+ if (cas != null) {
+ cas.release();
+ }
+
+ }
+}
Added: uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/TextMarkerTestUtils.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/TextMarkerTestUtils.java?rev=1243619&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/TextMarkerTestUtils.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/TextMarkerTestUtils.java Mon Feb 13 17:44:52 2012
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.textmarker;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.apache.uima.UIMAFramework;
+import org.apache.uima.analysis_engine.AnalysisEngine;
+import org.apache.uima.analysis_engine.AnalysisEngineDescription;
+import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
+import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.Type;
+import org.apache.uima.resource.ResourceConfigurationException;
+import org.apache.uima.resource.ResourceInitializationException;
+import org.apache.uima.resource.ResourceSpecifier;
+import org.apache.uima.resource.metadata.TypeSystemDescription;
+import org.apache.uima.textmarker.engine.TextMarkerEngine;
+import org.apache.uima.util.CasCreationUtils;
+import org.apache.uima.util.FileUtils;
+import org.apache.uima.util.InvalidXMLException;
+import org.apache.uima.util.XMLInputSource;
+
+public class TextMarkerTestUtils {
+
+ private static final String TYPE = "org.apache.uima.T";
+
+ public static CAS process(String ruleFileName, String textFileName, int amount)
+ throws URISyntaxException, IOException, InvalidXMLException,
+ ResourceInitializationException, AnalysisEngineProcessException,
+ ResourceConfigurationException {
+ return process(ruleFileName, textFileName, amount, false);
+ }
+
+ public static CAS process(String ruleFileName, String textFileName, int amount,
+ boolean dynamicAnchoring) throws URISyntaxException, IOException, InvalidXMLException,
+ ResourceInitializationException, AnalysisEngineProcessException,
+ ResourceConfigurationException {
+ URL resource = TextMarkerTestUtils.class.getClassLoader().getResource(ruleFileName);
+ File ruleFile = new File(resource.toURI());
+ resource = TextMarkerTestUtils.class.getClassLoader().getResource(textFileName);
+ File textFile = new File(resource.toURI());
+ URL url = TextMarkerEngine.class.getResource("BasicEngine.xml");
+ XMLInputSource in = new XMLInputSource(url);
+ ResourceSpecifier specifier = UIMAFramework.getXMLParser().parseResourceSpecifier(in);
+ AnalysisEngineDescription aed = (AnalysisEngineDescription) specifier;
+
+ TypeSystemDescription basicTypeSystem = aed.getAnalysisEngineMetaData().getTypeSystem();
+ for (int i = 1; i <= amount; i++) {
+ basicTypeSystem.addType(TYPE + i, "Type for Testing", "uima.tcas.Annotation");
+ }
+
+ Collection<TypeSystemDescription> tsds = new ArrayList<TypeSystemDescription>();
+ tsds.add(basicTypeSystem);
+ TypeSystemDescription mergeTypeSystems = CasCreationUtils.mergeTypeSystems(tsds);
+ aed.getAnalysisEngineMetaData().setTypeSystem(mergeTypeSystems);
+
+ AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(specifier);
+ ae.setConfigParameterValue(TextMarkerEngine.SCRIPT_PATHS, new String[] { ruleFile
+ .getParentFile().getPath() });
+ String name = ruleFile.getName();
+ if (name.endsWith(".tm")) {
+ name = name.substring(0, name.length() - 3);
+ }
+ ae.setConfigParameterValue(TextMarkerEngine.MAIN_SCRIPT, name);
+ ae.setConfigParameterValue(TextMarkerEngine.DYNAMIC_ANCHORING, dynamicAnchoring);
+ ae.reconfigure();
+ CAS cas = ae.newCAS();
+ cas.setDocumentText(FileUtils.file2String(textFile, "UTF-8"));
+ ae.process(cas);
+ return cas;
+ }
+
+ public static Type getTestType(CAS cas, int i) {
+ if (cas == null)
+ return null;
+ return cas.getTypeSystem().getType(TYPE + i);
+ }
+}
Added: uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/DynamicAnchoringTest2.tm
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/DynamicAnchoringTest2.tm?rev=1243619&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/DynamicAnchoringTest2.tm (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/DynamicAnchoringTest2.tm Mon Feb 13 17:44:52 2012
@@ -0,0 +1,9 @@
+PACKAGE org.apache.uima;
+
+DECLARE T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25;
+
+CW SW{-> MARK(T1,1,2)};
+
+SW CW{-> MARK(T2,1,2)};
+
+CW SW{-> MARK(T3,1,2,3)} CW;
\ No newline at end of file
Added: uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/DynamicAnchoringTest2.txt
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/DynamicAnchoringTest2.txt?rev=1243619&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/DynamicAnchoringTest2.txt (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/DynamicAnchoringTest2.txt Mon Feb 13 17:44:52 2012
@@ -0,0 +1,93 @@
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A b A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A
+
Added: uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/FilteringTest.tm
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/FilteringTest.tm?rev=1243619&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/FilteringTest.tm (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/FilteringTest.tm Mon Feb 13 17:44:52 2012
@@ -0,0 +1,28 @@
+PACKAGE org.apache.uima;
+
+DECLARE T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25;
+
+
+Document{-> RETAINTYPE(SPACE)};
+
+W W{-> MARK(T1)};
+
+W PM SPACE W{-> MARK(T2,1,2,3,4)};
+
+Document{-> FILTERTYPE(W)};
+
+W{-> MARK(T3)};
+
+(PM SPACE)+{-> MARK(T4)};
+
+Document{-> RETAINTYPE(W)};
+
+Document{-> FILTERTYPE(T4)};
+
+W ANY{-> MARK(T5,1,2)};
+
+Document{-> FILTERTYPE, RETAINTYPE};
+
+(((CW PM) CW){-> MARK(T15)} COMMA)
+ (CW SW (CW PERIOD){-> MARK(T16)})
+ {-> MARK(T17)};
\ No newline at end of file
Added: uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/FilteringTest.txt
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/FilteringTest.txt?rev=1243619&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/FilteringTest.txt (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/FilteringTest.txt Mon Feb 13 17:44:52 2012
@@ -0,0 +1 @@
+Peter, Jochen, Flo und Georg.