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 [6/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/condition/CurrentCountCondition.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/CurrentCountCondition.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/CurrentCountCondition.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/CurrentCountCondition.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.condition;
+
+import java.util.Iterator;
+
+import org.apache.uima.cas.Type;
+import org.apache.uima.textmarker.TextMarkerStream;
+import org.apache.uima.textmarker.expression.number.NumberExpression;
+import org.apache.uima.textmarker.expression.number.SimpleNumberExpression;
+import org.apache.uima.textmarker.expression.type.TypeExpression;
+import org.apache.uima.textmarker.rule.EvaluatedCondition;
+import org.apache.uima.textmarker.rule.TextMarkerRuleElement;
+import org.apache.uima.textmarker.type.TextMarkerBasic;
+import org.apache.uima.textmarker.visitor.InferenceCrowd;
+
+public class CurrentCountCondition extends TypeSentiveCondition {
+ private final NumberExpression min;
+
+ private final NumberExpression max;
+
+ private final String var;
+
+ public CurrentCountCondition(TypeExpression type, NumberExpression min, NumberExpression max,
+ String var) {
+ super(type);
+ this.min = min == null ? new SimpleNumberExpression(Integer.MIN_VALUE) : min;
+ this.max = max == null ? new SimpleNumberExpression(Integer.MAX_VALUE) : max;
+ this.var = var;
+ }
+
+ @Override
+ public EvaluatedCondition eval(TextMarkerBasic annotation, Type matchedType,
+ TextMarkerRuleElement element, TextMarkerStream stream, InferenceCrowd crowd) {
+ int count = 0;
+ Iterator<?> it = stream.getJCas().getAnnotationIndex(type.getType(element.getParent()))
+ .iterator();
+ while (it.hasNext()) {
+ it.next();
+ count++;
+ }
+ if (var != null) {
+ element.getParent().getEnvironment().setVariableValue(var, count);
+ }
+ boolean value = count >= min.getIntegerValue(element.getParent())
+ && count <= max.getIntegerValue(element.getParent());
+ return new EvaluatedCondition(this, value);
+ }
+
+ public NumberExpression getMin() {
+ return min;
+ }
+
+ public NumberExpression getMax() {
+ return max;
+ }
+
+ public String getVar() {
+ return var;
+ }
+}
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/CurrentCountCondition.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/CurrentCountCondition.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/EndsWithCondition.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/EndsWithCondition.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/EndsWithCondition.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/EndsWithCondition.java Fri Aug 12 10:44:04 2011
@@ -0,0 +1,110 @@
+/*
+ * 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.condition;
+
+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.list.TypeListExpression;
+import org.apache.uima.textmarker.expression.type.TypeExpression;
+import org.apache.uima.textmarker.rule.EvaluatedCondition;
+import org.apache.uima.textmarker.rule.TextMarkerRuleElement;
+import org.apache.uima.textmarker.type.TextMarkerBasic;
+import org.apache.uima.textmarker.visitor.InferenceCrowd;
+
+public class EndsWithCondition extends TypeSentiveCondition {
+
+ public EndsWithCondition(TypeExpression type) {
+ super(type);
+ }
+
+ public EndsWithCondition(TypeListExpression list) {
+ super(list);
+ }
+
+ @Override
+ public EvaluatedCondition eval(TextMarkerBasic basic, Type matchedType,
+ TextMarkerRuleElement element, TextMarkerStream stream, InferenceCrowd crowd) {
+ AnnotationFS matched = basic.getType(matchedType.getName());
+ if (!isWorkingOnList()) {
+ Type givenType = type.getType(element.getParent());
+ boolean result = check(stream, matched, givenType);
+ return new EvaluatedCondition(this, result);
+ } else {
+ boolean result = false;
+ List<Type> types = getList().getList(element.getParent());
+ for (Type t : types) {
+ result |= check(stream, matched, t);
+ if (result) {
+ break;
+ }
+ }
+ return new EvaluatedCondition(this, result);
+ }
+ }
+
+ private boolean check(TextMarkerStream stream, AnnotationFS matched, Type givenType) {
+ boolean result = false;
+ // List<AnnotationFS> inWindow = stream.getAnnotationsInWindow(matched, givenType);
+ // for (AnnotationFS annotationFS : inWindow) {
+ // if (annotationFS.getEnd() == matched.getEnd()) {
+ // result = true;
+ // break;
+ // }
+ // }
+ // TODO rewrite the code above
+ // check annotations that start before
+ if (!result) {
+ List<TextMarkerBasic> basicsInWindow = stream.getBasicsInWindow(matched);
+ if (!basicsInWindow.isEmpty()) {
+ TextMarkerBasic last = basicsInWindow.get(basicsInWindow.size() - 1);
+ if (last.isPartOf(givenType.getName())) {
+ // there is something
+ if (last.isAnchorOf(givenType.getName())) {
+ int end = last.getType(givenType.getName()).getEnd();
+ if (end == matched.getEnd()) {
+ return true;
+ }
+ } else {
+ stream.moveTo(last);
+ while (stream.isValid()) {
+ AnnotationFS fs = stream.get();
+ if (fs instanceof TextMarkerBasic) {
+ TextMarkerBasic b = (TextMarkerBasic) fs;
+ if (b.isAnchorOf(givenType.getName())) {
+ int end = b.getType(givenType.getName()).getEnd();
+ if (end == matched.getEnd()) {
+ return true;
+ }
+ }
+ }
+ stream.moveToPrevious();
+ }
+ }
+ }
+
+ }
+ }
+ return result;
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/EndsWithCondition.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/EndsWithCondition.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/FeatureCondition.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/FeatureCondition.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/FeatureCondition.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/FeatureCondition.java Fri Aug 12 10:44:04 2011
@@ -0,0 +1,131 @@
+/*
+ * 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.condition;
+
+import org.apache.uima.cas.Feature;
+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.bool.BooleanExpression;
+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.EvaluatedCondition;
+import org.apache.uima.textmarker.rule.TextMarkerRuleElement;
+import org.apache.uima.textmarker.type.TextMarkerBasic;
+import org.apache.uima.textmarker.visitor.InferenceCrowd;
+
+public class FeatureCondition extends AbstractTextMarkerCondition {
+
+ private final StringExpression featureStringExpression;
+
+ private StringExpression stringExpr;
+
+ private NumberExpression numberExpr;
+
+ private BooleanExpression booleanExpr;
+
+ private TypeExpression typeExpr;
+
+ protected FeatureCondition(StringExpression feature) {
+ super();
+ this.featureStringExpression = feature;
+ }
+
+ public FeatureCondition(StringExpression feature, StringExpression stringExpr) {
+ this(feature);
+ this.stringExpr = stringExpr;
+ }
+
+ public FeatureCondition(StringExpression feature, NumberExpression numberExpr) {
+ this(feature);
+ this.numberExpr = numberExpr;
+ }
+
+ public FeatureCondition(StringExpression feature, BooleanExpression booleanExpr) {
+ this(feature);
+ this.booleanExpr = booleanExpr;
+ }
+
+ public FeatureCondition(StringExpression feature, TypeExpression typeExpr, String variable) {
+ this(feature);
+ this.typeExpr = typeExpr;
+ }
+
+ @Override
+ public EvaluatedCondition eval(TextMarkerBasic basic, Type matchedType,
+ TextMarkerRuleElement element, TextMarkerStream stream, InferenceCrowd crowd) {
+ String stringValue = featureStringExpression.getStringValue(element.getParent());
+ Feature featureByBaseName = matchedType.getFeatureByBaseName(stringValue);
+ AnnotationFS expandAnchor = stream.expandAnchor(basic, matchedType);
+
+ if (stringExpr != null) {
+ String value = expandAnchor.getStringValue(featureByBaseName);
+ String string = stringExpr.getStringValue(element.getParent());
+ boolean result = string != null && string.equals(value);
+ return new EvaluatedCondition(this, result);
+ } else if (numberExpr != null) {
+ String range = featureByBaseName.getRange().getName();
+ boolean result = false;
+ if (range.equals("uima.cas.Integer")) {
+ int value = expandAnchor.getIntValue(featureByBaseName);
+ int v = numberExpr.getIntegerValue(element.getParent());
+ result = value == v;
+ } else if (range.equals("uima.cas.Double")) {
+ double value = expandAnchor.getDoubleValue(featureByBaseName);
+ double v = numberExpr.getDoubleValue(element.getParent());
+ result = value == v;
+ }
+ return new EvaluatedCondition(this, result);
+ } else if (booleanExpr != null) {
+ boolean value = expandAnchor.getBooleanValue(featureByBaseName);
+ boolean v = booleanExpr.getBooleanValue(element.getParent());
+ boolean result = value == v;
+ return new EvaluatedCondition(this, result);
+ } else if (typeExpr != null) {
+ // String value = expandAnchor.getStringValue(featureByBaseName);
+ // String string = stringExpr.getStringValue(element.getParent());
+ // boolean result = string != null && string.equals(value);
+ // return new EvaluatedCondition(this, result);
+ }
+ return new EvaluatedCondition(this, false);
+ }
+
+ public StringExpression getFeatureStringExpression() {
+ return featureStringExpression;
+ }
+
+ public StringExpression getStringExpr() {
+ return stringExpr;
+ }
+
+ public NumberExpression getNumberExpr() {
+ return numberExpr;
+ }
+
+ public BooleanExpression getBooleanExpr() {
+ return booleanExpr;
+ }
+
+ public TypeExpression getTypeExpr() {
+ return typeExpr;
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/FeatureCondition.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/FeatureCondition.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/IfCondition.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/IfCondition.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/IfCondition.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/IfCondition.java Fri Aug 12 10:44:04 2011
@@ -0,0 +1,49 @@
+/*
+ * 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.condition;
+
+import org.apache.uima.cas.Type;
+import org.apache.uima.textmarker.TextMarkerStream;
+import org.apache.uima.textmarker.expression.bool.BooleanExpression;
+import org.apache.uima.textmarker.rule.EvaluatedCondition;
+import org.apache.uima.textmarker.rule.TextMarkerRuleElement;
+import org.apache.uima.textmarker.type.TextMarkerBasic;
+import org.apache.uima.textmarker.visitor.InferenceCrowd;
+
+public class IfCondition extends AbstractTextMarkerCondition {
+
+ private final BooleanExpression expression;
+
+ public IfCondition(BooleanExpression e) {
+ super();
+ this.expression = e;
+ }
+
+ @Override
+ public EvaluatedCondition eval(TextMarkerBasic basic, Type matchedType,
+ TextMarkerRuleElement element, TextMarkerStream stream, InferenceCrowd crowd) {
+ return new EvaluatedCondition(this, expression.getBooleanValue(element.getParent()));
+ }
+
+ public BooleanExpression getExpression() {
+ return expression;
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/IfCondition.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/IfCondition.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/InListCondition.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/InListCondition.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/InListCondition.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/InListCondition.java Fri Aug 12 10:44:04 2011
@@ -0,0 +1,93 @@
+/*
+ * 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.condition;
+
+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.bool.BooleanExpression;
+import org.apache.uima.textmarker.expression.list.StringListExpression;
+import org.apache.uima.textmarker.expression.number.NumberExpression;
+import org.apache.uima.textmarker.expression.resource.WordListExpression;
+import org.apache.uima.textmarker.resource.TextMarkerWordList;
+import org.apache.uima.textmarker.rule.EvaluatedCondition;
+import org.apache.uima.textmarker.rule.TextMarkerRuleElement;
+import org.apache.uima.textmarker.type.TextMarkerBasic;
+import org.apache.uima.textmarker.visitor.InferenceCrowd;
+
+public class InListCondition extends TerminalTextMarkerCondition {
+
+ private BooleanExpression relative;
+
+ private final NumberExpression distance;
+
+ private WordListExpression listExpr;
+
+ private StringListExpression stringList;
+
+ public InListCondition(WordListExpression listExpr, NumberExpression distance,
+ BooleanExpression relative) {
+ super();
+ this.listExpr = listExpr;
+ this.distance = distance;
+ this.relative = relative;
+ }
+
+ public InListCondition(StringListExpression list, NumberExpression distance,
+ BooleanExpression relative) {
+ super();
+ this.distance = distance;
+ this.relative = relative;
+ this.stringList = list;
+ }
+
+ @Override
+ public EvaluatedCondition eval(TextMarkerBasic annotation, Type matchedType,
+ TextMarkerRuleElement element, TextMarkerStream stream, InferenceCrowd crowd) {
+ AnnotationFS matchedAnnotation = stream.expandAnchor(annotation, matchedType);
+ String coveredText = matchedAnnotation.getCoveredText();
+ if (stringList == null) {
+ TextMarkerWordList wordList = listExpr.getList(element.getParent());
+ return new EvaluatedCondition(this, wordList.contains(coveredText, false, 0, null, 0));
+ }
+ List<String> sList = stringList.getList(element.getParent());
+ boolean contains = sList.contains(coveredText);
+ return new EvaluatedCondition(this, contains);
+ }
+
+ public BooleanExpression getRelative() {
+ return relative;
+ }
+
+ public NumberExpression getDistance() {
+ return distance;
+ }
+
+ public WordListExpression getListExpression() {
+ return listExpr;
+ }
+
+ public StringListExpression getStringList() {
+ return stringList;
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/InListCondition.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/InListCondition.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/IsCondition.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/IsCondition.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/IsCondition.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/IsCondition.java Fri Aug 12 10:44:04 2011
@@ -0,0 +1,74 @@
+/*
+ * 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.condition;
+
+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.list.TypeListExpression;
+import org.apache.uima.textmarker.expression.type.TypeExpression;
+import org.apache.uima.textmarker.rule.EvaluatedCondition;
+import org.apache.uima.textmarker.rule.TextMarkerRuleElement;
+import org.apache.uima.textmarker.type.TextMarkerBasic;
+import org.apache.uima.textmarker.visitor.InferenceCrowd;
+
+public class IsCondition extends TypeSentiveCondition {
+
+ public IsCondition(TypeExpression type) {
+ super(type);
+ }
+
+ public IsCondition(TypeListExpression list) {
+ super(list);
+ }
+
+ @Override
+ public EvaluatedCondition eval(TextMarkerBasic basic, Type matchedType,
+ TextMarkerRuleElement element, TextMarkerStream stream, InferenceCrowd crowd) {
+ AnnotationFS a1 = basic.getType(matchedType.getName());
+ if (!isWorkingOnList()) {
+ AnnotationFS a2 = basic.getType(type.getType(element.getParent()).getName());
+ boolean result = check(a1, a2);
+ return new EvaluatedCondition(this, result);
+ } else {
+ boolean result = false;
+ List<Type> types = getList().getList(element.getParent());
+ for (Type type : types) {
+ AnnotationFS a2 = basic.getType(type.getName());
+ result |= check(a1, a2);
+ if (result == true) {
+ break;
+ }
+ }
+ return new EvaluatedCondition(this, result);
+ }
+ }
+
+ private boolean check(AnnotationFS a1, AnnotationFS a2) {
+ boolean result = false;
+ if (a1 != null && a2 != null && a1.getBegin() == a2.getBegin() && a1.getEnd() == a2.getEnd()) {
+ result = true;
+ }
+ return result;
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/IsCondition.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/IsCondition.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/IsInTagCondition.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/IsInTagCondition.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/IsInTagCondition.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/IsInTagCondition.java Fri Aug 12 10:44:04 2011
@@ -0,0 +1,74 @@
+/*
+ * 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.condition;
+
+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.textmarker.TextMarkerStream;
+import org.apache.uima.textmarker.expression.string.StringExpression;
+import org.apache.uima.textmarker.rule.EvaluatedCondition;
+import org.apache.uima.textmarker.rule.TextMarkerRuleElement;
+import org.apache.uima.textmarker.type.TextMarkerBasic;
+import org.apache.uima.textmarker.visitor.InferenceCrowd;
+
+public class IsInTagCondition extends TerminalTextMarkerCondition {
+
+ private final StringExpression tag;
+
+ private final List<StringExpression> tags;
+
+ private final List<StringExpression> values;
+
+ public IsInTagCondition(StringExpression tag, List<StringExpression> tags,
+ List<StringExpression> values) {
+ super();
+ this.tag = tag;
+ this.tags = tags;
+ this.values = values;
+ }
+
+ @Override
+ public EvaluatedCondition eval(TextMarkerBasic basic, Type matchedType,
+ TextMarkerRuleElement element, TextMarkerStream stream, InferenceCrowd crowd) {
+ boolean result = true;
+ AnnotationFS annotation = stream.expandAnchor(basic, matchedType);
+ for (TextMarkerBasic each : stream.getBasicsInWindow(annotation)) {
+ Map<String, String> tags = each.getTags();
+ result &= tags.containsKey(tag.getStringValue(element.getParent()));
+ }
+ return new EvaluatedCondition(this, result);
+ }
+
+ public StringExpression getTag() {
+ return tag;
+ }
+
+ public List<StringExpression> getTags() {
+ return tags;
+ }
+
+ public List<StringExpression> getValues() {
+ return values;
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/IsInTagCondition.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/IsInTagCondition.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/LastCondition.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/LastCondition.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/LastCondition.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/LastCondition.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.condition;
+
+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.type.TypeExpression;
+import org.apache.uima.textmarker.rule.EvaluatedCondition;
+import org.apache.uima.textmarker.rule.TextMarkerRuleElement;
+import org.apache.uima.textmarker.type.TextMarkerBasic;
+import org.apache.uima.textmarker.visitor.InferenceCrowd;
+
+public class LastCondition extends TypeSentiveCondition {
+
+ public LastCondition(TypeExpression type) {
+ super(type);
+ }
+
+ @Override
+ public EvaluatedCondition eval(TextMarkerBasic basic, Type matchedType,
+ TextMarkerRuleElement element, TextMarkerStream stream, InferenceCrowd crowd) {
+ AnnotationFS expand = stream.expandAnchor(basic, matchedType);
+ List<TextMarkerBasic> annotationsInWindow = stream.getBasicsInWindow(expand);
+ TextMarkerBasic textMarkerBasic = annotationsInWindow.get(annotationsInWindow.size() - 1);
+ boolean subsumes = stream.getJCas().getTypeSystem()
+ .subsumes(type.getType(element.getParent()), textMarkerBasic.getType());
+ return new EvaluatedCondition(this, subsumes);
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/LastCondition.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/LastCondition.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/MOfNCondition.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/MOfNCondition.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/MOfNCondition.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/MOfNCondition.java Fri Aug 12 10:44:04 2011
@@ -0,0 +1,72 @@
+/*
+ * 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.condition;
+
+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.number.NumberExpression;
+import org.apache.uima.textmarker.rule.EvaluatedCondition;
+import org.apache.uima.textmarker.rule.TextMarkerRuleElement;
+import org.apache.uima.textmarker.type.TextMarkerBasic;
+import org.apache.uima.textmarker.visitor.InferenceCrowd;
+
+public class MOfNCondition extends ComposedTextMarkerCondition {
+
+ private final NumberExpression min;
+
+ private final NumberExpression max;
+
+ public MOfNCondition(List<AbstractTextMarkerCondition> conditions, NumberExpression min,
+ NumberExpression max) {
+ super(conditions);
+ this.min = min;
+ this.max = max;
+ }
+
+ @Override
+ public EvaluatedCondition eval(TextMarkerBasic basic, Type matchedType,
+ TextMarkerRuleElement element, TextMarkerStream stream, InferenceCrowd crowd) {
+ int result = 0;
+ List<EvaluatedCondition> evals = new ArrayList<EvaluatedCondition>();
+ for (AbstractTextMarkerCondition each : conditions) {
+ crowd.beginVisit(each, null);
+ EvaluatedCondition eval = each.eval(basic, matchedType, element, stream, crowd);
+ crowd.endVisit(each, null);
+ evals.add(eval);
+ if (eval.isValue()) {
+ result++;
+ }
+ }
+ boolean value = result >= min.getIntegerValue(element.getParent())
+ && result <= max.getIntegerValue(element.getParent());
+ return new EvaluatedCondition(this, value, evals);
+ }
+
+ public NumberExpression getMin() {
+ return min;
+ }
+
+ public NumberExpression getMax() {
+ return max;
+ }
+}
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/MOfNCondition.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/MOfNCondition.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/NearCondition.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/NearCondition.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/NearCondition.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/NearCondition.java Fri Aug 12 10:44:04 2011
@@ -0,0 +1,98 @@
+/*
+ * 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.condition;
+
+import org.apache.uima.cas.FSIterator;
+import org.apache.uima.cas.FeatureStructure;
+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.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.type.TypeExpression;
+import org.apache.uima.textmarker.rule.EvaluatedCondition;
+import org.apache.uima.textmarker.rule.TextMarkerRuleElement;
+import org.apache.uima.textmarker.type.TextMarkerBasic;
+import org.apache.uima.textmarker.visitor.InferenceCrowd;
+
+public class NearCondition extends TypeSentiveCondition {
+
+ private final NumberExpression min;
+
+ private final NumberExpression max;
+
+ private final BooleanExpression forward;
+
+ private final BooleanExpression filtered;
+
+ public NearCondition(TypeExpression type, NumberExpression min, NumberExpression max,
+ BooleanExpression forward, BooleanExpression filtered) {
+ super(type);
+ this.min = min == null ? new SimpleNumberExpression(1) : min;
+ this.max = max == null ? new SimpleNumberExpression(1) : max;
+ this.forward = forward == null ? new SimpleBooleanExpression(true) : forward;
+ this.filtered = filtered == null ? new SimpleBooleanExpression(false) : filtered;
+ }
+
+ @Override
+ public EvaluatedCondition eval(TextMarkerBasic basic, Type matchedType,
+ TextMarkerRuleElement element, TextMarkerStream stream, InferenceCrowd crowd) {
+ FSIterator<AnnotationFS> it = filtered.getBooleanValue(element.getParent()) ? stream : stream
+ .getUnfilteredBasicIterator();
+ it.moveTo(basic);
+ int count = 0;
+ while (count <= max.getIntegerValue(element.getParent())) {
+ if (count >= min.getIntegerValue(element.getParent()) && it.isValid()) {
+ FeatureStructure featureStructure = it.get();
+ if (featureStructure instanceof TextMarkerBasic) {
+ TextMarkerBasic each = (TextMarkerBasic) featureStructure;
+ if (each.isPartOf(type.getType(element.getParent()).getName())) {
+ return new EvaluatedCondition(this, true);
+ }
+ }
+ }
+ if (forward.getBooleanValue(element.getParent())) {
+ it.moveToNext();
+ } else {
+ it.moveToPrevious();
+ }
+ count++;
+ }
+ return new EvaluatedCondition(this, false);
+ }
+
+ public NumberExpression getMin() {
+ return min;
+ }
+
+ public NumberExpression getMax() {
+ return max;
+ }
+
+ public BooleanExpression getForward() {
+ return forward;
+ }
+
+ public BooleanExpression getFiltered() {
+ return filtered;
+ }
+}
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/NearCondition.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/NearCondition.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/NotCondition.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/NotCondition.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/NotCondition.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/NotCondition.java Fri Aug 12 10:44:04 2011
@@ -0,0 +1,45 @@
+/*
+ * 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.condition;
+
+import org.apache.uima.cas.Type;
+import org.apache.uima.textmarker.TextMarkerStream;
+import org.apache.uima.textmarker.rule.EvaluatedCondition;
+import org.apache.uima.textmarker.rule.TextMarkerRuleElement;
+import org.apache.uima.textmarker.type.TextMarkerBasic;
+import org.apache.uima.textmarker.visitor.InferenceCrowd;
+
+public class NotCondition extends ComposedTextMarkerCondition {
+
+ public NotCondition(AbstractTextMarkerCondition condition) {
+ super(condition);
+ }
+
+ @Override
+ public EvaluatedCondition eval(TextMarkerBasic annotation, Type matchedType,
+ TextMarkerRuleElement element, TextMarkerStream stream, InferenceCrowd crowd) {
+ AbstractTextMarkerCondition cond = conditions.get(0);
+ crowd.beginVisit(cond, null);
+ EvaluatedCondition eval = cond.eval(annotation, matchedType, element, stream, crowd);
+ crowd.endVisit(cond, null);
+ return new EvaluatedCondition(this, !eval.isValue(), eval);
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/NotCondition.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/NotCondition.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/OrCondition.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/OrCondition.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/OrCondition.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/OrCondition.java Fri Aug 12 10:44:04 2011
@@ -0,0 +1,52 @@
+/*
+ * 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.condition;
+
+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.rule.EvaluatedCondition;
+import org.apache.uima.textmarker.rule.TextMarkerRuleElement;
+import org.apache.uima.textmarker.type.TextMarkerBasic;
+import org.apache.uima.textmarker.visitor.InferenceCrowd;
+
+public class OrCondition extends ComposedTextMarkerCondition {
+ public OrCondition(List<AbstractTextMarkerCondition> conditions) {
+ super(conditions);
+ }
+
+ @Override
+ public EvaluatedCondition eval(TextMarkerBasic currentSymbol, Type matchedType,
+ TextMarkerRuleElement element, TextMarkerStream symbolStream, InferenceCrowd crowd) {
+ boolean result = false;
+ List<EvaluatedCondition> evals = new ArrayList<EvaluatedCondition>();
+ for (AbstractTextMarkerCondition each : conditions) {
+ crowd.beginVisit(each, null);
+ EvaluatedCondition eval = each.eval(currentSymbol, matchedType, element, symbolStream, crowd);
+ crowd.endVisit(each, null);
+ result |= eval.isValue();
+ evals.add(eval);
+ }
+ return new EvaluatedCondition(this, result, evals);
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/OrCondition.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/OrCondition.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/ParseCondition.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/ParseCondition.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/ParseCondition.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/ParseCondition.java Fri Aug 12 10:44:04 2011
@@ -0,0 +1,88 @@
+/*
+ * 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.condition;
+
+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.rule.EvaluatedCondition;
+import org.apache.uima.textmarker.rule.TextMarkerRuleElement;
+import org.apache.uima.textmarker.type.TextMarkerBasic;
+import org.apache.uima.textmarker.visitor.InferenceCrowd;
+
+public class ParseCondition extends AbstractTextMarkerCondition {
+
+ private final String var;
+
+ public ParseCondition(String var) {
+ super();
+ this.var = var;
+ }
+
+ @Override
+ public EvaluatedCondition eval(TextMarkerBasic basic, Type matchedType,
+ TextMarkerRuleElement element, TextMarkerStream stream, InferenceCrowd crowd) {
+ AnnotationFS annotation = stream.expandAnchor(basic, matchedType);
+ String text = annotation.getCoveredText();
+ TextMarkerEnvironment env = element.getParent().getEnvironment();
+ Class<?> type = env.getVariableType(var);
+ try {
+ if (Integer.class.equals(type)) {
+ text = normalizeNumber(text);
+ int value = Integer.valueOf(text);
+ env.setVariableValue(var, value);
+ return new EvaluatedCondition(this, true);
+ } else if (Double.class.equals(type)) {
+ text = normalizeNumber(text);
+ double value = Double.valueOf(text);
+ env.setVariableValue(var, value);
+ return new EvaluatedCondition(this, true);
+ } else if (String.class.equals(type)) {
+ env.setVariableValue(var, text);
+ return new EvaluatedCondition(this, true);
+ } else if (Boolean.class.equals(type)) {
+ env.setVariableValue(var, !"".equals(text));
+ return new EvaluatedCondition(this, true);
+ } else if (Type.class.equals(type)) {
+ Type value = stream.getCas().getTypeSystem().getType(text);
+ env.setVariableValue(var, value);
+ return new EvaluatedCondition(this, true);
+ } else {
+ return new EvaluatedCondition(this, false);
+ }
+ } catch (Exception e) {
+ return new EvaluatedCondition(this, false);
+ }
+ }
+
+ private String normalizeNumber(String text) {
+ String[] split = text.split("[,]");
+ if (split.length == 2) {
+ return text.replaceAll(",", ".");
+ }
+ return text;
+ }
+
+ public String getVar() {
+ return var;
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/ParseCondition.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/ParseCondition.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/PartOfCondition.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/PartOfCondition.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/PartOfCondition.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/PartOfCondition.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.condition;
+
+import java.util.List;
+
+import org.apache.uima.cas.Type;
+import org.apache.uima.textmarker.TextMarkerStream;
+import org.apache.uima.textmarker.expression.list.TypeListExpression;
+import org.apache.uima.textmarker.expression.type.TypeExpression;
+import org.apache.uima.textmarker.rule.EvaluatedCondition;
+import org.apache.uima.textmarker.rule.TextMarkerRuleElement;
+import org.apache.uima.textmarker.type.TextMarkerBasic;
+import org.apache.uima.textmarker.visitor.InferenceCrowd;
+
+public class PartOfCondition extends TypeSentiveCondition {
+
+ public PartOfCondition(TypeExpression type) {
+ super(type);
+ }
+
+ public PartOfCondition(TypeListExpression list) {
+ super(list);
+ }
+
+ @Override
+ public EvaluatedCondition eval(TextMarkerBasic basic, Type matchedType,
+ TextMarkerRuleElement element, TextMarkerStream stream, InferenceCrowd crowd) {
+ if (!isWorkingOnList()) {
+ Type t = type.getType(element.getParent());
+ boolean result = check(t, basic, element, stream);
+ return new EvaluatedCondition(this, result);
+ } else {
+ boolean result = false;
+ List<Type> types = getList().getList(element.getParent());
+ for (Type t : types) {
+ result |= check(t, basic, element, stream);
+ if (result == true) {
+ break;
+ }
+ }
+ return new EvaluatedCondition(this, result);
+ }
+ }
+
+ private boolean check(Type t, TextMarkerBasic basic, TextMarkerRuleElement element,
+ TextMarkerStream stream) {
+ boolean result = stream.getCas().getTypeSystem().subsumes(t, basic.getType())
+ || basic.isAnchorOf(t.getName()) || basic.isPartOf(t.getName());
+ return result;
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/PartOfCondition.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/PartOfCondition.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/PartOfNeqCondition.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/PartOfNeqCondition.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/PartOfNeqCondition.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/PartOfNeqCondition.java Fri Aug 12 10:44:04 2011
@@ -0,0 +1,83 @@
+/*
+ * 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.condition;
+
+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.list.TypeListExpression;
+import org.apache.uima.textmarker.expression.type.TypeExpression;
+import org.apache.uima.textmarker.rule.EvaluatedCondition;
+import org.apache.uima.textmarker.rule.TextMarkerRuleElement;
+import org.apache.uima.textmarker.type.TextMarkerBasic;
+import org.apache.uima.textmarker.visitor.InferenceCrowd;
+
+public class PartOfNeqCondition extends TypeSentiveCondition {
+
+ public PartOfNeqCondition(TypeExpression type) {
+ super(type);
+ }
+
+ public PartOfNeqCondition(TypeListExpression list) {
+ super(list);
+ }
+
+ @Override
+ public EvaluatedCondition eval(TextMarkerBasic basic, Type matchedType,
+ TextMarkerRuleElement element, TextMarkerStream stream, InferenceCrowd crowd) {
+ if (!isWorkingOnList()) {
+ Type t = type.getType(element.getParent());
+ boolean result = check(basic, matchedType, stream, t);
+ return new EvaluatedCondition(this, result);
+ } else {
+ boolean result = false;
+ List<Type> types = getList().getList(element.getParent());
+ for (Type t : types) {
+ result |= check(basic, matchedType, stream, t);
+ if (result == true) {
+ break;
+ }
+ }
+ return new EvaluatedCondition(this, result);
+ }
+ }
+
+ private boolean check(TextMarkerBasic basic, Type matchedType, TextMarkerStream stream, Type t) {
+ AnnotationFS expandAnchor = stream.expandAnchor(basic, matchedType);
+ stream.moveTo(basic);
+ while (stream.isValid()) {
+ TextMarkerBasic each = (TextMarkerBasic) stream.get();
+ AnnotationFS afs = each.getType(t.getName());
+ if (afs != null
+ && afs.getType().equals(t)
+ && ((afs.getBegin() < expandAnchor.getBegin() && afs.getEnd() > expandAnchor.getEnd())
+ || (afs.getBegin() == expandAnchor.getBegin() && afs.getEnd() > expandAnchor
+ .getEnd()) || (afs.getBegin() < expandAnchor.getBegin() && afs
+ .getEnd() == expandAnchor.getEnd()))) {
+ return true;
+ }
+ stream.moveToPrevious();
+ }
+ return false;
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/PartOfNeqCondition.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/PartOfNeqCondition.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/PositionCondition.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/PositionCondition.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/PositionCondition.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/PositionCondition.java Fri Aug 12 10:44:04 2011
@@ -0,0 +1,77 @@
+/*
+ * 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.condition;
+
+import java.util.List;
+
+import org.apache.uima.cas.Type;
+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.EvaluatedCondition;
+import org.apache.uima.textmarker.rule.TextMarkerRuleElement;
+import org.apache.uima.textmarker.type.TextMarkerBasic;
+import org.apache.uima.textmarker.visitor.InferenceCrowd;
+
+public class PositionCondition extends TypeSentiveCondition {
+
+ private final NumberExpression position;
+
+ public NumberExpression getPosition() {
+ return position;
+ }
+
+ public PositionCondition(TypeExpression type, NumberExpression position) {
+ super(type);
+ this.position = position;
+ }
+
+ @Override
+ public EvaluatedCondition eval(TextMarkerBasic basic, Type matchedType,
+ TextMarkerRuleElement element, TextMarkerStream stream, InferenceCrowd crowd) {
+ Type t = type.getType(element.getParent());
+ if (!basic.isPartOf(t.getName())) {
+ return new EvaluatedCondition(this, false);
+ }
+ if (matchedType == null)
+ return new EvaluatedCondition(this, false);
+ int counter = 0;
+ List<TextMarkerBasic> annotationsInWindow = null;
+ if (t.getName().equals("uima.tcas.DocumentAnnotation")
+ || stream.getDocumentAnnotation().getType().equals(t)) {
+ annotationsInWindow = stream.getBasicsInWindow(stream.getDocumentAnnotation());
+ } else {
+ annotationsInWindow = stream.getAnnotationsOverlappingWindow(basic, t);
+ }
+ for (TextMarkerBasic eachBasic : annotationsInWindow) {
+ if (eachBasic.isAnchorOf(matchedType.getName())
+ || stream.getCas().getTypeSystem().subsumes(matchedType, eachBasic.getType())) {
+ counter++;
+ if (eachBasic.equals(basic)) {
+ if (counter == position.getIntegerValue(element.getParent())) {
+ return new EvaluatedCondition(this, true);
+ }
+ }
+ }
+ }
+ return new EvaluatedCondition(this, false);
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/PositionCondition.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/PositionCondition.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/RegExpCondition.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/RegExpCondition.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/RegExpCondition.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/RegExpCondition.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.condition;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+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.bool.BooleanExpression;
+import org.apache.uima.textmarker.expression.bool.SimpleBooleanExpression;
+import org.apache.uima.textmarker.expression.string.StringExpression;
+import org.apache.uima.textmarker.rule.EvaluatedCondition;
+import org.apache.uima.textmarker.rule.TextMarkerRuleElement;
+import org.apache.uima.textmarker.type.TextMarkerBasic;
+import org.apache.uima.textmarker.visitor.InferenceCrowd;
+
+public class RegExpCondition extends TerminalTextMarkerCondition {
+ private final StringExpression pattern;
+
+ private BooleanExpression ignoreCase;
+
+ public RegExpCondition(StringExpression pattern, BooleanExpression ignoreCase) {
+ this.pattern = pattern;
+ this.ignoreCase = ignoreCase == null ? new SimpleBooleanExpression(false) : ignoreCase;
+ }
+
+ @Override
+ public EvaluatedCondition eval(TextMarkerBasic basic, Type matchedType,
+ TextMarkerRuleElement element, TextMarkerStream stream, InferenceCrowd crowd) {
+ AnnotationFS annotation = stream.expandAnchor(basic, matchedType);
+ String coveredText = annotation.getCoveredText();
+ boolean ignore = ignoreCase == null ? false : ignoreCase.getBooleanValue(element.getParent());
+ Pattern regularExpPattern = null;
+ String stringValue = pattern.getStringValue(element.getParent());
+ if (ignore) {
+ regularExpPattern = Pattern.compile(stringValue, Pattern.CASE_INSENSITIVE);
+ } else {
+ regularExpPattern = Pattern.compile(stringValue);
+ }
+ Matcher macther = regularExpPattern.matcher(coveredText);
+ boolean matches = macther.matches();
+ return new EvaluatedCondition(this, matches);
+ }
+
+ public StringExpression getPattern() {
+ return pattern;
+ }
+}
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/RegExpCondition.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/RegExpCondition.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/ScoreCondition.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/ScoreCondition.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/ScoreCondition.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/ScoreCondition.java Fri Aug 12 10:44:04 2011
@@ -0,0 +1,84 @@
+/*
+ * 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.condition;
+
+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.number.SimpleNumberExpression;
+import org.apache.uima.textmarker.rule.EvaluatedCondition;
+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 ScoreCondition extends TerminalTextMarkerCondition {
+ private final NumberExpression min;
+
+ private final NumberExpression max;
+
+ private final String var;
+
+ public ScoreCondition(NumberExpression min, NumberExpression max, String var) {
+ this.min = min == null ? new SimpleNumberExpression(Integer.MIN_VALUE) : min;
+ this.max = max == null ? new SimpleNumberExpression(Integer.MAX_VALUE) : max;
+ this.var = var;
+ }
+
+ @Override
+ public EvaluatedCondition eval(TextMarkerBasic basic, Type matchedType,
+ TextMarkerRuleElement element, TextMarkerStream stream, InferenceCrowd crowd) {
+ AnnotationFS annotation = stream.expandAnchor(basic, matchedType);
+ Type heuristicType = stream.getJCas().getCasType(TextMarkerAnnotation.type);
+ List<AnnotationFS> annotationsInWindow = stream.getAnnotationsInWindow(annotation,
+ heuristicType);
+ double score = 0;
+ if (!annotationsInWindow.isEmpty()) {
+ TextMarkerAnnotation heuristicAnnotation = (TextMarkerAnnotation) stream.getCas()
+ .createAnnotation(heuristicType, annotation.getBegin(), annotation.getEnd());
+ heuristicAnnotation.setAnnotation((Annotation) annotation);
+ TextMarkerAnnotation tma = stream.getCorrectTMA(annotationsInWindow, heuristicAnnotation);
+ score = tma.getScore();
+ }
+ if (var != null) {
+ element.getParent().getEnvironment().setVariableValue(var, score);
+ }
+ boolean value = score >= min.getDoubleValue(element.getParent())
+ && score <= max.getDoubleValue(element.getParent());
+ return new EvaluatedCondition(this, value);
+ }
+
+ public NumberExpression getMin() {
+ return min;
+ }
+
+ public NumberExpression getMax() {
+ return max;
+ }
+
+ public String getVar() {
+ return var;
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/ScoreCondition.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/ScoreCondition.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/SizeCondition.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/SizeCondition.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/SizeCondition.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/SizeCondition.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.condition;
+
+import org.apache.uima.cas.Type;
+import org.apache.uima.textmarker.TextMarkerStream;
+import org.apache.uima.textmarker.expression.list.ListExpression;
+import org.apache.uima.textmarker.expression.number.NumberExpression;
+import org.apache.uima.textmarker.expression.number.SimpleNumberExpression;
+import org.apache.uima.textmarker.rule.EvaluatedCondition;
+import org.apache.uima.textmarker.rule.TextMarkerRuleElement;
+import org.apache.uima.textmarker.type.TextMarkerBasic;
+import org.apache.uima.textmarker.visitor.InferenceCrowd;
+
+public class SizeCondition extends AbstractTextMarkerCondition {
+
+ private ListExpression<?> listExpr;
+
+ private NumberExpression minExpr;
+
+ private NumberExpression maxExpr;
+
+ private String varExpr;
+
+ public SizeCondition(ListExpression<?> list, NumberExpression min, NumberExpression max,
+ String string) {
+ super();
+ this.listExpr = list;
+ this.minExpr = min == null ? new SimpleNumberExpression(Integer.MIN_VALUE) : min;
+ this.maxExpr = max == null ? new SimpleNumberExpression(Integer.MAX_VALUE) : max;
+ this.varExpr = string;
+ }
+
+ @Override
+ public EvaluatedCondition eval(TextMarkerBasic basic, Type matchedType,
+ TextMarkerRuleElement element, TextMarkerStream stream, InferenceCrowd crowd) {
+ int count = listExpr.getList(element.getParent()).size();
+ boolean value = count >= minExpr.getIntegerValue(element.getParent())
+ && count <= maxExpr.getIntegerValue(element.getParent());
+ if (varExpr != null) {
+ element.getParent().getEnvironment().setVariableValue(varExpr, count);
+ }
+ return new EvaluatedCondition(this, value);
+ }
+
+ public ListExpression<?> getListExpr() {
+ return listExpr;
+ }
+
+ public NumberExpression getMinExpr() {
+ return minExpr;
+ }
+
+ public NumberExpression getMaxExpr() {
+ return maxExpr;
+ }
+
+ public String getVarExpr() {
+ return varExpr;
+ }
+}
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/SizeCondition.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/SizeCondition.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/StartsWithCondition.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/StartsWithCondition.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/StartsWithCondition.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/StartsWithCondition.java Fri Aug 12 10:44:04 2011
@@ -0,0 +1,76 @@
+/*
+ * 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.condition;
+
+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.list.TypeListExpression;
+import org.apache.uima.textmarker.expression.type.TypeExpression;
+import org.apache.uima.textmarker.rule.EvaluatedCondition;
+import org.apache.uima.textmarker.rule.TextMarkerRuleElement;
+import org.apache.uima.textmarker.type.TextMarkerBasic;
+import org.apache.uima.textmarker.visitor.InferenceCrowd;
+
+public class StartsWithCondition extends TypeSentiveCondition {
+
+ public StartsWithCondition(TypeExpression type) {
+ super(type);
+ }
+
+ public StartsWithCondition(TypeListExpression list) {
+ super(list);
+ }
+
+ @Override
+ public EvaluatedCondition eval(TextMarkerBasic basic, Type matchedType,
+ TextMarkerRuleElement element, TextMarkerStream stream, InferenceCrowd crowd) {
+ if (!isWorkingOnList()) {
+ Type t = type.getType(element.getParent());
+ boolean result = check(basic, t);
+ return new EvaluatedCondition(this, result);
+ } else {
+ boolean result = false;
+ List<Type> types = getList().getList(element.getParent());
+ for (Type t : types) {
+ result |= check(basic, t);
+ if (result == true) {
+ break;
+ }
+ }
+ return new EvaluatedCondition(this, result);
+ }
+ }
+
+ private boolean check(TextMarkerBasic basic, Type t) {
+ if (basic == null) {
+ return false;
+ }
+ AnnotationFS a = basic.getType(t.getName());
+ boolean result = false;
+ if (a != null && basic.getBegin() == a.getBegin()) {
+ result = true;
+ }
+ return result;
+ }
+
+}
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/StartsWithCondition.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/StartsWithCondition.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/TerminalTextMarkerCondition.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/TerminalTextMarkerCondition.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/TerminalTextMarkerCondition.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/TerminalTextMarkerCondition.java Fri Aug 12 10:44:04 2011
@@ -0,0 +1,24 @@
+/*
+ * 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.condition;
+
+public abstract class TerminalTextMarkerCondition extends AbstractTextMarkerCondition {
+
+}
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/TerminalTextMarkerCondition.java
------------------------------------------------------------------------------
svn:executable = *
Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/condition/TerminalTextMarkerCondition.java
------------------------------------------------------------------------------
svn:mime-type = text/plain