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/12 12:44:18 UTC
svn commit: r1157040 [4/23] - in
/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine: ./ .settings/
META-INF/ desc/ lib/ src/ src/main/ src/main/java/ src/main/java/org/
src/main/java/org/apache/ src/main/java/org/apache/uima/
src/main/java/org/a...
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/ExecAction.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/ExecAction.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/ExecAction.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/ExecAction.java Fri Aug 12 10:44:04 2011
@@ -0,0 +1,108 @@
+/*
+ * 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.action;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.apache.uima.analysis_engine.AnalysisEngine;
+import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
+import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.cas.text.AnnotationIndex;
+import org.apache.uima.resource.ResourceInitializationException;
+import org.apache.uima.textmarker.ScriptApply;
+import org.apache.uima.textmarker.TextMarkerBlock;
+import org.apache.uima.textmarker.TextMarkerModule;
+import org.apache.uima.textmarker.TextMarkerStream;
+import org.apache.uima.textmarker.expression.list.TypeListExpression;
+import org.apache.uima.textmarker.rule.RuleMatch;
+import org.apache.uima.textmarker.rule.TextMarkerRuleElement;
+import org.apache.uima.textmarker.type.TextMarkerBasic;
+import org.apache.uima.textmarker.visitor.InferenceCrowd;
+
+public class ExecAction extends CallAction {
+
+ private TypeListExpression typeList;
+
+ public ExecAction(String namespace) {
+ super(namespace);
+ }
+
+ public ExecAction(String ns, TypeListExpression tl) {
+ this(ns);
+ this.typeList = tl;
+ }
+
+ @Override
+ protected void callScript(String blockName, RuleMatch match, TextMarkerRuleElement element,
+ TextMarkerStream stream, InferenceCrowd crowd, TextMarkerModule targetScript) {
+ TextMarkerBlock block = targetScript.getBlock(blockName);
+ if (block == null) {
+ return;
+ }
+ TextMarkerStream completeStream = stream.getCompleteStream();
+ ScriptApply apply = block.apply(completeStream, crowd);
+ match.addDelegateApply(this, apply);
+ }
+
+ @Override
+ protected void callEngine(RuleMatch match, InferenceCrowd crowd, AnalysisEngine targetEngine,
+ TextMarkerRuleElement element, TextMarkerStream stream)
+ throws ResourceInitializationException, AnalysisEngineProcessException {
+ CAS cas = stream.getCas();
+ targetEngine.process(cas);
+
+ if (typeList != null) {
+ List<Type> list = typeList.getList(element.getParent());
+ for (Type type : list) {
+ Map<TextMarkerBasic, Collection<AnnotationFS>> map = new HashMap<TextMarkerBasic, Collection<AnnotationFS>>();
+ AnnotationIndex<AnnotationFS> ai = cas.getAnnotationIndex(type);
+ for (AnnotationFS fs : ai) {
+ TextMarkerBasic basic = stream.getFirstBasicInWindow(fs);
+ if (basic != null) {
+ Collection<AnnotationFS> collection = map.get(basic);
+ if (collection == null) {
+ collection = new HashSet<AnnotationFS>();
+ map.put(basic, collection);
+ }
+ collection.add(fs);
+ }
+ }
+ Set<Entry<TextMarkerBasic, Collection<AnnotationFS>>> entrySet = map.entrySet();
+ for (Entry<TextMarkerBasic, Collection<AnnotationFS>> entry : entrySet) {
+ for (AnnotationFS each : entry.getValue()) {
+ cas.removeFsFromIndexes(each);
+ stream.removeAnnotation(entry.getKey(), each.getType());
+ cas.addFsToIndexes(each);
+ stream.addAnnotation(entry.getKey(), each);
+ }
+ }
+ }
+ }
+ System.out.println();
+ }
+}
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/ExecAction.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/ExecAction.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/ExpandAction.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/ExpandAction.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/ExpandAction.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/ExpandAction.java Fri Aug 12 10:44:04 2011
@@ -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.action;
+
+import java.util.List;
+
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.textmarker.TextMarkerStream;
+import org.apache.uima.textmarker.expression.number.NumberExpression;
+import org.apache.uima.textmarker.expression.type.TypeExpression;
+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.TextMarkerBasic;
+import org.apache.uima.textmarker.visitor.InferenceCrowd;
+
+public class ExpandAction extends MarkAction {
+
+ public ExpandAction(TypeExpression type, List<NumberExpression> list) {
+ super(type, null, 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);
+
+ 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 anchor = stream.getFirstBasicInWindow(first);
+ Type t = type.getType(element.getParent());
+ stream.removeAnnotation(anchor, t);
+ createAnnotation(anchor, element, stream, matchedAnnotation);
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/ExpandAction.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/ExpandAction.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/FillAction.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/FillAction.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/FillAction.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/FillAction.java Fri Aug 12 10:44:04 2011
@@ -0,0 +1,81 @@
+/*
+ * 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.action;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.jcas.tcas.Annotation;
+import org.apache.uima.textmarker.TextMarkerStream;
+import org.apache.uima.textmarker.expression.TextMarkerExpression;
+import org.apache.uima.textmarker.expression.string.StringExpression;
+import org.apache.uima.textmarker.expression.type.TypeExpression;
+import org.apache.uima.textmarker.rule.RuleMatch;
+import org.apache.uima.textmarker.rule.TextMarkerRuleElement;
+import org.apache.uima.textmarker.visitor.InferenceCrowd;
+
+public class FillAction extends AbstractStructureAction {
+
+ private Map<StringExpression, TextMarkerExpression> features;
+
+ private TypeExpression structureType;
+
+ public FillAction(TypeExpression structureType,
+ Map<StringExpression, TextMarkerExpression> features) {
+ super();
+ this.structureType = structureType;
+ this.features = features;
+ }
+
+ @Override
+ public void execute(RuleMatch match, TextMarkerRuleElement element, TextMarkerStream stream,
+ InferenceCrowd crowd) {
+ AnnotationFS matchedAnnotation = match.getMatchedAnnotation(stream, null);
+ if (matchedAnnotation == null) {
+ return;
+ }
+ Type type = getStructureType().getType(element.getParent());
+ List<AnnotationFS> list = stream.getAnnotationsInWindow(matchedAnnotation, type);
+ if (list.isEmpty()) {
+ list = stream.getOverappingAnnotations(matchedAnnotation, type);
+ }
+ //
+ // for (AnnotationFS each : list) {
+ // fillFeatures((Annotation)each, features, matchedAnnotation, element, stream);
+ // }
+ if (!list.isEmpty()) {
+ AnnotationFS annotationFS = list.get(0);
+ stream.getCas().removeFsFromIndexes(annotationFS);
+ fillFeatures((Annotation) annotationFS, features, matchedAnnotation, element, stream);
+ stream.getCas().addFsToIndexes(annotationFS);
+ }
+ }
+
+ public Map<StringExpression, TextMarkerExpression> getFeatures() {
+ return features;
+ }
+
+ public TypeExpression getStructureType() {
+ return structureType;
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/FillAction.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/FillAction.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/FilterMarkupAction.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/FilterMarkupAction.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/FilterMarkupAction.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/FilterMarkupAction.java Fri Aug 12 10:44:04 2011
@@ -0,0 +1,55 @@
+/*
+ * 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.action;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.uima.textmarker.TextMarkerStream;
+import org.apache.uima.textmarker.expression.string.StringExpression;
+import org.apache.uima.textmarker.rule.RuleMatch;
+import org.apache.uima.textmarker.rule.TextMarkerRuleElement;
+import org.apache.uima.textmarker.visitor.InferenceCrowd;
+
+
+public class FilterMarkupAction extends AbstractTextMarkerAction {
+
+ private List<StringExpression> markup;
+
+ public FilterMarkupAction(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.filterTags(list);
+ }
+
+ public List<StringExpression> getMarkup() {
+ return markup;
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/FilterMarkupAction.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/FilterMarkupAction.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/FilterTypeAction.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/FilterTypeAction.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/FilterTypeAction.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/FilterTypeAction.java Fri Aug 12 10:44:04 2011
@@ -0,0 +1,55 @@
+/*
+ * 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.action;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.uima.cas.Type;
+import org.apache.uima.textmarker.TextMarkerStream;
+import org.apache.uima.textmarker.expression.type.TypeExpression;
+import org.apache.uima.textmarker.rule.RuleMatch;
+import org.apache.uima.textmarker.rule.TextMarkerRuleElement;
+import org.apache.uima.textmarker.visitor.InferenceCrowd;
+
+public class FilterTypeAction extends AbstractTextMarkerAction {
+
+ public List<TypeExpression> getList() {
+ return list;
+ }
+
+ private List<TypeExpression> list;
+
+ public FilterTypeAction(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.filterTypes(types);
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/FilterTypeAction.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/FilterTypeAction.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/GatherAction.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/GatherAction.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/GatherAction.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/GatherAction.java Fri Aug 12 10:44:04 2011
@@ -0,0 +1,224 @@
+/*
+ * 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.action;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.uima.cas.FSIterator;
+import org.apache.uima.cas.Feature;
+import org.apache.uima.cas.FeatureStructure;
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.TypeSystem;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.jcas.JCas;
+import org.apache.uima.jcas.cas.FSArray;
+import org.apache.uima.jcas.cas.TOP;
+import org.apache.uima.jcas.tcas.Annotation;
+import org.apache.uima.textmarker.TextMarkerStream;
+import org.apache.uima.textmarker.expression.TextMarkerExpression;
+import org.apache.uima.textmarker.expression.list.NumberListExpression;
+import org.apache.uima.textmarker.expression.number.NumberExpression;
+import org.apache.uima.textmarker.expression.string.StringExpression;
+import org.apache.uima.textmarker.expression.type.TypeExpression;
+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.TextMarkerBasic;
+import org.apache.uima.textmarker.type.TextMarkerFrame;
+import org.apache.uima.textmarker.utils.UIMAUtils;
+import org.apache.uima.textmarker.visitor.InferenceCrowd;
+
+public class GatherAction extends AbstractStructureAction {
+
+ private TypeExpression structureType;
+
+ private Map<StringExpression, TextMarkerExpression> features;
+
+ private List<NumberExpression> indexes;
+
+ public GatherAction(TypeExpression structureType,
+ Map<StringExpression, TextMarkerExpression> features, List<NumberExpression> indexes) {
+ super();
+ this.structureType = structureType;
+ this.features = features == null ? new HashMap<StringExpression, TextMarkerExpression>()
+ : features;
+ this.indexes = (indexes == null || indexes.isEmpty()) ? null : indexes;
+ }
+
+ @Override
+ public void execute(RuleMatch match, TextMarkerRuleElement element, TextMarkerStream stream,
+ InferenceCrowd crowd) {
+ List<Integer> indexList = getIndexList(match, element);
+ AnnotationFS matchedAnnotation = match.getMatchedAnnotation(stream, indexList);
+ if (matchedAnnotation == null) {
+ return;
+ }
+ Type type = structureType.getType(element.getParent());
+ FeatureStructure newFS = stream.getCas().createFS(type);
+ if (newFS instanceof Annotation) {
+ Annotation a = (Annotation) newFS;
+ a.setBegin(matchedAnnotation.getBegin());
+ a.setEnd(matchedAnnotation.getEnd());
+ TextMarkerBasic first = stream.getFirstBasicInWindow(matchedAnnotation);
+ if (first == null) {
+ first = match.getFirstBasic();
+ }
+ stream.addAnnotation(first, a);
+ }
+ TOP newStructure = null;
+ if (newFS instanceof TOP) {
+ newStructure = (TOP) newFS;
+ gatherFeatures(newStructure, features, matchedAnnotation, element, match, stream);
+ newStructure.addToIndexes();
+ }
+ }
+
+ private void gatherFeatures(TOP structure, Map<StringExpression, TextMarkerExpression> features,
+ AnnotationFS matchedAnnotation, TextMarkerRuleElement element, RuleMatch match,
+ TextMarkerStream stream) {
+ Map<String, List<Number>> map = new HashMap<String, List<Number>>();
+ for (Entry<StringExpression, TextMarkerExpression> each : features.entrySet()) {
+ String value = each.getKey().getStringValue(element.getParent());
+ TextMarkerExpression expr = each.getValue();
+ List<Number> ints = new ArrayList<Number>();
+ if (expr instanceof NumberExpression) {
+ NumberExpression ne = (NumberExpression) expr;
+ ints.add(ne.getIntegerValue(element.getParent()));
+ map.put(value, ints);
+ } else if (expr instanceof NumberListExpression) {
+ NumberListExpression ne = (NumberListExpression) expr;
+ map.put(value, ne.getList(element.getParent()));
+ }
+ }
+
+ TypeSystem typeSystem = stream.getCas().getTypeSystem();
+ JCas jcas = stream.getJCas();
+ 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());
+ List<Number> reIndexes = map.get(shortFName);
+ if (reIndexes != null && !reIndexes.isEmpty()) {
+ Type range = targetFeature.getRange();
+
+ List<RuleElementMatch> tms = getMatchInfo(match, reIndexes);
+ if (tms.size() == 0) {// do nothing
+
+ } else if (tms.size() == 1) {
+ RuleElementMatch tm = tms.get(0);
+ List<AnnotationFS> textsMatched = tm.getTextsMatched();
+ if (textsMatched.size() == 1) {
+ AnnotationFS fs = textsMatched.get(0);
+ if (typeSystem.subsumes(jcas.getCasType(FSArray.type), range)) {
+ List<AnnotationFS> list = new ArrayList<AnnotationFS>();
+ list.add(fs);
+ structure.setFeatureValue(targetFeature, UIMAUtils.toFSArray(jcas, list));
+ } else if (typeSystem.subsumes(range, fs.getType())) {
+ structure.setFeatureValue(targetFeature, fs);
+ }
+ }
+ } else {
+ List<AnnotationFS> textsMatched = getMatchedText(tms);
+ if (typeSystem.subsumes(jcas.getCasType(FSArray.type), range)) {
+ structure.setFeatureValue(targetFeature, UIMAUtils.toFSArray(jcas, textsMatched));
+ } else {
+ int begin = textsMatched.get(0).getBegin();
+ int end = textsMatched.get(textsMatched.size() - 1).getEnd();
+ TextMarkerFrame frame = new TextMarkerFrame(jcas, begin, end);
+ FSIterator<Annotation> iterator = jcas.getAnnotationIndex(range).iterator(frame);
+ AnnotationFS newA = null;
+ while (iterator.isValid()) {
+ Annotation a = iterator.get();
+ if (a.getBegin() == begin && a.getEnd() == end
+ && jcas.getTypeSystem().subsumes(range, a.getType())) {
+ newA = a;
+ } else if (a.getBegin() > begin || a.getEnd() < end) {
+ break;
+ }
+ iterator.moveToNext();
+ }
+ if (newA == null) {
+ newA = jcas.getCas().createAnnotation(range, begin, end);
+ }
+ structure.setFeatureValue(targetFeature, newA);
+ }
+ }
+ }
+ }
+ }
+
+ private List<AnnotationFS> getMatchedText(List<RuleElementMatch> tms) {
+ List<AnnotationFS> result = new ArrayList<AnnotationFS>();
+ for (RuleElementMatch each : tms) {
+ result.addAll(each.getTextsMatched());
+ }
+ return result;
+ }
+
+ private List<RuleElementMatch> getMatchInfo(RuleMatch match, List<Number> reIndexes) {
+ List<RuleElementMatch> result = new ArrayList<RuleElementMatch>();
+ List<RuleElement> elements = match.getRule().getElements();
+ for (Number eachNumber : reIndexes) {
+ int eachInt = eachNumber.intValue();
+ RuleElement ruleElement = elements.get(eachInt - 1);
+ if (ruleElement instanceof TextMarkerRuleElement) {
+ result.addAll(match.getMatchInfo((TextMarkerRuleElement) ruleElement));
+ }
+ }
+ return result;
+ }
+
+ // TODO refactor duplicate methods -> MarkAction
+ protected List<Integer> getIndexList(RuleMatch match, TextMarkerRuleElement element) {
+ List<Integer> indexList = new ArrayList<Integer>();
+ if (indexes == null || indexes.isEmpty()) {
+ int self = match.getRule().getElements().indexOf(element) + 1;
+ indexList.add(self);
+ return indexList;
+ }
+ int last = Integer.MAX_VALUE - 1;
+ for (NumberExpression each : indexes) {
+ 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;
+ }
+
+ public TypeExpression getStructureType() {
+ return structureType;
+ }
+
+ public Map<StringExpression, TextMarkerExpression> getFeatures() {
+ return features;
+ }
+
+ public List<NumberExpression> getIndexes() {
+ return indexes;
+ }
+}
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/GatherAction.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/GatherAction.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/GetAction.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/GetAction.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/GetAction.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/GetAction.java Fri Aug 12 10:44:04 2011
@@ -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.action;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.uima.textmarker.TextMarkerBlock;
+import org.apache.uima.textmarker.TextMarkerStream;
+import org.apache.uima.textmarker.expression.TextMarkerExpression;
+import org.apache.uima.textmarker.expression.list.ListExpression;
+import org.apache.uima.textmarker.expression.string.StringExpression;
+import org.apache.uima.textmarker.rule.RuleMatch;
+import org.apache.uima.textmarker.rule.TextMarkerRuleElement;
+import org.apache.uima.textmarker.visitor.InferenceCrowd;
+
+
+public class GetAction extends AbstractTextMarkerAction {
+
+ private ListExpression<TextMarkerExpression> listExpr;
+
+ private String var;
+
+ private StringExpression opExpr;
+
+ public GetAction(ListExpression<TextMarkerExpression> f, String string, StringExpression op) {
+ super();
+ this.listExpr = f;
+ this.var = string;
+ this.opExpr = op;
+ }
+
+ @Override
+ public void execute(RuleMatch match, TextMarkerRuleElement element, TextMarkerStream stream,
+ InferenceCrowd crowd) {
+ String op = opExpr.getStringValue(element.getParent());
+ List<TextMarkerExpression> list = listExpr.getList(element.getParent());
+ if ("dominant".equals(op)) {
+ element.getParent().getEnvironment().setVariableValue(var,
+ getDominant(list, element.getParent()));
+ }
+ }
+
+ private Object getDominant(List<TextMarkerExpression> list, TextMarkerBlock parent) {
+ List<Object> objs = new ArrayList<Object>();
+ List<Integer> counts = new ArrayList<Integer>();
+ for (Object each : list) {
+ Object value = each;// getValue(each, parent);
+ if (objs.contains(value)) {
+ int indexOf = objs.indexOf(value);
+ Integer i = counts.get(indexOf);
+ counts.set(indexOf, ++i);
+ } else {
+ counts.add(1);
+ objs.add(each);
+ }
+ }
+ Object dominant = null;
+ int dominantCount = -1;
+ int i = 0;
+ for (Object each : objs) {
+ int count = counts.get(i++);
+ if (count > dominantCount) {
+ dominantCount = count;
+ dominant = each;
+ }
+ }
+ return dominant;
+ }
+
+ public ListExpression<TextMarkerExpression> getListExpr() {
+ return listExpr;
+ }
+
+ public String getVar() {
+ return var;
+ }
+
+ public StringExpression getOpExpr() {
+ return opExpr;
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/GetAction.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/GetAction.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/GetFeatureAction.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/GetFeatureAction.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/GetFeatureAction.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/GetFeatureAction.java Fri Aug 12 10:44:04 2011
@@ -0,0 +1,94 @@
+/*
+ * 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.action;
+
+import org.apache.uima.cas.Feature;
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.textmarker.TextMarkerEnvironment;
+import org.apache.uima.textmarker.TextMarkerStream;
+import org.apache.uima.textmarker.expression.string.StringExpression;
+import org.apache.uima.textmarker.rule.RuleMatch;
+import org.apache.uima.textmarker.rule.TextMarkerRuleElement;
+import org.apache.uima.textmarker.visitor.InferenceCrowd;
+
+public class GetFeatureAction extends AbstractTextMarkerAction {
+
+ private StringExpression featureStringExpression;
+
+ private String variable;
+
+ public GetFeatureAction(StringExpression f, String variable) {
+ super();
+ this.featureStringExpression = f;
+ this.variable = variable;
+ }
+
+ @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 stringValue = featureStringExpression.getStringValue(element.getParent());
+ Feature featureByBaseName = type.getFeatureByBaseName(stringValue);
+ AnnotationFS expandAnchor = stream.expandAnchor(match.getFirstBasic(), type);
+ TextMarkerEnvironment environment = element.getParent().getEnvironment();
+
+ if (expandAnchor.getType().getFeatureByBaseName(stringValue) == null) {
+ System.out.println("Can't access feature " + stringValue
+ + ", because it's not defined in the matched type: " + expandAnchor.getType());
+ return;
+ }
+
+ if (environment.getVariableType(variable).equals(String.class)
+ && featureByBaseName.getRange().getName().equals("uima.cas.String")) {
+ Object value = expandAnchor.getStringValue(featureByBaseName);
+ environment.setVariableValue(variable, value);
+ } else if (environment.getVariableType(variable).equals(Integer.class)
+ && featureByBaseName.getRange().getName().equals("uima.cas.Integer")) {
+ Object value = expandAnchor.getIntValue(featureByBaseName);
+ environment.setVariableValue(variable, value);
+ } else if (environment.getVariableType(variable).equals(Double.class)
+ && featureByBaseName.getRange().getName().equals("uima.cas.Double")) {
+ Object value = expandAnchor.getDoubleValue(featureByBaseName);
+ environment.setVariableValue(variable, value);
+ } else if (environment.getVariableType(variable).equals(Boolean.class)
+ && featureByBaseName.getRange().getName().equals("uima.cas.Boolean")) {
+ Object value = expandAnchor.getBooleanValue(featureByBaseName);
+ environment.setVariableValue(variable, value);
+ } else if (environment.getVariableType(variable).equals(Type.class)
+ && featureByBaseName.getRange().getName().equals("uima.cas.String")) {
+ Object value = expandAnchor.getStringValue(featureByBaseName);
+ Type t = stream.getCas().getTypeSystem().getType((String) value);
+ if (t != null) {
+ environment.setVariableValue(variable, t);
+ }
+ }
+ }
+
+ public StringExpression getFeatureStringExpression() {
+ return featureStringExpression;
+ }
+
+ public String getVariable() {
+ return variable;
+ }
+}
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/GetFeatureAction.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/GetFeatureAction.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/GetListAction.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/GetListAction.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/GetListAction.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/GetListAction.java Fri Aug 12 10:44:04 2011
@@ -0,0 +1,92 @@
+/*
+ * 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.action;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.textmarker.TextMarkerStream;
+import org.apache.uima.textmarker.expression.string.StringExpression;
+import org.apache.uima.textmarker.rule.RuleMatch;
+import org.apache.uima.textmarker.rule.TextMarkerRuleElement;
+import org.apache.uima.textmarker.type.TextMarkerBasic;
+import org.apache.uima.textmarker.visitor.InferenceCrowd;
+
+public class GetListAction extends AbstractTextMarkerAction {
+
+ private static final String TYPES = "Types";
+
+ private static final String TYPES_AT_END = "Types:End";
+
+ private static final String TYPES_AT_BEGIN = "Types:Begin";
+
+ private String var;
+
+ private StringExpression opExpr;
+
+ public GetListAction(String var, StringExpression op) {
+ super();
+ this.var = var;
+ this.opExpr = op;
+ }
+
+ @Override
+ public void execute(RuleMatch match, TextMarkerRuleElement element, TextMarkerStream stream,
+ InferenceCrowd crowd) {
+ String op = opExpr.getStringValue(element.getParent());
+ List<Type> list = new ArrayList<Type>();
+ int indexOf = match.getRule().getElements().indexOf(element);
+ List<Integer> indexes = new ArrayList<Integer>();
+ indexes.add(indexOf + 1);
+ AnnotationFS matched = match.getMatchedAnnotation(stream, indexes);
+ TextMarkerBasic firstBasic = stream.getFirstBasicInWindow(matched);
+ Collection<AnnotationFS> anchors = firstBasic.getAnchors();
+ if (TYPES_AT_BEGIN.equals(op)) {
+ for (AnnotationFS each : anchors) {
+ list.add(each.getType());
+ }
+ } else {
+ Type annotationType = stream.getCas().getAnnotationType();
+ if (TYPES_AT_END.equals(op)) {
+ List<AnnotationFS> inWindow = stream.getAnnotationsInWindow(matched, annotationType);
+ for (AnnotationFS each : inWindow) {
+ if (each.getEnd() == matched.getEnd()) {
+ list.add(each.getType());
+ }
+ }
+ } else if (TYPES.equals(op)) {
+ List<AnnotationFS> inWindow = stream.getAnnotationsInWindow(matched, annotationType);
+ for (AnnotationFS each : inWindow) {
+ if (each.getBegin() == matched.getBegin() && each.getEnd() == matched.getEnd()) {
+ list.add(each.getType());
+ }
+ if (each.getBegin() > matched.getBegin() || each.getEnd() < matched.getEnd()) {
+ break;
+ }
+ }
+ }
+ }
+ element.getParent().getEnvironment().setVariableValue(var, list);
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/GetListAction.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/GetListAction.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/LogAction.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/LogAction.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/LogAction.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/LogAction.java Fri Aug 12 10:44:04 2011
@@ -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.action;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.uima.textmarker.TextMarkerStream;
+import org.apache.uima.textmarker.expression.string.StringExpression;
+import org.apache.uima.textmarker.rule.RuleMatch;
+import org.apache.uima.textmarker.rule.TextMarkerRuleElement;
+import org.apache.uima.textmarker.visitor.InferenceCrowd;
+
+
+public class LogAction extends AbstractTextMarkerAction {
+
+ public static final String LOGGER_NAME = Logger.GLOBAL_LOGGER_NAME;
+
+ private final StringExpression text;
+
+ private final Level level;
+
+ public LogAction(StringExpression text, Level level) {
+ super();
+ this.text = text;
+ this.level = level == null ? Level.INFO : level;
+ }
+
+ @Override
+ public void execute(RuleMatch match, TextMarkerRuleElement element, TextMarkerStream stream,
+ InferenceCrowd crowd) {
+ String msg = text.getStringValue(element.getParent());
+ Logger.getLogger(LOGGER_NAME).log(level, msg);
+ }
+
+ public StringExpression getText() {
+ return text;
+ }
+
+ public Level getLevel() {
+ return level;
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/LogAction.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/LogAction.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/MarkAction.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/MarkAction.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/MarkAction.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/MarkAction.java Fri Aug 12 10:44:04 2011
@@ -0,0 +1,126 @@
+/*
+ * 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.action;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.jcas.tcas.Annotation;
+import org.apache.uima.textmarker.TextMarkerStream;
+import org.apache.uima.textmarker.expression.number.NumberExpression;
+import org.apache.uima.textmarker.expression.type.TypeExpression;
+import org.apache.uima.textmarker.rule.RuleMatch;
+import org.apache.uima.textmarker.rule.TextMarkerRuleElement;
+import org.apache.uima.textmarker.type.TextMarkerAnnotation;
+import org.apache.uima.textmarker.type.TextMarkerBasic;
+import org.apache.uima.textmarker.visitor.InferenceCrowd;
+
+public class MarkAction extends AbstractMarkAction {
+
+ protected final NumberExpression score;
+
+ protected final List<NumberExpression> list;
+
+ public MarkAction(TypeExpression type, NumberExpression scoreValue, List<NumberExpression> list) {
+ super(type);
+ this.score = scoreValue;
+ 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);
+ if (matchedAnnotation == null) {
+ return;
+ }
+ if (score == null) {
+ createAnnotation(match, element, stream, matchedAnnotation);
+ } else {
+ double deltaScore = score.getDoubleValue(element.getParent());
+ updateHeuristicAnnotation(match, element, stream, matchedAnnotation, deltaScore);
+ }
+ }
+
+ protected void updateHeuristicAnnotation(RuleMatch match, TextMarkerRuleElement element,
+ TextMarkerStream stream, AnnotationFS matchedAnnotation, double deltaScore) {
+ Type heuristicType = stream.getJCas().getCasType(TextMarkerAnnotation.type);
+ TextMarkerAnnotation heuristicAnnotation = (TextMarkerAnnotation) stream.getCas()
+ .createAnnotation(heuristicType, matchedAnnotation.getBegin(),
+ matchedAnnotation.getEnd());
+ Annotation newAnnotation = (Annotation) stream.getCas().createAnnotation(
+ type.getType(element.getParent()), heuristicAnnotation.getBegin(),
+ heuristicAnnotation.getEnd());
+ heuristicAnnotation.setScore(deltaScore);
+ heuristicAnnotation.setAnnotation(newAnnotation);
+ List<AnnotationFS> annotationsInWindow = stream.getAnnotationsInWindow(heuristicAnnotation,
+ heuristicType);
+
+ if (annotationsInWindow.isEmpty()) {
+ heuristicAnnotation.addToIndexes();
+ newAnnotation.addToIndexes();
+ TextMarkerBasic first = stream.getFirstBasicInWindow(newAnnotation);
+ stream.addAnnotation(first, newAnnotation);
+ } else {
+ TextMarkerAnnotation tma = stream.getCorrectTMA(annotationsInWindow, heuristicAnnotation);
+ if (tma != null) {
+ tma.removeFromIndexes();
+ double newScore = tma.getScore() + deltaScore;
+ tma.setScore(newScore);
+ tma.addToIndexes();
+ } else {
+ heuristicAnnotation.addToIndexes();
+ newAnnotation.addToIndexes();
+ TextMarkerBasic first = stream.getFirstBasicInWindow(newAnnotation);
+ stream.addAnnotation(first, newAnnotation);
+ }
+ }
+
+ }
+
+ 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;
+ }
+
+ public NumberExpression getScore() {
+ return score;
+ }
+
+ public List<NumberExpression> getList() {
+ return list;
+ }
+}
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/MarkAction.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/MarkAction.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/MarkFastAction.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/MarkFastAction.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/MarkFastAction.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/MarkFastAction.java Fri Aug 12 10:44:04 2011
@@ -0,0 +1,94 @@
+/*
+ * 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.action;
+
+import java.util.Collection;
+
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.textmarker.TextMarkerStream;
+import org.apache.uima.textmarker.expression.bool.BooleanExpression;
+import org.apache.uima.textmarker.expression.bool.SimpleBooleanExpression;
+import org.apache.uima.textmarker.expression.number.NumberExpression;
+import org.apache.uima.textmarker.expression.number.SimpleNumberExpression;
+import org.apache.uima.textmarker.expression.resource.WordListExpression;
+import org.apache.uima.textmarker.expression.type.TypeExpression;
+import org.apache.uima.textmarker.resource.TextMarkerWordList;
+import org.apache.uima.textmarker.resource.TreeWordList;
+import org.apache.uima.textmarker.rule.RuleMatch;
+import org.apache.uima.textmarker.rule.TextMarkerRuleElement;
+import org.apache.uima.textmarker.type.TextMarkerBasic;
+import org.apache.uima.textmarker.visitor.InferenceCrowd;
+
+
+public class MarkFastAction extends AbstractMarkAction {
+
+ private WordListExpression list;
+
+ private BooleanExpression ignore;
+
+ private NumberExpression ignoreLength;
+
+ public MarkFastAction(TypeExpression type, WordListExpression list, BooleanExpression ignore,
+ NumberExpression ignoreLength) {
+ super(type);
+ this.list = list;
+ this.ignore = ignore == null ? new SimpleBooleanExpression(false) : ignore;
+ this.ignoreLength = ignoreLength == null ? new SimpleNumberExpression(Integer.valueOf(0))
+ : ignoreLength;
+ }
+
+ @Override
+ public void execute(RuleMatch match, TextMarkerRuleElement element, TextMarkerStream stream,
+ InferenceCrowd crowd) {
+ // Annotation matchedAnnotation = match.getMatchedAnnotation(stream,
+ // null);
+ // TODO matched annotation is Document!!! HOTFIX
+ TextMarkerWordList wl = list.getList(element.getParent());
+ if (wl instanceof TreeWordList) {
+ Collection<AnnotationFS> found = wl.find(stream, ignore.getBooleanValue(element.getParent()),
+ ignoreLength.getIntegerValue(element.getParent()), null, 0);
+ for (AnnotationFS annotation : found) {
+ TextMarkerBasic anchor = stream.getFirstBasicInWindow(annotation);
+ createAnnotation(anchor, element, stream, annotation);
+ }
+ }
+ // if(list.contains(matchedAnnotation.getCoveredText(), ignore, 0)) {
+ // createAnnotation(match, stream, matchedAnnotation);
+ // } else {
+ // List<TextMarkerBasic> annotationsInWindow =
+ // stream.getBasicAnnotationsInWindow(matchedAnnotation,
+ // TextMarkerBasic.class);
+ // for (TextMarkerBasic textMarkerBasic : annotationsInWindow) {
+ // if(list.contains(textMarkerBasic.getCoveredText(), ignore, 0)) {
+ // createAnnotation(match, stream, textMarkerBasic);
+ // }
+ // }
+ // }
+ }
+
+ public WordListExpression getList() {
+ return list;
+ }
+
+ public BooleanExpression isIgnore() {
+ return ignore;
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/MarkFastAction.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/MarkFastAction.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/MarkLastAction.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/MarkLastAction.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/MarkLastAction.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/MarkLastAction.java Fri Aug 12 10:44:04 2011
@@ -0,0 +1,50 @@
+/*
+ * 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.action;
+
+import java.util.List;
+
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.textmarker.TextMarkerStream;
+import org.apache.uima.textmarker.expression.type.TypeExpression;
+import org.apache.uima.textmarker.rule.RuleMatch;
+import org.apache.uima.textmarker.rule.TextMarkerRuleElement;
+import org.apache.uima.textmarker.type.TextMarkerBasic;
+import org.apache.uima.textmarker.visitor.InferenceCrowd;
+
+
+public class MarkLastAction extends AbstractMarkAction {
+
+ public MarkLastAction(TypeExpression type) {
+ super(type);
+ }
+
+ @Override
+ public void execute(RuleMatch match, TextMarkerRuleElement element, TextMarkerStream stream,
+ InferenceCrowd crowd) {
+ AnnotationFS matchedAnnotation = match.getMatchedAnnotation(stream, null);
+ List<TextMarkerBasic> list = stream.getBasicsInWindow(matchedAnnotation);
+ if (!list.isEmpty()) {
+ TextMarkerBasic last = list.get(list.size() - 1);
+ createAnnotation(last, element, stream, last);
+ }
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/MarkLastAction.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/MarkLastAction.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/MarkOnceAction.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/MarkOnceAction.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/MarkOnceAction.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/MarkOnceAction.java Fri Aug 12 10:44:04 2011
@@ -0,0 +1,70 @@
+/*
+ * 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.action;
+
+import java.util.List;
+
+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.textmarker.TextMarkerStream;
+import org.apache.uima.textmarker.expression.number.NumberExpression;
+import org.apache.uima.textmarker.expression.type.TypeExpression;
+import org.apache.uima.textmarker.rule.RuleMatch;
+import org.apache.uima.textmarker.rule.TextMarkerRuleElement;
+import org.apache.uima.textmarker.visitor.InferenceCrowd;
+
+public class MarkOnceAction extends MarkAction {
+
+ public MarkOnceAction(TypeExpression type, NumberExpression scoreValue,
+ List<NumberExpression> list) {
+ super(type, scoreValue, 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);
+ CAS cas = stream.getCas();
+ if (matchedAnnotation == null)
+ return;
+ Type t = type.getType(element.getParent());
+ AnnotationFS createAnnotation = cas.createAnnotation(t, matchedAnnotation.getBegin(),
+ matchedAnnotation.getEnd());
+ boolean contains = false;
+ FSIterator<AnnotationFS> iterator = cas.getAnnotationIndex(t).iterator(createAnnotation);
+ while (iterator.isValid()
+ && ((AnnotationFS) iterator.get()).getEnd() == createAnnotation.getEnd()) {
+ AnnotationFS a = (AnnotationFS) iterator.get();
+ if (a.getBegin() == createAnnotation.getBegin() && a.getEnd() == createAnnotation.getEnd()
+ && a.getType().getName().equals(createAnnotation.getType().getName())) {
+ contains = true;
+ break;
+ }
+ iterator.moveToNext();
+ }
+ if (!contains) {
+ super.execute(match, element, stream, crowd);
+ }
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/MarkOnceAction.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/MarkOnceAction.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/MarkTableAction.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/MarkTableAction.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/MarkTableAction.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/MarkTableAction.java Fri Aug 12 10:44:04 2011
@@ -0,0 +1,128 @@
+/*
+ * 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.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.textmarker.TextMarkerBlock;
+import org.apache.uima.textmarker.TextMarkerStream;
+import org.apache.uima.textmarker.expression.number.NumberExpression;
+import org.apache.uima.textmarker.expression.resource.WordTableExpression;
+import org.apache.uima.textmarker.expression.string.StringExpression;
+import org.apache.uima.textmarker.expression.type.TypeExpression;
+import org.apache.uima.textmarker.resource.TextMarkerTable;
+import org.apache.uima.textmarker.resource.TextMarkerWordList;
+import org.apache.uima.textmarker.rule.RuleMatch;
+import org.apache.uima.textmarker.rule.TextMarkerRuleElement;
+import org.apache.uima.textmarker.type.TextMarkerBasic;
+import org.apache.uima.textmarker.visitor.InferenceCrowd;
+
+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/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/MarkTableAction.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/MarkTableAction.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/MatchedTextAction.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/MatchedTextAction.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/MatchedTextAction.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/MatchedTextAction.java Fri Aug 12 10:44:04 2011
@@ -0,0 +1,78 @@
+/*
+ * 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.action;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.textmarker.TextMarkerStream;
+import org.apache.uima.textmarker.expression.number.NumberExpression;
+import org.apache.uima.textmarker.rule.RuleMatch;
+import org.apache.uima.textmarker.rule.TextMarkerRuleElement;
+import org.apache.uima.textmarker.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/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/MatchedTextAction.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/MatchedTextAction.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/MergeAction.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/MergeAction.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/MergeAction.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/MergeAction.java Fri Aug 12 10:44:04 2011
@@ -0,0 +1,87 @@
+/*
+ * 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.action;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.collections.ListUtils;
+import org.apache.uima.textmarker.TextMarkerStream;
+import org.apache.uima.textmarker.expression.bool.BooleanExpression;
+import org.apache.uima.textmarker.expression.list.ListExpression;
+import org.apache.uima.textmarker.rule.RuleMatch;
+import org.apache.uima.textmarker.rule.TextMarkerRuleElement;
+import org.apache.uima.textmarker.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/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/MergeAction.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/MergeAction.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/RemoveAction.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/RemoveAction.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/RemoveAction.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/RemoveAction.java Fri Aug 12 10:44:04 2011
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+*/
+
+package org.apache.uima.textmarker.action;
+
+import java.util.List;
+
+import org.apache.uima.textmarker.TextMarkerStream;
+import org.apache.uima.textmarker.expression.TextMarkerExpression;
+import org.apache.uima.textmarker.expression.list.ListExpression;
+import org.apache.uima.textmarker.rule.RuleMatch;
+import org.apache.uima.textmarker.rule.TextMarkerRuleElement;
+import org.apache.uima.textmarker.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/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/RemoveAction.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/RemoveAction.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/RemoveDuplicateAction.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/RemoveDuplicateAction.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/RemoveDuplicateAction.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/RemoveDuplicateAction.java Fri Aug 12 10:44:04 2011
@@ -0,0 +1,55 @@
+/*
+ * 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.action;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.uima.textmarker.TextMarkerStream;
+import org.apache.uima.textmarker.rule.RuleMatch;
+import org.apache.uima.textmarker.rule.TextMarkerRuleElement;
+import org.apache.uima.textmarker.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/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/RemoveDuplicateAction.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/action/RemoveDuplicateAction.java
------------------------------------------------------------------------------
svn:mime-type = text/plain