You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by pk...@apache.org on 2016/01/04 11:33:50 UTC
svn commit: r1722834 [7/9] - in /uima/ruta/trunk: ./
example-projects/ruta-ep-example-extensions/
example-projects/ruta-ep-example-extensions/src/main/java/org/apache/uima/ruta/example/extensions/
ruta-core-ext/src/main/java/org/apache/uima/ruta/block/...
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/IStringExpression.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/IStringExpression.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/IStringExpression.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/IStringExpression.java Mon Jan 4 10:33:48 2016
@@ -19,17 +19,12 @@
package org.apache.uima.ruta.expression.string;
-import org.apache.uima.cas.text.AnnotationFS;
-import org.apache.uima.ruta.RutaBlock;
import org.apache.uima.ruta.RutaStream;
import org.apache.uima.ruta.expression.IRutaExpression;
-import org.apache.uima.ruta.rule.RuleElement;
-import org.apache.uima.ruta.rule.RuleMatch;
+import org.apache.uima.ruta.rule.MatchContext;
public interface IStringExpression extends IRutaExpression {
- String getStringValue(RutaBlock parent, AnnotationFS annotation, RutaStream stream);
-
- String getStringValue(RutaBlock parent, RuleMatch match, RuleElement element, RutaStream stream);
+ String getStringValue(MatchContext context, RutaStream stream);
}
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/RemoveFunction.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/RemoveFunction.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/RemoveFunction.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/RemoveFunction.java Mon Jan 4 10:33:48 2016
@@ -21,9 +21,9 @@ package org.apache.uima.ruta.expression.
import java.util.List;
-import org.apache.uima.cas.text.AnnotationFS;
import org.apache.uima.ruta.RutaBlock;
import org.apache.uima.ruta.RutaStream;
+import org.apache.uima.ruta.rule.MatchContext;
public class RemoveFunction extends StringFunctionExpression {
@@ -38,11 +38,12 @@ public class RemoveFunction extends Stri
}
@Override
- public String getStringValue(RutaBlock parent, AnnotationFS annotation, RutaStream stream) {
+ public String getStringValue(MatchContext context, RutaStream stream) {
+ RutaBlock parent = context.getParent();
StringBuilder result = new StringBuilder();
String value = parent.getEnvironment().getVariableValue(var, String.class);
for (IStringExpression each : list) {
- String string = each.getStringValue(parent, annotation, stream);
+ String string = each.getStringValue(context, stream);
String[] split = value.split(string);
for (String r : split) {
result.append(r);
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/SimpleStringExpression.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/SimpleStringExpression.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/SimpleStringExpression.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/SimpleStringExpression.java Mon Jan 4 10:33:48 2016
@@ -19,9 +19,8 @@
package org.apache.uima.ruta.expression.string;
-import org.apache.uima.cas.text.AnnotationFS;
-import org.apache.uima.ruta.RutaBlock;
import org.apache.uima.ruta.RutaStream;
+import org.apache.uima.ruta.rule.MatchContext;
public class SimpleStringExpression extends LiteralStringExpression {
@@ -41,7 +40,7 @@ public class SimpleStringExpression exte
}
@Override
- public String getStringValue(RutaBlock parent, AnnotationFS annotation, RutaStream stream) {
+ public String getStringValue(MatchContext context, RutaStream stream) {
return getValue();
}
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/StringFeatureExpression.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/StringFeatureExpression.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/StringFeatureExpression.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/StringFeatureExpression.java Mon Jan 4 10:33:48 2016
@@ -25,9 +25,9 @@ import java.util.List;
import org.apache.uima.cas.Feature;
import org.apache.uima.cas.Type;
import org.apache.uima.cas.text.AnnotationFS;
-import org.apache.uima.ruta.RutaBlock;
import org.apache.uima.ruta.RutaStream;
import org.apache.uima.ruta.expression.feature.FeatureExpression;
+import org.apache.uima.ruta.rule.MatchContext;
public class StringFeatureExpression extends AbstractStringExpression {
@@ -39,15 +39,16 @@ public class StringFeatureExpression ext
}
@Override
- public String getStringValue(RutaBlock parent, AnnotationFS annotation, RutaStream stream) {
- Type type = fe.getTypeExpr(parent).getType(parent);
- Feature feature = fe.getFeature(parent);
+ public String getStringValue(MatchContext context, RutaStream stream) {
+ AnnotationFS annotation = context.getAnnotation();
+ Type type = fe.getTypeExpr(context, stream).getType(context, stream);
+ Feature feature = fe.getFeature(context, stream);
List<AnnotationFS> list = getTargetAnnotation(annotation, type, stream);
- Collection<AnnotationFS> featureAnnotations = fe.getFeatureAnnotations(list, stream, parent,
+ Collection<AnnotationFS> featureAnnotations = fe.getFeatureAnnotations(list, stream, context,
false);
if (!featureAnnotations.isEmpty()) {
AnnotationFS next = featureAnnotations.iterator().next();
- if(feature == null) {
+ if (feature == null) {
// feature == coveredText
return next.getCoveredText();
} else {
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/StringFunctionFactory.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/StringFunctionFactory.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/StringFunctionFactory.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/string/StringFunctionFactory.java Mon Jan 4 10:33:48 2016
@@ -25,7 +25,8 @@ import org.antlr.runtime.Token;
public class StringFunctionFactory {
- public static AbstractStringExpression createRemoveFunction(Token var, List<IStringExpression> list) {
+ public static AbstractStringExpression createRemoveFunction(Token var,
+ List<IStringExpression> list) {
String v = var == null ? "" : var.getText();
return new RemoveFunction(v, list);
}
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/type/ITypeExpression.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/type/ITypeExpression.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/type/ITypeExpression.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/type/ITypeExpression.java Mon Jan 4 10:33:48 2016
@@ -20,18 +20,23 @@
package org.apache.uima.ruta.expression.type;
import org.apache.uima.cas.Type;
-import org.apache.uima.ruta.RutaBlock;
+import org.apache.uima.ruta.RutaStream;
+import org.apache.uima.ruta.expression.string.IStringExpression;
+import org.apache.uima.ruta.rule.MatchContext;
-public interface ITypeExpression {
+public interface ITypeExpression extends IStringExpression {
/**
* Returns the actual type of the TypeExpression
*
- * @param parent - the block of the element
+ * @param context
+ * - the match context
+ * @param stream
+ *
* @return annotation type
- * @throws IllegalArgumentException if the type cannot be resolved.
+ * @throws IllegalArgumentException
+ * if the type cannot be resolved.
*/
- Type getType(RutaBlock parent);
-
-
+ Type getType(MatchContext context, RutaStream stream);
+
}
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/type/SimpleTypeExpression.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/type/SimpleTypeExpression.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/type/SimpleTypeExpression.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/type/SimpleTypeExpression.java Mon Jan 4 10:33:48 2016
@@ -20,11 +20,11 @@
package org.apache.uima.ruta.expression.type;
import org.apache.uima.cas.Type;
-import org.apache.uima.cas.text.AnnotationFS;
import org.apache.uima.ruta.RutaBlock;
import org.apache.uima.ruta.RutaStream;
+import org.apache.uima.ruta.rule.MatchContext;
-public class SimpleTypeExpression extends TypeExpression {
+public class SimpleTypeExpression extends AbstractTypeExpression {
private final String typeString;
@@ -36,14 +36,15 @@ public class SimpleTypeExpression extend
/**
* Returns the actual type of the TypeExpression
*
- * @param parent - the block of the element
* @return annotation type
- * @throws IllegalArgumentException if the type cannot be resolved.
+ * @throws IllegalArgumentException
+ * if the type cannot be resolved.
*/
@Override
- public Type getType(RutaBlock parent) {
+ public Type getType(MatchContext context, RutaStream stream) {
+ RutaBlock parent = context.getParent();
Type type = parent.getEnvironment().getType(typeString);
- if(type == null) {
+ if (type == null) {
throw new IllegalArgumentException("Not able to resolve type: " + typeString);
}
return type;
@@ -55,7 +56,7 @@ public class SimpleTypeExpression extend
}
@Override
- public String getStringValue(RutaBlock parent, AnnotationFS annotation, RutaStream stream) {
+ public String getStringValue(MatchContext context, RutaStream stream) {
return typeString;
}
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/type/TypeFunctionExpression.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/type/TypeFunctionExpression.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/type/TypeFunctionExpression.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/expression/type/TypeFunctionExpression.java Mon Jan 4 10:33:48 2016
@@ -19,6 +19,6 @@
package org.apache.uima.ruta.expression.type;
-public abstract class TypeFunctionExpression extends TypeExpression {
+public abstract class TypeFunctionExpression extends AbstractTypeExpression {
}
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/extensions/IRutaBlockExtension.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/extensions/IRutaBlockExtension.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/extensions/IRutaBlockExtension.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/extensions/IRutaBlockExtension.java Mon Jan 4 10:33:48 2016
@@ -28,5 +28,5 @@ public interface IRutaBlockExtension ext
RutaBlock createBlock(String name, List<RutaExpression> args, RutaBlock env)
throws RutaParseException;
-
+
}
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/extensions/RutaExternalFactory.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/extensions/RutaExternalFactory.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/extensions/RutaExternalFactory.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/extensions/RutaExternalFactory.java Mon Jan 4 10:33:48 2016
@@ -29,10 +29,11 @@ import org.apache.uima.ruta.RutaBlock;
import org.apache.uima.ruta.action.AbstractRutaAction;
import org.apache.uima.ruta.condition.AbstractRutaCondition;
import org.apache.uima.ruta.expression.RutaExpression;
+import org.apache.uima.ruta.expression.annotation.IAnnotationExpression;
import org.apache.uima.ruta.expression.bool.IBooleanExpression;
import org.apache.uima.ruta.expression.number.INumberExpression;
import org.apache.uima.ruta.expression.string.AbstractStringExpression;
-import org.apache.uima.ruta.expression.type.TypeExpression;
+import org.apache.uima.ruta.expression.type.ITypeExpression;
public class RutaExternalFactory {
@@ -42,6 +43,8 @@ public class RutaExternalFactory {
private Map<String, IRutaTypeFunctionExtension> typeFunctionExtensions;
+ private Map<String, IRutaAnnotationFunctionExtension> annotationFunctionExtensions;
+
private Map<String, IRutaBooleanFunctionExtension> booleanFunctionExtensions;
private Map<String, IRutaStringFunctionExtension> stringFunctionExtensions;
@@ -60,6 +63,7 @@ public class RutaExternalFactory {
stringFunctionExtensions = new HashMap<String, IRutaStringFunctionExtension>();
numberFunctionExtensions = new HashMap<String, IRutaNumberFunctionExtension>();
typeFunctionExtensions = new HashMap<String, IRutaTypeFunctionExtension>();
+ annotationFunctionExtensions = new HashMap<String, IRutaAnnotationFunctionExtension>();
blockExtensions = new HashMap<String, IRutaBlockExtension>();
}
@@ -85,7 +89,7 @@ public class RutaExternalFactory {
return null;
}
- public TypeExpression createExternalTypeFunction(Token id, List<RutaExpression> args)
+ public ITypeExpression createExternalTypeFunction(Token id, List<RutaExpression> args)
throws RutaParseException {
String name = id.getText();
IRutaTypeFunctionExtension extension = typeFunctionExtensions.get(name);
@@ -96,6 +100,17 @@ public class RutaExternalFactory {
return null;
}
+ public IAnnotationExpression createExternalAnnotationFunction(Token id, List<RutaExpression> args)
+ throws RutaParseException {
+ String name = id.getText();
+ IRutaAnnotationFunctionExtension extension = annotationFunctionExtensions.get(name);
+ if (extension != null) {
+ return extension.createAnnotationFunction(name, args);
+ }
+ // Throw exception
+ return null;
+ }
+
public IBooleanExpression createExternalBooleanFunction(Token id, List<RutaExpression> args)
throws RutaParseException {
String name = id.getText();
@@ -232,6 +247,15 @@ public class RutaExternalFactory {
this.typeFunctionExtensions = typeFunctionExtensions;
}
+ public Map<String, IRutaAnnotationFunctionExtension> getAnnotationFunctionExtensions() {
+ return annotationFunctionExtensions;
+ }
+
+ public void setAnnotationFunctionExtensions(
+ Map<String, IRutaAnnotationFunctionExtension> annotationFunctionExtensions) {
+ this.annotationFunctionExtensions = annotationFunctionExtensions;
+ }
+
public Map<String, IRutaActionExtension> getActionExtensions() {
return actionExtensions;
}
@@ -264,4 +288,6 @@ public class RutaExternalFactory {
this.context = context;
}
+
+
}
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/extensions/RutaParseException.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/extensions/RutaParseException.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/extensions/RutaParseException.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/extensions/RutaParseException.java Mon Jan 4 10:33:48 2016
@@ -21,10 +21,10 @@ package org.apache.uima.ruta.extensions;
public class RutaParseException extends Exception {
- public RutaParseException(String message) {
- super(message);
- }
+ public RutaParseException(String message) {
+ super(message);
+ }
- private static final long serialVersionUID = -2728650696200821469L;
+ private static final long serialVersionUID = -2728650696200821469L;
}
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/resource/AnonymousWordList.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/resource/AnonymousWordList.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/resource/AnonymousWordList.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/resource/AnonymousWordList.java Mon Jan 4 10:33:48 2016
@@ -23,10 +23,8 @@ import java.util.ArrayList;
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.ruta.RutaStream;
-import org.apache.uima.ruta.expression.IRutaExpression;
import org.apache.uima.ruta.type.RutaBasic;
public class AnonymousWordList implements RutaWordList {
@@ -63,8 +61,8 @@ public class AnonymousWordList implement
return result;
}
- public List<AnnotationFS> find(RutaStream stream, Map<String, Object> typeMap, boolean ignoreCase,
- int ignoreLength, boolean edit, double distance, String ignoreToken) {
+ public List<AnnotationFS> find(RutaStream stream, Map<String, Object> typeMap,
+ boolean ignoreCase, int ignoreLength, boolean edit, double distance, String ignoreToken) {
return new ArrayList<AnnotationFS>();
}
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/resource/MultiTextNode.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/resource/MultiTextNode.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/resource/MultiTextNode.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/resource/MultiTextNode.java Mon Jan 4 10:33:48 2016
@@ -49,7 +49,7 @@ public class MultiTextNode {
private Set<String> types;
private boolean isWordEnd = false;
-
+
private static final int DEFAUL_INITIAL_CAPACITY = 5;
/** Default constructor uses a space as value. */
@@ -102,7 +102,6 @@ public class MultiTextNode {
return children.put(n.getValue(), n);
}
-
/**
* Returns the child, when you follow the c-edge, if exists. Returns null otherwise.
*
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/resource/MultiTreeWordList.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/resource/MultiTreeWordList.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/resource/MultiTreeWordList.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/resource/MultiTreeWordList.java Mon Jan 4 10:33:48 2016
@@ -145,8 +145,6 @@ public class MultiTreeWordList implement
}
}
-
-
public MultiTreeWordList(List<File> files, File base) throws IOException {
this.root = new MultiTextNode();
this.costMap = new EditDistanceCostMap();
@@ -157,7 +155,7 @@ public class MultiTreeWordList implement
}
private String getRelativePath(File file, File base) {
- if(base == null) {
+ if (base == null) {
return file.getName();
}
Path filePath = file.toPath();
@@ -175,17 +173,18 @@ public class MultiTreeWordList implement
* @throws IOException
* When there is a problem reading the resource.
*/
-
+
private void load(Resource resource) throws IOException {
load(resource, resource.getFilename());
}
-
+
/**
* Load a resource in this word list.
*
* @param resource
- * Resource to load.
- * @param name - The resource's name must end with .txt or .mtwl.
+ * Resource to load.
+ * @param name
+ * - The resource's name must end with .txt or .mtwl.
* @throws IOException
* When there is a problem reading the resource.
*/
@@ -874,7 +873,7 @@ public class MultiTreeWordList implement
Type type = null;
String featureString = null;
Object value = each;
- if (list.size() == 2 ||list.size() == 3) {
+ if (list.size() == 2 || list.size() == 3) {
if (list.get(0) instanceof Type) {
type = (Type) list.get(0);
}
@@ -882,9 +881,9 @@ public class MultiTreeWordList implement
featureString = (String) list.get(1);
}
if (list.size() == 3) {
- value = list.get(2);
+ value = list.get(2);
}
-
+
if (type != null && featureString != null) {
int begin = basicsToAdd.get(0).getBegin();
int end = basicsToAdd.get(basicsToAdd.size() - 1).getEnd();
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/resource/ResourcePathResourceLoader.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/resource/ResourcePathResourceLoader.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/resource/ResourcePathResourceLoader.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/resource/ResourcePathResourceLoader.java Mon Jan 4 10:33:48 2016
@@ -33,7 +33,8 @@ public class ResourcePathResourceLoader
private final String[] resourcePaths;
/**
- * @param resourcePaths Resource paths to search in.
+ * @param resourcePaths
+ * Resource paths to search in.
*/
public ResourcePathResourceLoader(String[] resourcePaths) {
this.resourcePaths = resourcePaths;
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/resource/RutaResourceLoader.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/resource/RutaResourceLoader.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/resource/RutaResourceLoader.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/resource/RutaResourceLoader.java Mon Jan 4 10:33:48 2016
@@ -27,17 +27,21 @@ import org.springframework.core.io.suppo
/**
* Resource loader for ruta.
*
- * This resource loader first looks in the resource paths and fallback in the classpath if it is not found.
+ * This resource loader first looks in the resource paths and fallback in the classpath if it is not
+ * found.
*/
public class RutaResourceLoader implements ResourceLoader {
private final ResourceLoader wrapped;
+
private final ResourceLoader fallback;
/**
- * @param resourcePaths Resource paths to search in priority.
+ * @param resourcePaths
+ * Resource paths to search in priority.
*/
public RutaResourceLoader(String[] resourcePaths) {
- this.wrapped = new PathMatchingResourcePatternResolver(new ResourcePathResourceLoader(resourcePaths));
+ this.wrapped = new PathMatchingResourcePatternResolver(new ResourcePathResourceLoader(
+ resourcePaths));
this.fallback = new DefaultResourceLoader();
}
@@ -50,6 +54,6 @@ public class RutaResourceLoader implemen
}
public ClassLoader getClassLoader() {
- return getClass().getClassLoader();
+ return getClass().getClassLoader();
}
}
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/resource/RutaWordList.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/resource/RutaWordList.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/resource/RutaWordList.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/resource/RutaWordList.java Mon Jan 4 10:33:48 2016
@@ -22,7 +22,6 @@ package org.apache.uima.ruta.resource;
import java.util.Collection;
import java.util.Map;
-import org.apache.uima.cas.Type;
import org.apache.uima.cas.text.AnnotationFS;
import org.apache.uima.ruta.RutaStream;
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/AbstractRuleElement.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/AbstractRuleElement.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/AbstractRuleElement.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/AbstractRuleElement.java Mon Jan 4 10:33:48 2016
@@ -46,7 +46,7 @@ public abstract class AbstractRuleElemen
private boolean startAnchor;
private String label;
-
+
private RuleElementContainer container;
protected RutaBlock parent;
@@ -57,7 +57,7 @@ public abstract class AbstractRuleElemen
protected List<RutaStatement> inlinedConditionRules;
protected List<RutaStatement> inlinedActionRules;
-
+
public AbstractRuleElement(RuleElementQuantifier quantifier,
List<AbstractRutaCondition> conditions, List<AbstractRutaAction> actions,
RuleElementContainer container, RutaBlock parent) {
@@ -104,9 +104,9 @@ public abstract class AbstractRuleElemen
}
return null;
}
-
- protected List<ScriptApply> processInlinedRules(List<RutaStatement> inlinedRules, RuleMatch ruleMatch, RutaStream stream,
- InferenceCrowd crowd) {
+
+ protected List<ScriptApply> processInlinedRules(List<RutaStatement> inlinedRules,
+ RuleMatch ruleMatch, RutaStream stream, InferenceCrowd crowd) {
List<ScriptApply> result = new ArrayList<ScriptApply>();
List<AnnotationFS> matchedAnnotationsOf = ruleMatch.getMatchedAnnotationsOfElement(this);
// TODO where to implement the explanation of inlined rules?
@@ -126,12 +126,10 @@ public abstract class AbstractRuleElemen
return result;
}
-
-
public void apply(RuleMatch ruleMatch, RutaStream stream, InferenceCrowd crowd) {
for (AbstractRutaAction action : actions) {
crowd.beginVisit(action, null);
- action.execute(ruleMatch, this, stream, crowd);
+ action.execute(new MatchContext(this, ruleMatch), stream, crowd);
crowd.endVisit(action, null);
}
processInlinedActionRules(ruleMatch, stream, crowd);
@@ -165,9 +163,9 @@ public abstract class AbstractRuleElemen
return matchInfo;
}
- public List<RuleElementMatch> evaluateMatches(List<RuleElementMatch> matches, RutaBlock parent,
- RutaStream stream) {
- return quantifier.evaluateMatches(matches, parent, stream, emptyCrowd);
+ public List<RuleElementMatch> evaluateMatches(List<RuleElementMatch> matches,
+ MatchContext context, RutaStream stream) {
+ return quantifier.evaluateMatches(matches, context, stream, emptyCrowd);
}
public List<Integer> getSelfIndexList() {
@@ -289,19 +287,19 @@ public abstract class AbstractRuleElemen
public void setLabel(String label) {
this.label = label;
}
-
+
public void setInlinedConditionRules(List<RutaStatement> innerRules) {
this.inlinedConditionRules = innerRules;
}
-
+
public List<RutaStatement> getInlinedConditionRules() {
return inlinedConditionRules;
}
-
+
public void setInlinedActionRules(List<RutaStatement> innerRules) {
this.inlinedActionRules = innerRules;
}
-
+
public List<RutaStatement> getInlinedActionRules() {
return inlinedActionRules;
}
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/ComposedRuleElement.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/ComposedRuleElement.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/ComposedRuleElement.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/ComposedRuleElement.java Mon Jan 4 10:33:48 2016
@@ -96,8 +96,8 @@ public class ComposedRuleElement extends
for (Entry<RuleMatch, ComposedRuleElementMatch> entry : entrySet) {
RuleMatch eachRuleMatch = entry.getKey();
ComposedRuleElementMatch eachComposedMatch = entry.getValue();
- AnnotationFS lastAnnotation = eachRuleMatch.getLastMatchedAnnotation(this, true, null,
- parent, stream);
+ MatchContext context = new MatchContext(null, this, eachRuleMatch, true);
+ AnnotationFS lastAnnotation = eachRuleMatch.getLastMatchedAnnotation(context, stream);
boolean failed = !eachComposedMatch.matched();
List<RuleMatch> fallbackContinue = fallbackContinue(true, failed, lastAnnotation,
eachRuleMatch, ruleApply, eachComposedMatch, null, entryPoint, stream, crowd);
@@ -142,8 +142,8 @@ public class ComposedRuleElement extends
for (Entry<RuleMatch, ComposedRuleElementMatch> entry : entrySet) {
RuleMatch eachRuleMatch = entry.getKey();
ComposedRuleElementMatch eachComposedMatch = entry.getValue();
- AnnotationFS lastAnnotation = eachRuleMatch.getLastMatchedAnnotation(this, true, null,
- parent, stream);
+ MatchContext context = new MatchContext(this, eachRuleMatch);
+ AnnotationFS lastAnnotation = eachRuleMatch.getLastMatchedAnnotation(context, stream);
boolean failed = !eachComposedMatch.matched();
List<AnnotationFS> textsMatched = eachComposedMatch.getTextsMatched();
if ((!stream.isGreedyAnchoring() && !stream.isOnlyOnce())
@@ -159,8 +159,8 @@ public class ComposedRuleElement extends
}
private AnnotationFS getPrefixAnnotation(RuleMatch ruleMatch, RutaStream stream) {
- AnnotationFS lastMatchedAnnotation = ruleMatch.getLastMatchedAnnotation(this, true, null,
- parent, stream);
+ MatchContext context = new MatchContext(this, ruleMatch);
+ AnnotationFS lastMatchedAnnotation = ruleMatch.getLastMatchedAnnotation(context, stream);
if (lastMatchedAnnotation.getBegin() == 0) {
JCas jCas = stream.getJCas();
AnnotationFS dummy = new RutaFrame(jCas, 0, 0);
@@ -216,8 +216,8 @@ public class ComposedRuleElement extends
for (Entry<RuleMatch, ComposedRuleElementMatch> entry : entrySet) {
RuleMatch eachRuleMatch = entry.getKey();
ComposedRuleElementMatch eachComposedMatch = entry.getValue();
- AnnotationFS lastAnnotation = eachRuleMatch.getLastMatchedAnnotation(this, after,
- annotation, parent, stream);
+ MatchContext context = new MatchContext(annotation, this, eachRuleMatch, after);
+ AnnotationFS lastAnnotation = eachRuleMatch.getLastMatchedAnnotation(context, stream);
boolean failed = !eachComposedMatch.matched();
List<AnnotationFS> textsMatched = eachRuleMatch.getMatchedAnnotationsOfRoot();
if ((!stream.isGreedyAnchoring() && !stream.isOnlyOnce())
@@ -260,8 +260,8 @@ public class ComposedRuleElement extends
for (Entry<RuleMatch, ComposedRuleElementMatch> entry : entrySet) {
RuleMatch eachRuleMatch = entry.getKey();
ComposedRuleElementMatch eachComposedMatch = entry.getValue();
- AnnotationFS lastAnnotation = eachRuleMatch.getLastMatchedAnnotation(this, after,
- annotation, parent, stream);
+ MatchContext context = new MatchContext(this, eachRuleMatch);
+ AnnotationFS lastAnnotation = eachRuleMatch.getLastMatchedAnnotation(context, stream);
boolean failed = !eachComposedMatch.matched();
@@ -327,8 +327,8 @@ public class ComposedRuleElement extends
if (elementMatch.matched()) {
result.put(ruleMatch, elementMatch);
} else {
- AnnotationFS lastMatchedAnnotation = ruleMatch.getLastMatchedAnnotation(getFirstElement(),
- direction, null, parent, stream);
+ MatchContext context = new MatchContext(getFirstElement(), ruleMatch, direction);
+ AnnotationFS lastMatchedAnnotation = ruleMatch.getLastMatchedAnnotation(context, stream);
if (largestEntry == null) {
largestEntry = entry;
largestAnnotation = lastMatchedAnnotation;
@@ -376,15 +376,16 @@ public class ComposedRuleElement extends
ComposedRuleElementMatch parentContainerMatch = containerMatch.getContainerMatch();
List<RuleElementMatch> match = getMatch(ruleMatch, parentContainerMatch);
int lenghtBefore = match.size();
- List<RuleElementMatch> evaluateMatches = quantifier.evaluateMatches(match, parent,
+ MatchContext context = new MatchContext(this, ruleMatch, after);
+ List<RuleElementMatch> evaluateMatches = quantifier.evaluateMatches(match, context,
stream, crowd);
ruleMatch.setMatched(ruleMatch.matched() && evaluateMatches != null);
if (evaluateMatches != null && evaluateMatches.size() != lenghtBefore) {
failed = true;
stopMatching = true;
}
- if (!quantifier.continueMatch(after, nextAnnotation, this, ruleMatch, containerMatch,
- stream, crowd)) {
+ if (!quantifier.continueMatch(after, context, nextAnnotation, containerMatch, stream,
+ crowd)) {
stopMatching = true;
}
if (evaluateMatches != null) {
@@ -408,7 +409,7 @@ public class ComposedRuleElement extends
InferenceCrowd crowd) {
List<RuleMatch> result = new ArrayList<RuleMatch>();
RuleElementContainer container = getContainer();
- doMatch(containerMatch, ruleMatch, stream, crowd);
+ doMatch(after, containerMatch, ruleMatch, stream, crowd);
if (this.equals(entryPoint) && ruleApply == null) {
result.add(ruleMatch);
} else if (container == null) {
@@ -419,13 +420,14 @@ public class ComposedRuleElement extends
RuleElement nextElement = container.getNextElement(after, this);
List<RuleElementMatch> match = getMatch(ruleMatch, parentContainerMatch);
int sizeBefore = match.size();
- boolean continueMatch = quantifier.continueMatch(after, annotation, this, ruleMatch,
+ MatchContext context = new MatchContext(annotation, this, ruleMatch, after);
+ boolean continueMatch = quantifier.continueMatch(after, context, annotation,
parentContainerMatch, stream, crowd);
- List<RuleElementMatch> evaluateMatches = quantifier.evaluateMatches(match, parent, stream,
+ List<RuleElementMatch> evaluateMatches = quantifier.evaluateMatches(match, context, stream,
crowd);
int sizeAfter = evaluateMatches != null ? evaluateMatches.size() : sizeBefore;
boolean removedFailedMatches = sizeAfter < sizeBefore;
- if(removedFailedMatches) {
+ if (removedFailedMatches) {
containerMatch.enforceUpdate();
}
ruleMatch.setMatched((ruleMatch.matched() || removedFailedMatches)
@@ -530,8 +532,8 @@ public class ComposedRuleElement extends
}
}
- private void doMatch(ComposedRuleElementMatch match, RuleMatch ruleMatch, RutaStream stream,
- InferenceCrowd crowd) {
+ private void doMatch(boolean after, ComposedRuleElementMatch match, RuleMatch ruleMatch,
+ RutaStream stream, InferenceCrowd crowd) {
List<AnnotationFS> textsMatched = match.getTextsMatched();
if (textsMatched == null || textsMatched.isEmpty()) {
match.evaluateInnerMatches(true, stream);
@@ -542,11 +544,13 @@ public class ComposedRuleElement extends
AnnotationFS annotation = stream.getCas().createAnnotation(stream.getCas().getAnnotationType(),
begin, end);
+ MatchContext context = new MatchContext(annotation, this, ruleMatch, after);
+
List<EvaluatedCondition> evaluatedConditions = new ArrayList<EvaluatedCondition>(
conditions.size());
for (AbstractRutaCondition condition : conditions) {
crowd.beginVisit(condition, null);
- EvaluatedCondition eval = condition.eval(annotation, this, stream, crowd);
+ EvaluatedCondition eval = condition.eval(context, stream, crowd);
crowd.endVisit(condition, null);
evaluatedConditions.add(eval);
}
@@ -567,7 +571,8 @@ public class ComposedRuleElement extends
for (RuleElement each : elements) {
result += each.estimateAnchors(stream);
}
- if (quantifier.isOptional(getParent(), stream)) {
+ MatchContext context = new MatchContext(null, null);
+ if (quantifier.isOptional(context, stream)) {
// three times since sibling elements maybe need to be checked
result *= 3 * (int) stream.getIndexPenalty();
}
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/ComposedRuleElementMatch.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/ComposedRuleElementMatch.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/ComposedRuleElementMatch.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/ComposedRuleElementMatch.java Mon Jan 4 10:33:48 2016
@@ -90,7 +90,8 @@ public class ComposedRuleElementMatch ex
for (Entry<RuleElement, List<RuleElementMatch>> entry : entrySet) {
RuleElement element = entry.getKey();
List<RuleElementMatch> value = entry.getValue();
- allDone &= (element.getQuantifier().isOptional(element.getParent(), stream) || value != null);
+ MatchContext context = new MatchContext(element, null, true);
+ allDone &= (element.getQuantifier().isOptional(context, stream) || value != null);
if (value != null && !value.isEmpty() && included) {
for (RuleElementMatch ruleElementMatch : value) {
allDone &= ruleElementMatch.matched();
@@ -198,7 +199,7 @@ public class ComposedRuleElementMatch ex
if (value != null) {
List<RuleElementMatch> newValue = new ArrayList<RuleElementMatch>();
newValue.addAll(value);
- if(!newValue.isEmpty()) {
+ if (!newValue.isEmpty()) {
// there was no match
newValue.set(newValue.size() - 1, extendedContainerMatch);
}
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/ConjunctRulesRuleElement.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/ConjunctRulesRuleElement.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/ConjunctRulesRuleElement.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/ConjunctRulesRuleElement.java Mon Jan 4 10:33:48 2016
@@ -46,11 +46,13 @@ public class ConjunctRulesRuleElement ex
ComposedRuleElementMatch composedMatch = createComposedMatch(ruleMatch, containerMatch, stream);
boolean allMatched = true;
for (RuleElement each : elements) {
- List<RuleMatch> startMatch = each.startMatch(ruleMatch, null, composedMatch, each, stream, crowd);
- boolean oneMatched = false;;
+ List<RuleMatch> startMatch = each.startMatch(ruleMatch, null, composedMatch, each, stream,
+ crowd);
+ boolean oneMatched = false;
+ ;
for (RuleMatch eachRuleMatch : startMatch) {
boolean matched = eachRuleMatch.matched();
- if(matched) {
+ if (matched) {
oneMatched = true;
break;
}
@@ -58,7 +60,7 @@ public class ConjunctRulesRuleElement ex
allMatched &= oneMatched;
result.addAll(startMatch);
}
-
+
for (RuleMatch each : result) {
if (!each.isApplied()) {
ruleApply.add(each);
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RegExpRule.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RegExpRule.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RegExpRule.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RegExpRule.java Mon Jan 4 10:33:48 2016
@@ -48,20 +48,20 @@ import org.apache.uima.ruta.expression.b
import org.apache.uima.ruta.expression.number.INumberExpression;
import org.apache.uima.ruta.expression.string.AbstractStringExpression;
import org.apache.uima.ruta.expression.string.IStringExpression;
-import org.apache.uima.ruta.expression.type.TypeExpression;
+import org.apache.uima.ruta.expression.type.ITypeExpression;
import org.apache.uima.ruta.utils.UIMAUtils;
import org.apache.uima.ruta.visitor.InferenceCrowd;
public class RegExpRule extends AbstractRule {
- private Map<TypeExpression, INumberExpression> typeMap;
+ private Map<ITypeExpression, INumberExpression> typeMap;
private IStringExpression regexpExpr;
- private Map<TypeExpression, Map<IStringExpression, IRutaExpression>> featureAssignments;
+ private Map<ITypeExpression, Map<IStringExpression, IRutaExpression>> featureAssignments;
- public RegExpRule(AbstractStringExpression regexp, Map<TypeExpression, INumberExpression> typeMap, int id,
- RutaBlock parent) {
+ public RegExpRule(AbstractStringExpression regexp,
+ Map<ITypeExpression, INumberExpression> typeMap, int id, RutaBlock parent) {
super(parent, id);
this.regexpExpr = regexp;
this.typeMap = typeMap;
@@ -71,13 +71,13 @@ public class RegExpRule extends Abstract
public ScriptApply apply(RutaStream stream, InferenceCrowd crowd) {
RuleApply ruleApply = new RuleApply(this, false);
crowd.beginVisit(this, ruleApply);
-
- String regexpString = regexpExpr.getStringValue(getParent(), null, stream);
+ MatchContext context = new MatchContext(getParent());
+ String regexpString = regexpExpr.getStringValue(context, stream);
AnnotationFS documentAnnotation = stream.getDocumentAnnotation();
String document = documentAnnotation.getCoveredText();
int delta = documentAnnotation.getBegin();
- Map<Integer, List<Type>> groupTypes = getGroup2Types(stream);
+ Map<Integer, List<Type>> groupTypes = getGroup2Types(context, stream);
Map<Integer, Map<Type, Map<String, Object>>> fa = getFeatureAssignmentMap(stream);
Pattern pattern = Pattern.compile(regexpString, Pattern.MULTILINE | Pattern.DOTALL);
@@ -111,14 +111,15 @@ public class RegExpRule extends Abstract
private Map<Integer, Map<Type, Map<String, Object>>> getFeatureAssignmentMap(RutaStream stream) {
Map<Integer, Map<Type, Map<String, Object>>> result = new HashMap<Integer, Map<Type, Map<String, Object>>>();
- Set<Entry<TypeExpression, Map<IStringExpression, IRutaExpression>>> entrySet = featureAssignments
+ Set<Entry<ITypeExpression, Map<IStringExpression, IRutaExpression>>> entrySet = featureAssignments
.entrySet();
- for (Entry<TypeExpression, Map<IStringExpression, IRutaExpression>> entry : entrySet) {
- TypeExpression key = entry.getKey();
- Type type = key.getType(getParent());
+ MatchContext context = new MatchContext(getParent());
+ for (Entry<ITypeExpression, Map<IStringExpression, IRutaExpression>> entry : entrySet) {
+ ITypeExpression key = entry.getKey();
+ Type type = key.getType(context, stream);
Map<IStringExpression, IRutaExpression> value = entry.getValue();
INumberExpression cgExpr = typeMap.get(key);
- int cg = cgExpr == null ? 0 : cgExpr.getIntegerValue(getParent(), null, stream);
+ int cg = cgExpr == null ? 0 : cgExpr.getIntegerValue(context, stream);
Map<Type, Map<String, Object>> map = result.get(cg);
if (map == null) {
map = new HashMap<Type, Map<String, Object>>();
@@ -133,20 +134,20 @@ public class RegExpRule extends Abstract
for (Entry<IStringExpression, IRutaExpression> entry2 : entrySet2) {
IStringExpression key2 = entry2.getKey();
IRutaExpression value2 = entry2.getValue();
- String stringValue = key2.getStringValue(getParent(), null, stream);
+ String stringValue = key2.getStringValue(context, stream);
typeMap.put(stringValue, value2);
}
}
return result;
}
- private Map<Integer, List<Type>> getGroup2Types(RutaStream stream) {
+ private Map<Integer, List<Type>> getGroup2Types(MatchContext context, RutaStream stream) {
Map<Integer, List<Type>> groupTypes = new TreeMap<Integer, List<Type>>();
- Set<Entry<TypeExpression, INumberExpression>> entrySet = typeMap.entrySet();
- for (Entry<TypeExpression, INumberExpression> entry : entrySet) {
- Type type = entry.getKey().getType(getParent());
+ Set<Entry<ITypeExpression, INumberExpression>> entrySet = typeMap.entrySet();
+ for (Entry<ITypeExpression, INumberExpression> entry : entrySet) {
+ Type type = entry.getKey().getType(context, stream);
INumberExpression value = entry.getValue();
- int group = value == null ? 0 : value.getIntegerValue(getParent(), null, stream);
+ int group = value == null ? 0 : value.getIntegerValue(context, stream);
List<Type> list = groupTypes.get(group);
if (list == null) {
list = new ArrayList<Type>();
@@ -181,6 +182,7 @@ public class RegExpRule extends Abstract
jcas = cas.getJCas();
} catch (CASException e) {
}
+ MatchContext context = new MatchContext(null, null, null, true);
TypeSystem typeSystem = cas.getTypeSystem();
Map<Type, Map<String, Object>> typeMap = fa.get(group);
if (typeMap != null) {
@@ -194,7 +196,7 @@ public class RegExpRule extends Abstract
Type range = feature.getRange();
if (argExpr instanceof INumberExpression) {
INumberExpression ne = (INumberExpression) argExpr;
- int cg = ne.getIntegerValue(getParent(), afs, stream);
+ int cg = ne.getIntegerValue(context, stream);
if (range.getName().equals(UIMAConstants.TYPE_STRING)) {
String s = matchResult.group(cg);
afs.setStringValue(feature, s);
@@ -222,11 +224,11 @@ public class RegExpRule extends Abstract
}
}
} else {
- if (argExpr instanceof TypeExpression
+ if (argExpr instanceof ITypeExpression
&& range.getName().equals(UIMAConstants.TYPE_STRING)) {
- TypeExpression typeExpr = (TypeExpression) argExpr;
+ ITypeExpression typeExpr = (ITypeExpression) argExpr;
List<AnnotationFS> annotationsInWindow = stream.getAnnotationsInWindow(afs,
- typeExpr.getType(getParent()));
+ typeExpr.getType(context, stream));
if (annotationsInWindow != null && !annotationsInWindow.isEmpty()) {
AnnotationFS annotation = annotationsInWindow.get(0);
afs.setStringValue(feature, annotation.getCoveredText());
@@ -234,7 +236,7 @@ public class RegExpRule extends Abstract
} else if (argExpr instanceof AbstractStringExpression
&& range.getName().equals(UIMAConstants.TYPE_STRING)) {
afs.setStringValue(feature,
- ((AbstractStringExpression) argExpr).getStringValue(getParent(), afs, stream));
+ ((AbstractStringExpression) argExpr).getStringValue(context, stream));
// numbers are reserved for capturing groups
//
// } else if (argExpr instanceof NumberExpression) {
@@ -260,14 +262,14 @@ public class RegExpRule extends Abstract
} else if (argExpr instanceof IBooleanExpression
&& range.getName().equals(UIMAConstants.TYPE_BOOLEAN)) {
afs.setBooleanValue(feature,
- ((IBooleanExpression) argExpr).getBooleanValue(getParent(), null, stream));
- } else if (argExpr instanceof TypeExpression) {
- TypeExpression typeExpr = (TypeExpression) argExpr;
+ ((IBooleanExpression) argExpr).getBooleanValue(context, stream));
+ } else if (argExpr instanceof ITypeExpression) {
+ ITypeExpression typeExpr = (ITypeExpression) argExpr;
List<AnnotationFS> annotationsInWindow = stream.getAnnotationsInWindow(afs,
- typeExpr.getType(getParent()));
+ typeExpr.getType(context, stream));
if (typeSystem.subsumes(jcas.getCasType(FSArray.type), range)) {
afs.setFeatureValue(feature, UIMAUtils.toFSArray(jcas, annotationsInWindow));
- } else if (typeSystem.subsumes(range, typeExpr.getType(getParent()))
+ } else if (typeSystem.subsumes(range, typeExpr.getType(context, stream))
&& !annotationsInWindow.isEmpty()) {
AnnotationFS annotation = annotationsInWindow.get(0);
afs.setFeatureValue(feature, annotation);
@@ -285,11 +287,11 @@ public class RegExpRule extends Abstract
return getParent().getEnvironment();
}
- public Map<TypeExpression, INumberExpression> getTypeMap() {
+ public Map<ITypeExpression, INumberExpression> getTypeMap() {
return typeMap;
}
- public void setTypeMap(Map<TypeExpression, INumberExpression> typeMap) {
+ public void setTypeMap(Map<ITypeExpression, INumberExpression> typeMap) {
this.typeMap = typeMap;
}
@@ -301,11 +303,11 @@ public class RegExpRule extends Abstract
this.regexpExpr = regexp;
}
- public void setFeatureAssignments(Map<TypeExpression, Map<IStringExpression, IRutaExpression>> fa) {
+ public void setFeatureAssignments(Map<ITypeExpression, Map<IStringExpression, IRutaExpression>> fa) {
this.featureAssignments = fa;
}
- public Map<TypeExpression, Map<IStringExpression, IRutaExpression>> getFeatureAssignments() {
+ public Map<ITypeExpression, Map<IStringExpression, IRutaExpression>> getFeatureAssignments() {
return featureAssignments;
}
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleElement.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleElement.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleElement.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleElement.java Mon Jan 4 10:33:48 2016
@@ -49,7 +49,7 @@ public interface RuleElement {
RutaRuleElement sideStepOrigin, RuleElement entryPoint, RutaStream stream,
InferenceCrowd crowd);
- List<RuleElementMatch> evaluateMatches(List<RuleElementMatch> matches, RutaBlock parent,
+ List<RuleElementMatch> evaluateMatches(List<RuleElementMatch> matches, MatchContext context,
RutaStream stream);
Collection<AnnotationFS> getAnchors(RutaStream symbolStream);
@@ -79,11 +79,11 @@ public interface RuleElement {
boolean isStartAnchor();
void setInlinedActionRules(List<RutaStatement> innerRules);
-
+
void setInlinedConditionRules(List<RutaStatement> innerRules);
void setLabel(String label);
-
+
String getLabel();
}
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleElementCaretaker.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleElementCaretaker.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleElementCaretaker.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleElementCaretaker.java Mon Jan 4 10:33:48 2016
@@ -47,7 +47,7 @@ public class RuleElementCaretaker implem
if (indexOf > 0) {
RuleElement ruleElement = container.getRuleElements().get(indexOf - 1);
return ruleElement;
- } else if(indexOf == -1) {
+ } else if (indexOf == -1) {
return container.getRuleElements().get(container.getRuleElements().size() - 1);
}
return null;
@@ -59,9 +59,9 @@ public class RuleElementCaretaker implem
public RuleElement getAnchoringRuleElement(RutaStream stream) {
List<RuleElement> ruleElements = container.getRuleElements();
- if (ruleElements.size() == 1
- //|| containsLiteralMatcher(ruleElements)
- ) {
+ if (ruleElements.size() == 1
+ // || containsLiteralMatcher(ruleElements)
+ ) {
return ruleElements.get(0);
}
for (RuleElement ruleElement : ruleElements) {
@@ -76,11 +76,11 @@ public class RuleElementCaretaker implem
int i = 1;
for (RuleElement each : ruleElements) {
long estimate = each.estimateAnchors(stream);
- if(estimate == 0) {
+ if (estimate == 0) {
return each;
}
double factor = stream.getIndexPenalty();
- if(factor != 0) {
+ if (factor != 0) {
estimate = (long) (Math.log(estimate) * (i * factor));
}
if (estimate < min) {
@@ -95,7 +95,6 @@ public class RuleElementCaretaker implem
}
-
public RuleElement getFirstElement() {
List<RuleElement> ruleElements = container.getRuleElements();
return ruleElements.get(0);
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleElementMatch.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleElementMatch.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleElementMatch.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleElementMatch.java Mon Jan 4 10:33:48 2016
@@ -36,7 +36,7 @@ public class RuleElementMatch {
protected boolean baseConditionMatched = true;
private boolean inlinedRulesMatched = true;
-
+
protected List<EvaluatedCondition> conditions;
protected ComposedRuleElementMatch containerMatch;
@@ -53,7 +53,7 @@ public class RuleElementMatch {
public String getLabel() {
return ruleElement.getLabel();
}
-
+
public void setMatchInfo(boolean baseCondition, List<AnnotationFS> texts,
List<EvaluatedCondition> conditionList, RutaStream stream) {
baseConditionMatched = baseCondition;
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleMatch.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleMatch.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleMatch.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RuleMatch.java Mon Jan 4 10:33:48 2016
@@ -28,7 +28,6 @@ import java.util.Set;
import org.apache.uima.cas.CAS;
import org.apache.uima.cas.text.AnnotationFS;
-import org.apache.uima.ruta.RutaBlock;
import org.apache.uima.ruta.RutaElement;
import org.apache.uima.ruta.RutaStream;
import org.apache.uima.ruta.ScriptApply;
@@ -54,7 +53,7 @@ public class RuleMatch extends AbstractR
public List<AnnotationFS> getMatchedAnnotationsOfElement(RuleElement element) {
return getMatchedAnnotations(element.getSelfIndexList(), element.getContainer());
}
-
+
public List<AnnotationFS> getMatchedAnnotationsOfLabel(String label) {
RuleElement element = getRuleElementWithLabel(label);
return getMatchedAnnotationsOfElement(element);
@@ -66,11 +65,13 @@ public class RuleMatch extends AbstractR
return element;
}
- public AnnotationFS getLastMatchedAnnotation(RuleElement element, boolean direction,
- AnnotationFS annotation, RutaBlock parent, RutaStream stream) {
+ public AnnotationFS getLastMatchedAnnotation(MatchContext context, RutaStream stream) {
+ RuleElement element = context.getElement();
+ AnnotationFS annotation = context.getAnnotation();
+ boolean direction = context.getDirection();
List<AnnotationFS> matchedAnnotations = getMatchedAnnotationsOfElement(element);
if (matchedAnnotations.isEmpty()) {
- if (element.getQuantifier().isOptional(parent, stream)) {
+ if (element.getQuantifier().isOptional(context, stream)) {
return annotation;
} else {
return null;
@@ -78,7 +79,7 @@ public class RuleMatch extends AbstractR
}
if (direction) {
AnnotationFS matched = matchedAnnotations.get(matchedAnnotations.size() - 1);
- if(annotation != null && matched.getEnd() < annotation.getEnd()) {
+ if (annotation != null && matched.getEnd() < annotation.getEnd()) {
// multiple matches, but none last time
return annotation;
} else {
@@ -86,7 +87,7 @@ public class RuleMatch extends AbstractR
}
} else {
AnnotationFS matched = matchedAnnotations.get(0);
- if(annotation != null && matched.getBegin() > annotation.getBegin()) {
+ if (annotation != null && matched.getBegin() > annotation.getBegin()) {
// multiple matches, but none last time
return annotation;
} else {
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaLiteralMatcher.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaLiteralMatcher.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaLiteralMatcher.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaLiteralMatcher.java Mon Jan 4 10:33:48 2016
@@ -43,8 +43,11 @@ public class RutaLiteralMatcher implemen
List<AnnotationFS> result = new ArrayList<AnnotationFS>();
AnnotationFS windowAnnotation = stream.getDocumentAnnotation();
List<RutaBasic> list = stream.getBasicsInWindow(windowAnnotation);
+ // TODO improve matching on literal strings
for (RutaBasic each : list) {
- if (each.getCoveredText().equals(expression.getStringValue(parent, null, stream))) {
+ MatchContext context = new MatchContext(each, null, null, true);
+ context.setParent(parent);
+ if (each.getCoveredText().equals(expression.getStringValue(context, stream))) {
result.add(each);
}
}
@@ -55,7 +58,9 @@ public class RutaLiteralMatcher implemen
if (annotation == null) {
return false;
}
- return annotation.getCoveredText().equals(expression.getStringValue(parent, null, stream));
+ MatchContext context = new MatchContext(annotation, null, null, true);
+ context.setParent(parent);
+ return annotation.getCoveredText().equals(expression.getStringValue(context, stream));
}
@Override
@@ -88,7 +93,9 @@ public class RutaLiteralMatcher implemen
if (basicNextTo == null) {
return result;
}
- String stringValue = expression.getStringValue(parent, annotation, stream);
+ MatchContext context = new MatchContext(annotation, null, null, !before);
+ context.setParent(parent);
+ String stringValue = expression.getStringValue(context, stream);
if (stringValue.equals(basicNextTo.getCoveredText())) {
result.add(basicNextTo);
}
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaRule.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaRule.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaRule.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaRule.java Mon Jan 4 10:33:48 2016
@@ -23,7 +23,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang3.StringUtils;
import org.apache.uima.ruta.RutaBlock;
import org.apache.uima.ruta.RutaEnvironment;
@@ -34,8 +33,8 @@ public class RutaRule extends AbstractRu
private ComposedRuleElement root;
- private Map<String,RuleElement> label2Element;
-
+ private Map<String, RuleElement> label2Element;
+
public RutaRule(List<RuleElement> elements, RutaBlock parent, int id) {
super(parent, id);
this.root = new ComposedRuleElement(elements, null, null, null, null, parent);
@@ -58,7 +57,7 @@ public class RutaRule extends AbstractRu
@Override
public String toString() {
- return root == null ? "<empty>": root.toString();
+ return root == null ? "<empty>" : root.toString();
}
public final List<RuleElement> getRuleElements() {
@@ -68,7 +67,7 @@ public class RutaRule extends AbstractRu
public RuleElement getRuleElementWithLabel(String label) {
return label2Element.get(label);
}
-
+
@Override
public RutaEnvironment getEnvironment() {
return getParent().getEnvironment();
@@ -81,20 +80,20 @@ public class RutaRule extends AbstractRu
} else {
root.setRuleElements(elements);
}
- if(elements != null) {
+ if (elements != null) {
// update label map
for (RuleElement ruleElement : elements) {
fillLabelMap(ruleElement);
}
}
-
+
}
private void fillLabelMap(RuleElement ruleElement) {
- if(!StringUtils.isBlank(ruleElement.getLabel())) {
+ if (!StringUtils.isBlank(ruleElement.getLabel())) {
label2Element.put(ruleElement.getLabel(), ruleElement);
}
- if(ruleElement instanceof ComposedRuleElement) {
+ if (ruleElement instanceof ComposedRuleElement) {
ComposedRuleElement cre = (ComposedRuleElement) ruleElement;
List<RuleElement> ruleElements = cre.getRuleElements();
for (RuleElement each : ruleElements) {
@@ -107,6 +106,4 @@ public class RutaRule extends AbstractRu
return root;
}
-
-
}
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaRuleElement.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaRuleElement.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaRuleElement.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaRuleElement.java Mon Jan 4 10:33:48 2016
@@ -29,7 +29,7 @@ import org.apache.uima.ruta.RutaBlock;
import org.apache.uima.ruta.RutaStream;
import org.apache.uima.ruta.action.AbstractRutaAction;
import org.apache.uima.ruta.condition.AbstractRutaCondition;
-import org.apache.uima.ruta.expression.MatchReference;
+import org.apache.uima.ruta.expression.IRutaExpression;
import org.apache.uima.ruta.expression.feature.FeatureExpression;
import org.apache.uima.ruta.rule.quantifier.RuleElementQuantifier;
import org.apache.uima.ruta.visitor.InferenceCrowd;
@@ -59,26 +59,27 @@ public class RutaRuleElement extends Abs
Collection<AnnotationFS> anchors = getAnchors(stream);
boolean useAlternatives = anchors.size() != 1;
for (AnnotationFS eachAnchor : anchors) {
- if(earlyExit(eachAnchor, ruleApply, stream)) {
+ if (earlyExit(eachAnchor, ruleApply, stream)) {
// ... for different matching paradigms that avoid some matches
continue;
}
-
+
ComposedRuleElementMatch extendedContainerMatch = containerMatch;
RuleMatch extendedMatch = ruleMatch;
if (useAlternatives) {
extendedContainerMatch = containerMatch.copy();
extendedMatch = ruleMatch.copy(extendedContainerMatch, true);
}
- doMatch(eachAnchor, extendedMatch, extendedContainerMatch, true, stream, crowd);
+ doMatch(true, eachAnchor, extendedMatch, extendedContainerMatch, true, stream, crowd);
if (this.equals(entryPoint) && ruleApply == null) {
result.add(extendedMatch);
} else if (extendedMatch.matched()) {
RuleElement after = getContainer().getNextElement(true, this);
RuleElement before = getContainer().getNextElement(false, this);
RutaRuleElement sideStepOrigin = hasAncestor(false) ? this : null;
- if (quantifier.continueMatch(true, eachAnchor, this, extendedMatch, extendedContainerMatch,
- stream, crowd)) {
+ MatchContext context = new MatchContext(this, extendedMatch, true);
+ if (quantifier.continueMatch(true, context, eachAnchor, extendedContainerMatch, stream,
+ crowd)) {
List<RuleMatch> continueOwnMatch = continueOwnMatch(true, eachAnchor, extendedMatch,
ruleApply, extendedContainerMatch, sideStepOrigin, entryPoint, stream, crowd);
result.addAll(continueOwnMatch);
@@ -127,15 +128,17 @@ public class RutaRuleElement extends Abs
RutaRuleElement sideStepOrigin, RuleElement entryPoint, RutaStream stream,
InferenceCrowd crowd) {
List<RuleMatch> result = new ArrayList<RuleMatch>();
- if (quantifier.continueMatch(after, annotation, this, ruleMatch, containerMatch, stream, crowd)) {
+ MatchContext context = new MatchContext(this, ruleMatch, after);
+ if (quantifier.continueMatch(after, context, annotation, containerMatch, stream, crowd)) {
boolean stopMatching = false;
AnnotationFS eachAnchor = annotation;
AnnotationFS lastAnchor = annotation;
ComposedRuleElementMatch extendedContainerMatch = containerMatch;
RuleMatch extendedMatch = ruleMatch;
while (!stopMatching) {
- if (!quantifier.continueMatch(after, eachAnchor, this, extendedMatch,
- extendedContainerMatch, stream, crowd)) {
+ context = new MatchContext(this, extendedMatch, after);
+ if (!quantifier.continueMatch(after, context, eachAnchor, extendedContainerMatch, stream,
+ crowd)) {
stopMatching = true;
stepbackMatch(after, lastAnchor, extendedMatch, ruleApply, extendedContainerMatch,
sideStepOrigin, stream, crowd, entryPoint);
@@ -149,12 +152,12 @@ public class RutaRuleElement extends Abs
} else if (nextAnnotations.size() == 1) {
lastAnchor = eachAnchor;
eachAnchor = nextAnnotations.iterator().next();
- doMatch(eachAnchor, extendedMatch, extendedContainerMatch, false, stream, crowd);
+ doMatch(after, eachAnchor, extendedMatch, extendedContainerMatch, false, stream, crowd);
if (this.equals(entryPoint)) {
result.add(extendedMatch);
} else if (extendedMatch.matched()) {
- if (quantifier.continueMatch(after, eachAnchor, this, extendedMatch,
- extendedContainerMatch, stream, crowd)) {
+ if (quantifier.continueMatch(after, context, eachAnchor, extendedContainerMatch,
+ stream, crowd)) {
// continue in while loop
} else {
stopMatching = true;
@@ -202,7 +205,8 @@ public class RutaRuleElement extends Abs
InferenceCrowd crowd) {
List<RuleMatch> result = new ArrayList<RuleMatch>();
// if() for really lazy quantifiers
- if (quantifier.continueMatch(after, annotation, this, ruleMatch, containerMatch, stream, crowd)) {
+ MatchContext context = new MatchContext(this, ruleMatch, after);
+ if (quantifier.continueMatch(after, context, annotation, containerMatch, stream, crowd)) {
Collection<AnnotationFS> nextAnnotations = getNextAnnotations(after, annotation, stream);
if (nextAnnotations.isEmpty()) {
result = stepbackMatch(after, annotation, ruleMatch, ruleApply, containerMatch,
@@ -210,24 +214,25 @@ public class RutaRuleElement extends Abs
}
boolean useAlternatives = nextAnnotations.size() != 1;
for (AnnotationFS eachAnchor : nextAnnotations) {
- if(earlyExit(eachAnchor, ruleApply, stream)) {
+ if (earlyExit(eachAnchor, ruleApply, stream)) {
// ... for different matching paradigms that avoid some matches
continue;
}
-
+
ComposedRuleElementMatch extendedContainerMatch = containerMatch;
RuleMatch extendedMatch = ruleMatch;
if (useAlternatives) {
extendedContainerMatch = containerMatch.copy();
extendedMatch = ruleMatch.copy(extendedContainerMatch, after);
}
- doMatch(eachAnchor, extendedMatch, extendedContainerMatch, false, stream, crowd);
+ doMatch(after, eachAnchor, extendedMatch, extendedContainerMatch, false, stream, crowd);
if (this.equals(entryPoint) && ruleApply == null) {
result.add(extendedMatch);
} else if (extendedMatch.matched()) {
- if (quantifier.continueMatch(after, annotation, this, extendedMatch,
- extendedContainerMatch, stream, crowd)) {
+ context = new MatchContext(this, extendedMatch, after);
+ if (quantifier.continueMatch(after, context, annotation, extendedContainerMatch, stream,
+ crowd)) {
List<RuleMatch> continueOwnMatch = continueOwnMatch(after, eachAnchor, extendedMatch,
ruleApply, extendedContainerMatch, sideStepOrigin, entryPoint, stream, crowd);
result.addAll(continueOwnMatch);
@@ -242,8 +247,8 @@ public class RutaRuleElement extends Abs
// hotfix for UIMA-3820
result.add(extendedMatch);
} else {
- List<RuleMatch> stepbackMatch = stepbackMatch(after, annotation, extendedMatch, ruleApply,
- extendedContainerMatch, sideStepOrigin, stream, crowd, entryPoint);
+ List<RuleMatch> stepbackMatch = stepbackMatch(after, annotation, extendedMatch,
+ ruleApply, extendedContainerMatch, sideStepOrigin, stream, crowd, entryPoint);
result.addAll(stepbackMatch);
}
}
@@ -265,13 +270,15 @@ public class RutaRuleElement extends Abs
return result;
}
List<RuleElementMatch> matchInfo = getMatch(ruleMatch, containerMatch);
+ MatchContext context = new MatchContext(this, ruleMatch, after);
if (matchInfo == null) {
- if (quantifier.isOptional(parent, stream)) {
+ if (quantifier.isOptional(context, stream)) {
result = continueMatchSomewhereElse(after, true, annotation, ruleMatch, ruleApply,
containerMatch, sideStepOrigin, entryPoint, stream, crowd);
} else if (getContainer() instanceof ComposedRuleElement) {
ComposedRuleElement cre = (ComposedRuleElement) getContainer();
- result = cre.fallbackContinue(after, true, annotation, ruleMatch, ruleApply, containerMatch, sideStepOrigin, entryPoint, stream, crowd);
+ result = cre.fallbackContinue(after, true, annotation, ruleMatch, ruleApply,
+ containerMatch, sideStepOrigin, entryPoint, stream, crowd);
// was:
// [Peter] why only check the parent? the grandparent could be optional!
// should we add the second part again for the explanation component?
@@ -288,7 +295,7 @@ public class RutaRuleElement extends Abs
// }
}
} else {
- List<RuleElementMatch> evaluateMatches = quantifier.evaluateMatches(matchInfo, parent,
+ List<RuleElementMatch> evaluateMatches = quantifier.evaluateMatches(matchInfo, context,
stream, crowd);
// TODO enforce match update?
ruleMatch.setMatched(evaluateMatches != null);
@@ -335,9 +342,9 @@ public class RutaRuleElement extends Abs
sideStepContainerMatch = (ComposedRuleElementMatch) list.get(0);
}
}
-
- if (quantifier.continueMatch(newDirection, annotation, this, ruleMatch,
- sideStepContainerMatch, stream, crowd)) {
+ MatchContext context = new MatchContext(this, ruleMatch, newDirection);
+ if (quantifier.continueMatch(newDirection, context, annotation, sideStepContainerMatch,
+ stream, crowd)) {
continueMatch(newDirection, annotation, ruleMatch, ruleApply, sideStepContainerMatch, null,
entryPoint, stream, crowd);
} else {
@@ -355,7 +362,7 @@ public class RutaRuleElement extends Abs
return result;
}
- private void doMatch(AnnotationFS annotation, RuleMatch ruleMatch,
+ private void doMatch(boolean after, AnnotationFS annotation, RuleMatch ruleMatch,
ComposedRuleElementMatch containerMatch, boolean ruleAnchor, RutaStream stream,
InferenceCrowd crowd) {
RuleElementMatch result = new RuleElementMatch(this, containerMatch);
@@ -366,17 +373,18 @@ public class RutaRuleElement extends Abs
boolean base = true;
if (matcher instanceof RutaTypeMatcher) {
RutaTypeMatcher rtm = (RutaTypeMatcher) matcher;
- MatchReference mr = (MatchReference) rtm.getExpression();
- FeatureExpression featureExpression = mr.getFeatureExpression(parent);
- if (featureExpression != null) {
+ IRutaExpression expression = rtm.getExpression();
+ if (expression instanceof FeatureExpression) {
base = matcher.match(annotation, stream, getParent());
}
}
+ MatchContext context = new MatchContext(annotation, this, ruleMatch, after);
+
List<AnnotationFS> textsMatched = new ArrayList<AnnotationFS>(1);
if (base) {
for (AbstractRutaCondition condition : conditions) {
crowd.beginVisit(condition, null);
- EvaluatedCondition eval = condition.eval(annotation, this, stream, crowd);
+ EvaluatedCondition eval = condition.eval(context, stream, crowd);
crowd.endVisit(condition, null);
evaluatedConditions.add(eval);
}
@@ -416,7 +424,8 @@ public class RutaRuleElement extends Abs
}
public long estimateAnchors(RutaStream stream) {
- if (quantifier.isOptional(getParent(), stream)) {
+ // TODO what about the match context?
+ if (quantifier.isOptional(null, stream)) {
return matcher.estimateAnchors(parent, stream) + Integer.MAX_VALUE;
}
return matcher.estimateAnchors(parent, stream);
Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaTypeMatcher.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaTypeMatcher.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaTypeMatcher.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaTypeMatcher.java Mon Jan 4 10:33:48 2016
@@ -31,24 +31,31 @@ import org.apache.uima.cas.TypeSystem;
import org.apache.uima.cas.text.AnnotationFS;
import org.apache.uima.ruta.RutaBlock;
import org.apache.uima.ruta.RutaStream;
-import org.apache.uima.ruta.expression.MatchReference;
-import org.apache.uima.ruta.expression.RutaExpression;
+import org.apache.uima.ruta.expression.IRutaExpression;
import org.apache.uima.ruta.expression.feature.FeatureExpression;
import org.apache.uima.ruta.expression.feature.FeatureMatchExpression;
-import org.apache.uima.ruta.expression.type.TypeExpression;
+import org.apache.uima.ruta.expression.type.ITypeExpression;
import org.apache.uima.ruta.type.RutaBasic;
public class RutaTypeMatcher implements RutaMatcher {
private static final boolean CHECK_ON_FEATURE = false;
- protected final MatchReference mr;
+ private ITypeExpression typeExpression;
+
+ private FeatureExpression featureExpression;
protected AnnotationComparator comparator;
- public RutaTypeMatcher(MatchReference mr) {
+ public RutaTypeMatcher(FeatureExpression expression) {
+ super();
+ this.featureExpression = expression;
+ this.comparator = new AnnotationComparator();
+ }
+
+ public RutaTypeMatcher(ITypeExpression expression) {
super();
- this.mr = mr;
+ this.typeExpression = expression;
this.comparator = new AnnotationComparator();
}
@@ -72,9 +79,11 @@ public class RutaTypeMatcher implements
annotations.addAll(stream.getAnnotations(type));
}
}
- FeatureExpression featureExpression = mr.getFeatureExpression(parent);
+ MatchContext context = new MatchContext(null, null, true);
+ context.setParent(parent);
if (featureExpression != null) {
- return featureExpression.getFeatureAnnotations(annotations, stream, parent, CHECK_ON_FEATURE);
+ return featureExpression
+ .getFeatureAnnotations(annotations, stream, context, CHECK_ON_FEATURE);
} else {
return annotations;
}
@@ -82,7 +91,7 @@ public class RutaTypeMatcher implements
public Collection<AnnotationFS> getAnnotationsAfter(RutaRuleElement ruleElement,
AnnotationFS annotation, RutaStream stream, RutaBlock parent) {
- if(annotation.getEnd() == stream.getDocumentAnnotation().getEnd()) {
+ if (annotation.getEnd() == stream.getDocumentAnnotation().getEnd()) {
return Collections.emptyList();
}
RutaBasic lastBasic = stream.getEndAnchor(annotation.getEnd());
@@ -96,7 +105,8 @@ public class RutaTypeMatcher implements
}
if (annotation.getEnd() > 0) {
stream.moveTo(lastBasic);
- if (stream.isVisible(lastBasic) && stream.isValid() && stream.get().getEnd() == lastBasic.getEnd()) {
+ if (stream.isVisible(lastBasic) && stream.isValid()
+ && stream.get().getEnd() == lastBasic.getEnd()) {
stream.moveToNext();
}
} else {
@@ -118,15 +128,17 @@ public class RutaTypeMatcher implements
Collection<AnnotationFS> beginAnchors = nextBasic.getBeginAnchors(eachMatchType);
if (beginAnchors != null) {
for (AnnotationFS afs : beginAnchors) {
- if (afs.getBegin() >= stream.getDocumentAnnotation().getBegin() && afs.getEnd() <= stream.getDocumentAnnotation().getEnd()) {
+ if (afs.getBegin() >= stream.getDocumentAnnotation().getBegin()
+ && afs.getEnd() <= stream.getDocumentAnnotation().getEnd()) {
anchors.add(afs);
}
}
}
}
- FeatureExpression fm = mr.getFeatureExpression(parent);
- if (fm != null) {
- return fm.getFeatureAnnotations(anchors, stream, parent, CHECK_ON_FEATURE);
+ MatchContext context = new MatchContext(null, null, true);
+ context.setParent(parent);
+ if (featureExpression != null) {
+ return featureExpression.getFeatureAnnotations(anchors, stream, context, CHECK_ON_FEATURE);
} else {
return anchors;
}
@@ -136,7 +148,7 @@ public class RutaTypeMatcher implements
public Collection<AnnotationFS> getAnnotationsBefore(RutaRuleElement ruleElement,
AnnotationFS annotation, RutaStream stream, RutaBlock parent) {
- if(annotation.getBegin() == stream.getDocumentAnnotation().getBegin()) {
+ if (annotation.getBegin() == stream.getDocumentAnnotation().getBegin()) {
return Collections.emptyList();
}
RutaBasic firstBasic = stream.getBeginAnchor(annotation.getBegin());
@@ -169,9 +181,10 @@ public class RutaTypeMatcher implements
}
}
}
- FeatureExpression fm = mr.getFeatureExpression(parent);
- if (fm != null) {
- return fm.getFeatureAnnotations(anchors, stream, parent, CHECK_ON_FEATURE);
+ MatchContext context = new MatchContext(null, null, true);
+ context.setParent(parent);
+ if (featureExpression != null) {
+ return featureExpression.getFeatureAnnotations(anchors, stream, context, CHECK_ON_FEATURE);
} else {
return anchors;
}
@@ -180,19 +193,29 @@ public class RutaTypeMatcher implements
}
public boolean match(AnnotationFS annotation, RutaStream stream, RutaBlock parent) {
+ // TODO refactor method, current state was chosen for debugging
if (annotation == null) {
return false;
}
- FeatureExpression featureExpression = mr.getFeatureExpression(parent);
if (featureExpression == null) {
boolean b = checkType(annotation, stream, parent);
if (b) {
return true;
}
} else {
- boolean b = checkFeature(annotation, stream, parent);
- if (b) {
- return true;
+
+ if (featureExpression.getFeatures(new MatchContext(parent), stream) == null) {
+ // hotfix for flawed feature expressions
+ boolean b = checkType(annotation, stream, parent);
+ if (b) {
+ return true;
+ }
+ } else {
+
+ boolean b = checkFeature(annotation, stream, parent);
+ if (b) {
+ return true;
+ }
}
}
@@ -217,11 +240,12 @@ public class RutaTypeMatcher implements
}
private boolean checkFeature(AnnotationFS annotation, RutaStream stream, RutaBlock parent) {
- FeatureExpression fe = mr.getFeatureExpression(parent);
- Feature feature = fe.getFeature(parent);
- if (fe instanceof FeatureMatchExpression) {
- FeatureMatchExpression fme = (FeatureMatchExpression) fe;
- boolean checkFeatureValue = fme.checkFeatureValue(annotation, stream, parent);
+ MatchContext context = new MatchContext(annotation, null, null, true);
+ context.setParent(parent);
+ Feature feature = featureExpression.getFeature(context, stream);
+ if (featureExpression instanceof FeatureMatchExpression) {
+ FeatureMatchExpression fme = (FeatureMatchExpression) featureExpression;
+ boolean checkFeatureValue = fme.checkFeatureValue(annotation, context, stream);
if (checkFeatureValue) {
return true;
}
@@ -237,15 +261,27 @@ public class RutaTypeMatcher implements
@Override
public String toString() {
- return mr.toString();
+ IRutaExpression expression = getExpression();
+ if (expression != null) {
+ return expression.toString();
+ } else {
+ return "";
+ }
}
- public RutaExpression getExpression() {
- return mr;
+ @Override
+ public IRutaExpression getExpression() {
+ if (featureExpression != null) {
+ return featureExpression;
+ } else if (typeExpression != null) {
+ return typeExpression;
+ }
+ return null;
}
- protected Type getType(TypeExpression expression, RutaBlock parent, RutaStream stream, boolean resolveDocumentAnnotation) {
- Type type = expression.getType(parent);
+ protected Type getType(ITypeExpression expression, RutaBlock parent, RutaStream stream, boolean resolveDocumentAnnotation) {
+ MatchContext context = new MatchContext(parent);
+ Type type = expression.getType(context, stream);
if (resolveDocumentAnnotation && type != null && "uima.tcas.DocumentAnnotation".equals(type.getName())) {
return stream.getDocumentAnnotationType();
}
@@ -253,15 +289,19 @@ public class RutaTypeMatcher implements
}
public long estimateAnchors(RutaBlock parent, RutaStream stream) {
- TypeExpression typeExpression = mr.getTypeExpression(parent);
return stream.getHistogram(getType(typeExpression, parent, stream, true));
}
public List<Type> getTypes(RutaBlock parent, RutaStream stream) {
List<Type> result = new ArrayList<Type>(1);
- TypeExpression typeExpression = mr.getTypeExpression(parent);
- Type type = getType(typeExpression, parent, stream, false);
- result.add(type);
+ if (typeExpression != null) {
+ Type type = getType(typeExpression, parent, stream, false);
+ result.add(type);
+ } else if (featureExpression != null) {
+ Type type = getType(featureExpression.getTypeExpr(new MatchContext(parent), stream), parent,
+ stream, false);
+ result.add(type);
+ }
return result;
}