You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by jo...@apache.org on 2011/08/01 17:25:50 UTC

svn commit: r1152824 [8/21] - in /uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker: ./ action/ batch/ condition/ engine/ kernel/ kernel/constraint/ kernel/expression/ kernel/expression/bool/...

Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/expression/type/TypeFunctionExpression.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/expression/type/TypeFunctionExpression.java?rev=1152824&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/expression/type/TypeFunctionExpression.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/expression/type/TypeFunctionExpression.java Mon Aug  1 15:24:44 2011
@@ -0,0 +1,6 @@
+package org.apache.uima.tm.textmarker.kernel.expression.type;
+
+
+public abstract class TypeFunctionExpression extends TypeExpression {
+
+}

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/expression/type/TypeFunctionExpression.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/expression/type/TypeFunctionExpression.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/DefaultEngineLoader.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/DefaultEngineLoader.java?rev=1152824&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/DefaultEngineLoader.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/DefaultEngineLoader.java Mon Aug  1 15:24:44 2011
@@ -0,0 +1,26 @@
+package org.apache.uima.tm.textmarker.kernel.extensions;
+
+import java.io.IOException;
+
+import org.apache.uima.UIMAFramework;
+import org.apache.uima.analysis_engine.AnalysisEngine;
+import org.apache.uima.resource.ResourceInitializationException;
+import org.apache.uima.resource.ResourceSpecifier;
+import org.apache.uima.util.InvalidXMLException;
+import org.apache.uima.util.XMLInputSource;
+
+public abstract class DefaultEngineLoader implements IEngineLoader {
+
+  public AnalysisEngine loadEngine(String location) throws InvalidXMLException,
+          ResourceInitializationException, IOException {
+    return loadEngineMyself(location);
+  }
+
+  protected AnalysisEngine loadEngineMyself(String location) throws IOException,
+          InvalidXMLException, ResourceInitializationException {
+    XMLInputSource in = new XMLInputSource(location);
+    ResourceSpecifier specifier = UIMAFramework.getXMLParser().parseResourceSpecifier(in);
+    AnalysisEngine ae = UIMAFramework.produceAnalysisEngine(specifier);
+    return ae;
+  }
+}

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/DefaultEngineLoader.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/DefaultEngineLoader.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/IEngineLoader.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/IEngineLoader.java?rev=1152824&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/IEngineLoader.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/IEngineLoader.java Mon Aug  1 15:24:44 2011
@@ -0,0 +1,16 @@
+package org.apache.uima.tm.textmarker.kernel.extensions;
+
+import java.io.IOException;
+
+import org.apache.uima.analysis_engine.AnalysisEngine;
+import org.apache.uima.resource.ResourceInitializationException;
+import org.apache.uima.util.InvalidXMLException;
+
+public interface IEngineLoader {
+
+  String[] getKnownEngines();
+
+  AnalysisEngine loadEngine(String location) throws InvalidXMLException,
+          ResourceInitializationException, IOException;
+
+}

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/IEngineLoader.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/IEngineLoader.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/ITextMarkerActionExtension.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/ITextMarkerActionExtension.java?rev=1152824&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/ITextMarkerActionExtension.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/ITextMarkerActionExtension.java Mon Aug  1 15:24:44 2011
@@ -0,0 +1,15 @@
+package org.apache.uima.tm.textmarker.kernel.extensions;
+
+import java.util.List;
+
+import org.apache.uima.tm.textmarker.action.AbstractTextMarkerAction;
+import org.apache.uima.tm.textmarker.kernel.expression.TextMarkerExpression;
+
+import antlr.ANTLRException;
+
+public interface ITextMarkerActionExtension extends ITextMarkerExtension {
+
+  AbstractTextMarkerAction createAction(String name, List<TextMarkerExpression> args)
+          throws ANTLRException;
+
+}

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/ITextMarkerActionExtension.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/ITextMarkerActionExtension.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/ITextMarkerBooleanFunctionExtension.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/ITextMarkerBooleanFunctionExtension.java?rev=1152824&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/ITextMarkerBooleanFunctionExtension.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/ITextMarkerBooleanFunctionExtension.java Mon Aug  1 15:24:44 2011
@@ -0,0 +1,15 @@
+package org.apache.uima.tm.textmarker.kernel.extensions;
+
+import java.util.List;
+
+import org.apache.uima.tm.textmarker.kernel.expression.TextMarkerExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.bool.BooleanFunctionExpression;
+
+import antlr.ANTLRException;
+
+public interface ITextMarkerBooleanFunctionExtension extends ITextMarkerExtension {
+
+  BooleanFunctionExpression createBooleanFunction(String name, List<TextMarkerExpression> args)
+          throws ANTLRException;
+
+}

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/ITextMarkerBooleanFunctionExtension.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/ITextMarkerBooleanFunctionExtension.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/ITextMarkerConditionExtension.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/ITextMarkerConditionExtension.java?rev=1152824&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/ITextMarkerConditionExtension.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/ITextMarkerConditionExtension.java Mon Aug  1 15:24:44 2011
@@ -0,0 +1,15 @@
+package org.apache.uima.tm.textmarker.kernel.extensions;
+
+import java.util.List;
+
+import org.apache.uima.tm.textmarker.condition.AbstractTextMarkerCondition;
+import org.apache.uima.tm.textmarker.kernel.expression.TextMarkerExpression;
+
+import antlr.ANTLRException;
+
+public interface ITextMarkerConditionExtension extends ITextMarkerExtension {
+
+  AbstractTextMarkerCondition createCondition(String name, List<TextMarkerExpression> args)
+          throws ANTLRException;
+
+}

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/ITextMarkerConditionExtension.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/ITextMarkerConditionExtension.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/ITextMarkerExtension.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/ITextMarkerExtension.java?rev=1152824&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/ITextMarkerExtension.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/ITextMarkerExtension.java Mon Aug  1 15:24:44 2011
@@ -0,0 +1,16 @@
+package org.apache.uima.tm.textmarker.kernel.extensions;
+
+import org.apache.uima.tm.textmarker.kernel.TextMarkerElement;
+import org.apache.uima.tm.textmarker.verbalize.TextMarkerVerbalizer;
+
+public interface ITextMarkerExtension {
+
+  String[] getKnownExtensions();
+
+  Class<?>[] extensions();
+
+  String verbalize(TextMarkerElement element, TextMarkerVerbalizer verbalizer);
+
+  String verbalizeName(TextMarkerElement element);
+
+}

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/ITextMarkerExtension.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/ITextMarkerExtension.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/ITextMarkerNumberFunctionExtension.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/ITextMarkerNumberFunctionExtension.java?rev=1152824&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/ITextMarkerNumberFunctionExtension.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/ITextMarkerNumberFunctionExtension.java Mon Aug  1 15:24:44 2011
@@ -0,0 +1,15 @@
+package org.apache.uima.tm.textmarker.kernel.extensions;
+
+import java.util.List;
+
+import org.apache.uima.tm.textmarker.kernel.expression.TextMarkerExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.number.NumberFunctionExpression;
+
+import antlr.ANTLRException;
+
+public interface ITextMarkerNumberFunctionExtension extends ITextMarkerExtension {
+
+  NumberFunctionExpression createNumberFunction(String name, List<TextMarkerExpression> args)
+          throws ANTLRException;
+
+}

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/ITextMarkerNumberFunctionExtension.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/ITextMarkerNumberFunctionExtension.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/ITextMarkerStringFunctionExtension.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/ITextMarkerStringFunctionExtension.java?rev=1152824&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/ITextMarkerStringFunctionExtension.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/ITextMarkerStringFunctionExtension.java Mon Aug  1 15:24:44 2011
@@ -0,0 +1,15 @@
+package org.apache.uima.tm.textmarker.kernel.extensions;
+
+import java.util.List;
+
+import org.apache.uima.tm.textmarker.kernel.expression.TextMarkerExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.string.StringFunctionExpression;
+
+import antlr.ANTLRException;
+
+public interface ITextMarkerStringFunctionExtension extends ITextMarkerExtension {
+
+  StringFunctionExpression createStringFunction(String name, List<TextMarkerExpression> args)
+          throws ANTLRException;
+
+}

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/ITextMarkerStringFunctionExtension.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/ITextMarkerStringFunctionExtension.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/ITextMarkerTypeFunctionExtension.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/ITextMarkerTypeFunctionExtension.java?rev=1152824&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/ITextMarkerTypeFunctionExtension.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/ITextMarkerTypeFunctionExtension.java Mon Aug  1 15:24:44 2011
@@ -0,0 +1,15 @@
+package org.apache.uima.tm.textmarker.kernel.extensions;
+
+import java.util.List;
+
+import org.apache.uima.tm.textmarker.kernel.expression.TextMarkerExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.type.TypeFunctionExpression;
+
+import antlr.ANTLRException;
+
+public interface ITextMarkerTypeFunctionExtension extends ITextMarkerExtension {
+
+  TypeFunctionExpression createTypeFunction(String name, List<TextMarkerExpression> args)
+          throws ANTLRException;
+
+}

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/ITextMarkerTypeFunctionExtension.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/ITextMarkerTypeFunctionExtension.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/TextMarkerEngineLoader.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/TextMarkerEngineLoader.java?rev=1152824&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/TextMarkerEngineLoader.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/TextMarkerEngineLoader.java Mon Aug  1 15:24:44 2011
@@ -0,0 +1,54 @@
+package org.apache.uima.tm.textmarker.kernel.extensions;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.uima.analysis_engine.AnalysisEngine;
+import org.apache.uima.resource.ResourceInitializationException;
+import org.apache.uima.util.InvalidXMLException;
+
+public class TextMarkerEngineLoader extends DefaultEngineLoader {
+
+  private Map<String, IEngineLoader> loaders;
+
+  public TextMarkerEngineLoader() {
+    super();
+    loaders = new HashMap<String, IEngineLoader>();
+  }
+
+  @Override
+  public AnalysisEngine loadEngine(String location) throws InvalidXMLException,
+          ResourceInitializationException, IOException {
+    String name = getEngineName(location);
+    AnalysisEngine result = null;
+    IEngineLoader engineLoader = loaders.get(name);
+    if (engineLoader != null) {
+      result = engineLoader.loadEngine(location);
+    } else {
+      result = loadEngineMyself(location);
+    }
+    return result;
+  }
+
+  public void addLoader(String engine, IEngineLoader loader) {
+    loaders.put(engine, loader);
+  }
+
+  private String getEngineName(String location) {
+    File file = new File(location);
+    location = file.getName();
+    String[] split = location.split("[.]");
+    return split[split.length - 2];
+  }
+
+  public boolean isInitialized() {
+    return !loaders.isEmpty();
+  }
+
+  public String[] getKnownEngines() {
+    return loaders.keySet().toArray(new String[0]);
+  }
+
+}

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/TextMarkerEngineLoader.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/TextMarkerEngineLoader.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/TextMarkerExternalFactory.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/TextMarkerExternalFactory.java?rev=1152824&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/TextMarkerExternalFactory.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/TextMarkerExternalFactory.java Mon Aug  1 15:24:44 2011
@@ -0,0 +1,154 @@
+package org.apache.uima.tm.textmarker.kernel.extensions;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.antlr.runtime.Token;
+import org.apache.uima.tm.textmarker.action.AbstractTextMarkerAction;
+import org.apache.uima.tm.textmarker.condition.AbstractTextMarkerCondition;
+import org.apache.uima.tm.textmarker.kernel.expression.TextMarkerExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.bool.BooleanExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.number.NumberExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.string.StringExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.type.TypeExpression;
+
+import antlr.ANTLRException;
+
+public class TextMarkerExternalFactory {
+
+  private Map<String, ITextMarkerConditionExtension> conditionExtensions;
+
+  private Map<String, ITextMarkerActionExtension> actionExtensions;
+
+  private Map<String, ITextMarkerTypeFunctionExtension> typeFunctionExtensions;
+
+  private Map<String, ITextMarkerBooleanFunctionExtension> booleanFunctionExtensions;
+
+  private Map<String, ITextMarkerStringFunctionExtension> stringFunctionExtensions;
+
+  private Map<String, ITextMarkerNumberFunctionExtension> numberFunctionExtensions;
+
+  public TextMarkerExternalFactory() {
+    super();
+    conditionExtensions = new HashMap<String, ITextMarkerConditionExtension>();
+    actionExtensions = new HashMap<String, ITextMarkerActionExtension>();
+    booleanFunctionExtensions = new HashMap<String, ITextMarkerBooleanFunctionExtension>();
+    stringFunctionExtensions = new HashMap<String, ITextMarkerStringFunctionExtension>();
+    numberFunctionExtensions = new HashMap<String, ITextMarkerNumberFunctionExtension>();
+    typeFunctionExtensions = new HashMap<String, ITextMarkerTypeFunctionExtension>();
+  }
+
+  public AbstractTextMarkerCondition createExternalCondition(Token id,
+          List<TextMarkerExpression> args) throws ANTLRException {
+    String name = id.getText();
+    ITextMarkerConditionExtension extension = conditionExtensions.get(name);
+    if (extension != null) {
+      return extension.createCondition(name, args);
+    }
+    // Throw exception
+    return null;
+  }
+
+  public AbstractTextMarkerAction createExternalAction(Token id, List<TextMarkerExpression> args)
+          throws ANTLRException {
+    String name = id.getText();
+    ITextMarkerActionExtension extension = actionExtensions.get(name);
+    if (extension != null) {
+      return extension.createAction(name, args);
+    }
+    // Throw exception
+    return null;
+  }
+
+  public TypeExpression createExternalTypeFunction(Token id, List<TextMarkerExpression> args)
+          throws ANTLRException {
+    String name = id.getText();
+    ITextMarkerTypeFunctionExtension extension = typeFunctionExtensions.get(name);
+    if (extension != null) {
+      return extension.createTypeFunction(name, args);
+    }
+    // Throw exception
+    return null;
+  }
+
+  public BooleanExpression createExternalBooleanFunction(Token id, List<TextMarkerExpression> args)
+          throws ANTLRException {
+    String name = id.getText();
+    ITextMarkerBooleanFunctionExtension extension = booleanFunctionExtensions.get(name);
+    if (extension != null) {
+      return extension.createBooleanFunction(name, args);
+    }
+    // Throw exception
+    return null;
+  }
+
+  public StringExpression createExternalStringFunction(Token id, List<TextMarkerExpression> args)
+          throws ANTLRException {
+    String name = id.getText();
+    ITextMarkerStringFunctionExtension extension = stringFunctionExtensions.get(name);
+    if (extension != null) {
+      return extension.createStringFunction(name, args);
+    }
+    // Throw exception
+    return null;
+  }
+
+  public NumberExpression createExternalNumberFunction(Token id, List<TextMarkerExpression> args)
+          throws ANTLRException {
+    String name = id.getText();
+    ITextMarkerNumberFunctionExtension extension = numberFunctionExtensions.get(name);
+    if (extension != null) {
+      return extension.createNumberFunction(name, args);
+    }
+    // Throw exception
+    return null;
+  }
+
+  public void addExtension(String id, ITextMarkerExtension extension) {
+    if (extension instanceof ITextMarkerActionExtension) {
+      addActionExtension(id, (ITextMarkerActionExtension) extension);
+    } else if (extension instanceof ITextMarkerConditionExtension) {
+      addConditionExtension(id, (ITextMarkerConditionExtension) extension);
+    } else if (extension instanceof ITextMarkerBooleanFunctionExtension) {
+      addBooleanFunctionExtension(id, (ITextMarkerBooleanFunctionExtension) extension);
+    } else if (extension instanceof ITextMarkerStringFunctionExtension) {
+      addStringFunctionExtension(id, (ITextMarkerStringFunctionExtension) extension);
+    } else if (extension instanceof ITextMarkerNumberFunctionExtension) {
+      addNumberFunctionExtension(id, (ITextMarkerNumberFunctionExtension) extension);
+    } else if (extension instanceof ITextMarkerTypeFunctionExtension) {
+      addTypeFunctionExtension(id, (ITextMarkerTypeFunctionExtension) extension);
+    }
+  }
+
+  public void addConditionExtension(String id, ITextMarkerConditionExtension extension) {
+    conditionExtensions.put(id, extension);
+  }
+
+  public void addActionExtension(String id, ITextMarkerActionExtension extension) {
+    actionExtensions.put(id, extension);
+  }
+
+  public void addNumberFunctionExtension(String id, ITextMarkerNumberFunctionExtension extension) {
+    numberFunctionExtensions.put(id, extension);
+  }
+
+  public void addBooleanFunctionExtension(String id, ITextMarkerBooleanFunctionExtension extension) {
+    booleanFunctionExtensions.put(id, extension);
+  }
+
+  public void addStringFunctionExtension(String id, ITextMarkerStringFunctionExtension extension) {
+    stringFunctionExtensions.put(id, extension);
+  }
+
+  public void addTypeFunctionExtension(String id, ITextMarkerTypeFunctionExtension extension) {
+    typeFunctionExtensions.put(id, extension);
+  }
+
+  public boolean isInitialized() {
+    return !actionExtensions.isEmpty() || !conditionExtensions.isEmpty()
+            || !booleanFunctionExtensions.isEmpty() || !numberFunctionExtensions.isEmpty()
+            || !stringFunctionExtensions.isEmpty() || !typeFunctionExtensions.isEmpty();
+  }
+
+}

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/TextMarkerExternalFactory.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/extensions/TextMarkerExternalFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/AbstractRuleElement.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/AbstractRuleElement.java?rev=1152824&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/AbstractRuleElement.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/AbstractRuleElement.java Mon Aug  1 15:24:44 2011
@@ -0,0 +1,40 @@
+package org.apache.uima.tm.textmarker.kernel.rule;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.uima.tm.textmarker.kernel.TextMarkerBlock;
+import org.apache.uima.tm.textmarker.kernel.TextMarkerElement;
+import org.apache.uima.tm.textmarker.kernel.TextMarkerStream;
+import org.apache.uima.tm.textmarker.kernel.rule.quantifier.RuleElementQuantifier;
+import org.apache.uima.tm.textmarker.kernel.type.TextMarkerBasic;
+import org.apache.uima.tm.textmarker.kernel.visitor.InferenceCrowd;
+
+
+public abstract class AbstractRuleElement extends TextMarkerElement implements RuleElement {
+
+  protected RuleElementQuantifier quantifier;
+
+  public AbstractRuleElement(RuleElementQuantifier quantifier) {
+    super();
+    this.quantifier = quantifier;
+  }
+
+  @SuppressWarnings("unchecked")
+  protected final InferenceCrowd emptyCrowd = new InferenceCrowd(Collections.EMPTY_LIST);
+
+  public List<RuleElementMatch> evaluateMatches(List<RuleElementMatch> matches,
+          TextMarkerBlock parent) {
+    return quantifier.evaluateMatches(matches, parent, emptyCrowd);
+  }
+
+  public boolean continueMatch(int index, List<RuleElement> elements, TextMarkerBasic next,
+          RuleElementMatch match, List<RuleElementMatch> matches, TextMarkerStream stream) {
+    return quantifier.continueMatch(index, elements, next, match, matches, stream, emptyCrowd);
+  }
+
+  public RuleElementQuantifier getQuantifier() {
+    return quantifier;
+  }
+
+}

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/AbstractRuleElement.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/AbstractRuleElement.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/ComposedRuleElement.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/ComposedRuleElement.java?rev=1152824&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/ComposedRuleElement.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/ComposedRuleElement.java Mon Aug  1 15:24:44 2011
@@ -0,0 +1,68 @@
+package org.apache.uima.tm.textmarker.kernel.rule;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.uima.cas.FSIterator;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.tm.textmarker.kernel.TextMarkerBlock;
+import org.apache.uima.tm.textmarker.kernel.TextMarkerStream;
+import org.apache.uima.tm.textmarker.kernel.rule.quantifier.RuleElementQuantifier;
+import org.apache.uima.tm.textmarker.kernel.type.TextMarkerBasic;
+import org.apache.uima.tm.textmarker.kernel.visitor.InferenceCrowd;
+
+
+public class ComposedRuleElement extends AbstractRuleElement {
+
+  private List<RuleElement> elements;
+
+  private TextMarkerBlock parent;
+
+  public ComposedRuleElement(List<RuleElement> elements, RuleElementQuantifier quantifier,
+          TextMarkerBlock parent) {
+    super(quantifier);
+    this.elements = elements;
+    this.parent = parent;
+
+  }
+
+  public void apply(RuleMatch matchInfos, TextMarkerStream symbolStream, InferenceCrowd crowd) {
+    for (RuleElement each : elements) {
+      each.apply(matchInfos, symbolStream, crowd);
+    }
+  }
+
+  public List<TextMarkerBasic> getAnchors(TextMarkerStream symbolStream) {
+    return elements.get(0).getAnchors(symbolStream);
+  }
+
+  public FSIterator<AnnotationFS> getAnchors2(TextMarkerStream symbolStream) {
+    return elements.get(0).getAnchors2(symbolStream);
+  }
+
+  public TextMarkerMatcher getMatcher() {
+    return elements.get(0).getMatcher();
+  }
+
+  public TextMarkerBlock getParent() {
+    return parent;
+  }
+
+  public RuleElementMatch match(TextMarkerBasic anchor, TextMarkerStream stream,
+          InferenceCrowd crowd) {
+    RuleElementMatch result = new RuleElementMatch(this);
+    TextMarkerBasic current = anchor;
+    List<RuleElementMatch> innerMatches = new ArrayList<RuleElementMatch>();
+    for (RuleElement each : elements) {
+      RuleElementMatch match = each.match(current, stream, crowd);
+      current = stream.nextAnnotation(match);
+      innerMatches.add(match);
+    }
+    result.setInnerMatches(innerMatches);
+    return result;
+  }
+
+  public List<RuleElement> getElements() {
+    return elements;
+  }
+}

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/ComposedRuleElement.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/ComposedRuleElement.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/DummyFSIterator.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/DummyFSIterator.java?rev=1152824&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/DummyFSIterator.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/DummyFSIterator.java Mon Aug  1 15:24:44 2011
@@ -0,0 +1,75 @@
+package org.apache.uima.tm.textmarker.kernel.rule;
+
+import java.util.NoSuchElementException;
+
+import org.apache.uima.cas.FSIterator;
+import org.apache.uima.cas.FeatureStructure;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.tm.textmarker.kernel.type.TextMarkerBasic;
+
+
+public class DummyFSIterator implements FSIterator<AnnotationFS> {
+
+  boolean valid = true;
+
+  private TextMarkerBasic element;
+
+  public DummyFSIterator(TextMarkerBasic first) {
+    element = first;
+  }
+
+  @Override
+  public FSIterator<AnnotationFS> copy() {
+    return new DummyFSIterator(element);
+  }
+
+  @Override
+  public AnnotationFS get() throws NoSuchElementException {
+    return element;
+  }
+
+  @Override
+  public boolean isValid() {
+    return valid;
+  }
+
+  @Override
+  public void moveTo(FeatureStructure arg0) {
+  }
+
+  @Override
+  public void moveToFirst() {
+    valid = true;
+  }
+
+  @Override
+  public void moveToLast() {
+    valid = true;
+  }
+
+  @Override
+  public void moveToNext() {
+    valid = false;
+  }
+
+  @Override
+  public void moveToPrevious() {
+    valid = false;
+  }
+
+  @Override
+  public boolean hasNext() {
+    return false;
+  }
+
+  @Override
+  public AnnotationFS next() {
+    return null;
+  }
+
+  @Override
+  public void remove() {
+
+  }
+
+}

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/DummyFSIterator.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/DummyFSIterator.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/EvaluatedCondition.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/EvaluatedCondition.java?rev=1152824&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/EvaluatedCondition.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/EvaluatedCondition.java Mon Aug  1 15:24:44 2011
@@ -0,0 +1,55 @@
+package org.apache.uima.tm.textmarker.kernel.rule;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.uima.tm.textmarker.condition.AbstractTextMarkerCondition;
+import org.apache.uima.tm.textmarker.condition.NotCondition;
+
+
+public class EvaluatedCondition {
+
+  private final AbstractTextMarkerCondition condition;
+
+  private final boolean value;
+
+  private final List<EvaluatedCondition> conditions;
+
+  private final List<EvaluatedCondition> noConditions = new ArrayList<EvaluatedCondition>(0);
+
+  public EvaluatedCondition(AbstractTextMarkerCondition condition, boolean value,
+          List<EvaluatedCondition> conditions) {
+    super();
+    this.condition = condition;
+    this.value = value;
+    this.conditions = conditions;
+  }
+
+  public EvaluatedCondition(AbstractTextMarkerCondition condition, boolean value) {
+    super();
+    this.condition = condition;
+    this.value = value;
+    this.conditions = noConditions;
+  }
+
+  public EvaluatedCondition(NotCondition condition, boolean value, EvaluatedCondition eval) {
+    super();
+    this.condition = condition;
+    this.value = value;
+    this.conditions = new ArrayList<EvaluatedCondition>();
+    conditions.add(eval);
+  }
+
+  public AbstractTextMarkerCondition getCondition() {
+    return condition;
+  }
+
+  public boolean isValue() {
+    return value;
+  }
+
+  public List<EvaluatedCondition> getConditions() {
+    return conditions;
+  }
+
+}

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/EvaluatedCondition.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/EvaluatedCondition.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/RuleApply.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/RuleApply.java?rev=1152824&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/RuleApply.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/RuleApply.java Mon Aug  1 15:24:44 2011
@@ -0,0 +1,67 @@
+package org.apache.uima.tm.textmarker.kernel.rule;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.uima.tm.textmarker.kernel.ScriptApply;
+
+
+public class RuleApply extends ScriptApply {
+
+  private int tried = 0;
+
+  private int applied = 0;
+
+  private boolean acceptMatches;
+
+  private List<RuleMatch> list;
+
+  public RuleApply(TextMarkerRule rule) {
+    this(rule, false);
+  }
+
+  public RuleApply(TextMarkerRule rule, boolean remember) {
+    super(rule);
+    list = new ArrayList<RuleMatch>();
+    acceptMatches = remember;
+  }
+
+  public void add(RuleMatch match) {
+    if (match.matched()) {
+      applied++;
+    }
+    tried++;
+    if (acceptMatches) {
+      list.add(match);
+    }
+  }
+
+  public List<RuleMatch> getList() {
+    return list;
+  }
+
+  @Override
+  public String toString() {
+    StringBuilder sb = new StringBuilder();
+    sb.append(((TextMarkerRule) getElement()).getId() + "\t");
+    sb.append(applied + "/" + tried + ":\t");
+    sb.append(getElement().toString());
+    return sb.toString();
+  }
+
+  public int getTried() {
+    return tried;
+  }
+
+  public int getApplied() {
+    return applied;
+  }
+
+  public boolean isAcceptMatches() {
+    return acceptMatches;
+  }
+
+  public void setAcceptMatches(boolean acceptMatches) {
+    this.acceptMatches = acceptMatches;
+  }
+}

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/RuleApply.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/RuleApply.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/RuleElement.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/RuleElement.java?rev=1152824&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/RuleElement.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/RuleElement.java Mon Aug  1 15:24:44 2011
@@ -0,0 +1,32 @@
+package org.apache.uima.tm.textmarker.kernel.rule;
+
+import java.util.List;
+
+import org.apache.uima.cas.FSIterator;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.tm.textmarker.kernel.TextMarkerBlock;
+import org.apache.uima.tm.textmarker.kernel.TextMarkerStream;
+import org.apache.uima.tm.textmarker.kernel.type.TextMarkerBasic;
+import org.apache.uima.tm.textmarker.kernel.visitor.InferenceCrowd;
+
+
+public interface RuleElement {
+
+  void apply(RuleMatch matchInfos, TextMarkerStream symbolStream, InferenceCrowd crowd);
+
+  RuleElementMatch match(TextMarkerBasic currentBasic, TextMarkerStream stream, InferenceCrowd crowd);
+
+  List<RuleElementMatch> evaluateMatches(List<RuleElementMatch> matches, TextMarkerBlock parent);
+
+  List<TextMarkerBasic> getAnchors(TextMarkerStream symbolStream);
+
+  FSIterator<AnnotationFS> getAnchors2(TextMarkerStream symbolStream);
+
+  boolean continueMatch(int index, List<RuleElement> elements, TextMarkerBasic next,
+          RuleElementMatch match, List<RuleElementMatch> matches, TextMarkerStream stream);
+
+  TextMarkerBlock getParent();
+
+  TextMarkerMatcher getMatcher();
+
+}

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/RuleElement.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/RuleElement.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/RuleElementMatch.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/RuleElementMatch.java?rev=1152824&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/RuleElementMatch.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/RuleElementMatch.java Mon Aug  1 15:24:44 2011
@@ -0,0 +1,100 @@
+package org.apache.uima.tm.textmarker.kernel.rule;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.uima.cas.text.AnnotationFS;
+
+public class RuleElementMatch {
+
+  private final RuleElement ruleElement;
+
+  private List<AnnotationFS> textsMatched;
+
+  private boolean conditionsMatched = true;
+
+  private boolean baseConditionMatched = true;
+
+  private List<EvaluatedCondition> conditions;
+
+  private List<RuleElementMatch> innerMatches;
+
+  public RuleElementMatch(RuleElement ruleElement) {
+    super();
+    this.ruleElement = ruleElement;
+    textsMatched = Collections.emptyList();
+  }
+
+  public void setMatchInfo(boolean baseCondition, List<AnnotationFS> texts,
+          List<EvaluatedCondition> conditionList) {
+    baseConditionMatched = baseCondition;
+    textsMatched = texts;
+    conditions = conditionList;
+    conditionsMatched = baseConditionMatched;
+    if (baseConditionMatched) {
+      for (EvaluatedCondition each : conditions) {
+        conditionsMatched &= each.isValue();
+      }
+    }
+  }
+
+  public boolean matched() {
+    return conditionsMatched;
+  }
+
+  public RuleElement getRuleElement() {
+    return ruleElement;
+  }
+
+  public List<AnnotationFS> getTextsMatched() {
+    if (textsMatched.size() > 1) {
+      System.out.println("TEXTMATCHED > 1");
+    }
+    return textsMatched;
+  }
+
+  public List<EvaluatedCondition> getConditions() {
+    return conditions;
+  }
+
+  @Override
+  public String toString() {
+    StringBuilder sb = new StringBuilder();
+    sb.append(matched() + " : ");
+    for (AnnotationFS each : textsMatched) {
+      sb.append(each.getCoveredText());
+    }
+    String string = sb.toString();
+    if (string.length() > 20) {
+      string = string.substring(0, 20) + "...";
+    }
+    return string;
+  }
+
+  public void setMatched(boolean matched) {
+    conditionsMatched = matched;
+  }
+
+  public boolean isBaseConditionMatched() {
+    return baseConditionMatched;
+  }
+
+  public void setInnerMatches(List<RuleElementMatch> innerMatches) {
+    this.innerMatches = innerMatches;
+    textsMatched = new ArrayList<AnnotationFS>();
+    boolean matched = true;
+    for (RuleElementMatch ruleElementMatch : innerMatches) {
+      List<AnnotationFS> list = ruleElementMatch.getTextsMatched();
+      textsMatched.addAll(list);
+      matched &= ruleElementMatch.matched();
+    }
+    baseConditionMatched = matched;
+    conditionsMatched = matched;
+  }
+
+  public List<RuleElementMatch> getInnerMatches() {
+    return innerMatches;
+  }
+
+}

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/RuleElementMatch.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/RuleElementMatch.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/RuleMatch.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/RuleMatch.java?rev=1152824&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/RuleMatch.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/RuleMatch.java Mon Aug  1 15:24:44 2011
@@ -0,0 +1,144 @@
+package org.apache.uima.tm.textmarker.kernel.rule;
+
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.jcas.tcas.Annotation;
+import org.apache.uima.tm.textmarker.action.AbstractTextMarkerAction;
+import org.apache.uima.tm.textmarker.kernel.ScriptApply;
+import org.apache.uima.tm.textmarker.kernel.TextMarkerStream;
+import org.apache.uima.tm.textmarker.kernel.type.TextMarkerBasic;
+
+
+public class RuleMatch {
+
+  private static class RuleElementComparator implements Comparator<RuleElement> {
+    private final TextMarkerRule rule;
+
+    public RuleElementComparator(TextMarkerRule rule) {
+      this.rule = rule;
+    }
+
+    public int compare(RuleElement re1, RuleElement re2) {
+      List<RuleElement> elements = rule.getElements();
+      int i1 = elements.indexOf(re1);
+      int i2 = elements.indexOf(re2);
+      if (i1 == i2)
+        return 0;
+      return i1 < i2 ? -1 : 1;
+    }
+  }
+
+  private boolean matched;
+
+  private TextMarkerBasic first;
+
+  private final TextMarkerRule rule;
+
+  private Map<AbstractTextMarkerAction, ScriptApply> delegateApply;
+
+  private Map<RuleElement, List<RuleElementMatch>> map;
+
+  public RuleMatch(TextMarkerRule rule) {
+    super();
+    this.rule = rule;
+    map = new TreeMap<RuleElement, List<RuleElementMatch>>(new RuleElementComparator(rule));
+    delegateApply = new HashMap<AbstractTextMarkerAction, ScriptApply>(0);
+  }
+
+  public boolean processMatchInfo(RuleElement ruleElement,
+          List<RuleElementMatch> ruleElementMatches, TextMarkerStream stream) {
+    // return true, if you changed the matches -> current basic needs to be set correctly
+    boolean result = false;
+    List<RuleElementMatch> evaluatedMatches = ruleElement.evaluateMatches(ruleElementMatches,
+            ruleElement.getParent());
+    if (evaluatedMatches != null) {
+      ruleElementMatches = evaluatedMatches;
+      result = true;
+    }
+    map.put(ruleElement, ruleElementMatches);
+    matched = evaluatedMatches != null;
+
+    if (first == null && !ruleElementMatches.isEmpty()) {
+      List<AnnotationFS> textsMatched = ruleElementMatches.get(0).getTextsMatched();
+      if (!textsMatched.isEmpty()) {
+        AnnotationFS annotation = textsMatched.get(0);
+        if (annotation instanceof TextMarkerBasic) {
+          first = (TextMarkerBasic) annotation;
+        } else if (annotation.getBegin() == stream.getDocumentAnnotation().getBegin()
+                && annotation.getEnd() == stream.getDocumentAnnotation().getEnd()) {
+          first = stream.getFirstBasicOfAll();
+        } else {
+          first = stream.getFirstBasicInWindow(annotation);
+        }
+      }
+    }
+    return result;
+  }
+
+  public Map<RuleElement, List<RuleElementMatch>> getMatchInfos() {
+    return map;
+  }
+
+  public List<RuleElementMatch> getMatchInfo(TextMarkerRuleElement element) {
+    return map.get(element);
+  }
+
+  public boolean matched() {
+    return matched;
+  }
+
+  public AnnotationFS getMatchedAnnotation(TextMarkerStream stream, List<Integer> indexes) {
+    int begin = Integer.MAX_VALUE;
+    int end = 0;
+    for (RuleElement element : map.keySet()) {
+      int indexOf = rule.getElements().indexOf(element) + 1;
+      if (indexes == null || indexes.isEmpty() || indexes.contains(indexOf)) {
+        for (RuleElementMatch rem : map.get(element)) {
+          List<AnnotationFS> textsMatched = rem.getTextsMatched();
+          if (!textsMatched.isEmpty()) {
+            begin = Math.min(textsMatched.get(0).getBegin(), begin);
+            end = Math.max(textsMatched.get(textsMatched.size() - 1).getEnd(), end);
+          }
+        }
+      }
+    }
+    if (stream.getJCas() != null && end != 0) {
+      Annotation annotation = new Annotation(stream.getJCas());
+      annotation.setBegin(begin);
+      annotation.setEnd(end);
+      return annotation;
+    } else {
+      return null;
+    }
+  }
+
+  @Override
+  public String toString() {
+    StringBuilder result = new StringBuilder();
+    result.append((matched ? "Matched : " : "Not Matched :"));
+    result.append(getMatchInfos());
+    return result.toString();
+  }
+
+  public TextMarkerBasic getFirstBasic() {
+    return first;
+  }
+
+  public final TextMarkerRule getRule() {
+    return rule;
+  }
+
+  public Map<AbstractTextMarkerAction, ScriptApply> getDelegateApply() {
+    return delegateApply;
+  }
+
+  public void addDelegateApply(AbstractTextMarkerAction action, ScriptApply scriptApply) {
+    delegateApply.put(action, scriptApply);
+  }
+
+}

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/RuleMatch.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/RuleMatch.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/TextMarkerLiteralMatcher.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/TextMarkerLiteralMatcher.java?rev=1152824&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/TextMarkerLiteralMatcher.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/TextMarkerLiteralMatcher.java Mon Aug  1 15:24:44 2011
@@ -0,0 +1,67 @@
+package org.apache.uima.tm.textmarker.kernel.rule;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.uima.cas.FSIterator;
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.tm.textmarker.kernel.TextMarkerBlock;
+import org.apache.uima.tm.textmarker.kernel.TextMarkerStream;
+import org.apache.uima.tm.textmarker.kernel.expression.TextMarkerExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.string.StringExpression;
+import org.apache.uima.tm.textmarker.kernel.type.TextMarkerBasic;
+
+
+public class TextMarkerLiteralMatcher implements TextMarkerMatcher {
+
+  private final StringExpression expression;
+
+  public TextMarkerLiteralMatcher(StringExpression expression) {
+    super();
+    this.expression = expression;
+  }
+
+  public List<TextMarkerBasic> getMatchingBasics(TextMarkerStream stream, TextMarkerBlock parent) {
+    List<TextMarkerBasic> result = new ArrayList<TextMarkerBasic>();
+    AnnotationFS windowAnnotation = stream.getDocumentAnnotation();
+    List<TextMarkerBasic> list = stream.getBasicsInWindow(windowAnnotation);
+    for (TextMarkerBasic each : list) {
+      if (each.getCoveredText().equals(expression.getStringValue(parent))) {
+        result.add(each);
+      }
+    }
+    return result;
+  }
+
+  @Override
+  public FSIterator<AnnotationFS> getMatchingBasics2(TextMarkerStream stream, TextMarkerBlock parent) {
+    assert (false);
+    return null;
+  }
+
+  public Type getType(TextMarkerStream stream) {
+    return null;
+  }
+
+  public boolean match(TextMarkerBasic annotation, TextMarkerStream stream, TextMarkerBlock parent) {
+    if (annotation == null) {
+      return false;
+    }
+    return annotation.getCoveredText().equals(expression.getStringValue(parent));
+  }
+
+  @Override
+  public String toString() {
+    return "\"" + expression.toString() + "\"";
+  }
+
+  public TextMarkerExpression getExpression() {
+    return expression;
+  }
+
+  public Type getType(TextMarkerBlock parent, TextMarkerStream stream) {
+    return null;
+  }
+
+}

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/TextMarkerLiteralMatcher.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/TextMarkerLiteralMatcher.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/TextMarkerMatcher.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/TextMarkerMatcher.java?rev=1152824&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/TextMarkerMatcher.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/TextMarkerMatcher.java Mon Aug  1 15:24:44 2011
@@ -0,0 +1,26 @@
+package org.apache.uima.tm.textmarker.kernel.rule;
+
+import java.util.List;
+
+import org.apache.uima.cas.FSIterator;
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.tm.textmarker.kernel.TextMarkerBlock;
+import org.apache.uima.tm.textmarker.kernel.TextMarkerStream;
+import org.apache.uima.tm.textmarker.kernel.expression.TextMarkerExpression;
+import org.apache.uima.tm.textmarker.kernel.type.TextMarkerBasic;
+
+
+public interface TextMarkerMatcher {
+
+  List<TextMarkerBasic> getMatchingBasics(TextMarkerStream stream, TextMarkerBlock parent);
+
+  FSIterator<AnnotationFS> getMatchingBasics2(TextMarkerStream stream, TextMarkerBlock parent);
+
+  boolean match(TextMarkerBasic currentBasic, TextMarkerStream stream, TextMarkerBlock parent);
+
+  Type getType(TextMarkerBlock parent, TextMarkerStream stream);
+
+  TextMarkerExpression getExpression();
+
+}

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/TextMarkerMatcher.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/TextMarkerMatcher.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/TextMarkerRule.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/TextMarkerRule.java?rev=1152824&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/TextMarkerRule.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/TextMarkerRule.java Mon Aug  1 15:24:44 2011
@@ -0,0 +1,129 @@
+package org.apache.uima.tm.textmarker.kernel.rule;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.uima.cas.FSIterator;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.tm.textmarker.kernel.TextMarkerBlock;
+import org.apache.uima.tm.textmarker.kernel.TextMarkerEnvironment;
+import org.apache.uima.tm.textmarker.kernel.TextMarkerStatement;
+import org.apache.uima.tm.textmarker.kernel.TextMarkerStream;
+import org.apache.uima.tm.textmarker.kernel.type.TextMarkerBasic;
+import org.apache.uima.tm.textmarker.kernel.visitor.InferenceCrowd;
+
+
+public class TextMarkerRule extends TextMarkerStatement {
+
+  private final List<RuleElement> elements;
+
+  private final int id;
+
+  public TextMarkerRule(List<RuleElement> elements, TextMarkerBlock parent, int id) {
+    super(parent);
+    this.elements = elements;
+    this.id = id;
+  }
+
+  @Override
+  public RuleApply apply(TextMarkerStream stream, InferenceCrowd crowd) {
+    return apply(stream, crowd, false);
+  }
+
+  public RuleApply apply(TextMarkerStream stream, InferenceCrowd crowd, boolean remember) {
+    RuleApply result = new RuleApply(this, remember);
+    crowd.beginVisit(this, result);
+    List<TextMarkerBasic> anchors = getAnchors(stream);
+    // FSIterator<AnnotationFS> anchors = getAnchors2(stream);
+    for (TextMarkerBasic each : anchors) {
+
+      // while (anchors.isValid()) {
+      TextMarkerBasic currentBasic = each;
+      // TextMarkerBasic currentBasic = (TextMarkerBasic) anchors.get();
+      RuleMatch ruleMatch = new RuleMatch(this);
+      List<RuleElementMatch> ruleElementMatches = new ArrayList<RuleElementMatch>();
+      for (int i = 0; i < elements.size(); i++) {
+        RuleElement re = elements.get(i);
+        // for really lazy rule elements, that don't even want to match anything
+        if (re.continueMatch(i, elements, currentBasic, null, ruleElementMatches, stream)) {
+          RuleElementMatch match = re.match(currentBasic, stream, crowd);
+          ruleElementMatches.add(match);
+          TextMarkerBasic nextBasic = stream.nextAnnotation(match);
+          // AnnotationFS fs1 = anchors.get();
+          if (re.continueMatch(i, elements, nextBasic, match, ruleElementMatches, stream)) {
+            TextMarkerBasic lastBasic = currentBasic;
+            if (nextBasic != null) {
+              i--;
+              currentBasic = nextBasic;
+              continue;
+            } else if (!match.matched()) {
+              nextBasic = lastBasic;
+              ruleElementMatches.remove(ruleElementMatches.size() - 1);
+            }
+          }
+          TextMarkerBasic previousBasic = currentBasic;
+          currentBasic = nextBasic;
+          boolean changedMatches = ruleMatch.processMatchInfo(re, ruleElementMatches, stream);
+          if (!ruleMatch.matched() /* || currentBasic == null */) {
+            break;
+          } else {
+            if (currentBasic == null
+                    && re.continueMatch(i, elements, nextBasic, match, ruleElementMatches, stream)
+                    && stream.nextAnnotation(match) != null) {
+              currentBasic = previousBasic;
+            } else if (currentBasic == null && changedMatches && match.matched()) {
+            } else if (currentBasic == null && changedMatches) {
+              currentBasic = previousBasic;
+            }
+          }
+          ruleElementMatches = new ArrayList<RuleElementMatch>();
+
+        }
+      }
+      if (ruleMatch.matched()) {
+        fireRule(ruleMatch, stream, crowd);
+      }
+      result.add(ruleMatch);
+      // anchors.moveToNext();
+    }
+    crowd.endVisit(this, result);
+    return result;
+  }
+
+  private void fireRule(RuleMatch matchInfos, TextMarkerStream symbolStream, InferenceCrowd crowd) {
+    if (matchInfos.matched()) {
+      Map<RuleElement, List<RuleElementMatch>> map = matchInfos.getMatchInfos();
+      for (RuleElement eachElement : map.keySet()) {
+        eachElement.apply(matchInfos, symbolStream, crowd);
+      }
+    }
+  }
+
+  public List<TextMarkerBasic> getAnchors(TextMarkerStream symbolStream) {
+    return elements.get(0).getAnchors(symbolStream);
+  }
+
+  public FSIterator<AnnotationFS> getAnchors2(TextMarkerStream symbolStream) {
+    return elements.get(0).getAnchors2(symbolStream);
+  }
+
+  @Override
+  public String toString() {
+    return elements.toString();
+  }
+
+  public final List<RuleElement> getElements() {
+    return elements;
+  }
+
+  public int getId() {
+    return id;
+  }
+
+  @Override
+  public TextMarkerEnvironment getEnvironment() {
+    return getParent().getEnvironment();
+  }
+
+}

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/TextMarkerRule.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/TextMarkerRule.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/TextMarkerRuleElement.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/TextMarkerRuleElement.java?rev=1152824&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/TextMarkerRuleElement.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/TextMarkerRuleElement.java Mon Aug  1 15:24:44 2011
@@ -0,0 +1,118 @@
+package org.apache.uima.tm.textmarker.kernel.rule;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.uima.cas.FSIterator;
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.tm.textmarker.action.AbstractTextMarkerAction;
+import org.apache.uima.tm.textmarker.condition.AbstractTextMarkerCondition;
+import org.apache.uima.tm.textmarker.kernel.TextMarkerBlock;
+import org.apache.uima.tm.textmarker.kernel.TextMarkerStream;
+import org.apache.uima.tm.textmarker.kernel.rule.quantifier.RuleElementQuantifier;
+import org.apache.uima.tm.textmarker.kernel.type.TextMarkerBasic;
+import org.apache.uima.tm.textmarker.kernel.visitor.InferenceCrowd;
+
+
+public class TextMarkerRuleElement extends AbstractRuleElement {
+
+  private TextMarkerMatcher matcher;
+
+  private List<AbstractTextMarkerCondition> conditions;
+
+  private List<AbstractTextMarkerAction> actions;
+
+  private TextMarkerBlock parent;
+
+  @SuppressWarnings("unchecked")
+  protected final InferenceCrowd emptyCrowd = new InferenceCrowd(Collections.EMPTY_LIST);
+
+  public TextMarkerRuleElement(TextMarkerMatcher matcher, RuleElementQuantifier quantifier,
+          List<AbstractTextMarkerCondition> conditions, List<AbstractTextMarkerAction> actions,
+          TextMarkerBlock parent) {
+    super(quantifier);
+    this.matcher = matcher;
+    this.conditions = conditions;
+    this.actions = actions;
+    this.parent = parent;
+    if (conditions == null) {
+      this.conditions = new ArrayList<AbstractTextMarkerCondition>();
+    }
+    if (actions == null) {
+      this.actions = new ArrayList<AbstractTextMarkerAction>();
+    }
+  }
+
+  public List<TextMarkerBasic> getAnchors(TextMarkerStream symbolStream) {
+    return matcher.getMatchingBasics(symbolStream, getParent());
+  }
+
+  public FSIterator<AnnotationFS> getAnchors2(TextMarkerStream symbolStream) {
+    return matcher.getMatchingBasics2(symbolStream, getParent());
+  }
+
+  public RuleElementMatch match(TextMarkerBasic currentBasic, TextMarkerStream stream,
+          InferenceCrowd crowd) {
+    RuleElementMatch result = new RuleElementMatch(this);
+    List<EvaluatedCondition> conditionResults = new ArrayList<EvaluatedCondition>(conditions.size());
+
+    boolean matched = true;
+    boolean base = matcher.match(currentBasic, stream, getParent());
+    Type type = matcher.getType(getParent(), stream);
+    // TODO rethink cap init
+    List<AnnotationFS> textsMatched = new ArrayList<AnnotationFS>(1);
+    if (base) {
+      for (AbstractTextMarkerCondition condition : conditions) {
+        crowd.beginVisit(condition, null);
+        EvaluatedCondition eval = condition.eval(currentBasic, type, this, stream, crowd);
+        crowd.endVisit(condition, null);
+        matched &= eval.isValue();
+        conditionResults.add(eval);
+      }
+    }
+    if (currentBasic != null) {
+      textsMatched.add(stream.expandAnchor(currentBasic, type));
+    }
+    result.setMatchInfo(base, textsMatched, conditionResults);
+    return result;
+  }
+
+  public void apply(RuleMatch matchInfos, TextMarkerStream symbolStream, InferenceCrowd crowd) {
+    for (AbstractTextMarkerAction action : actions) {
+      crowd.beginVisit(action, null);
+      action.execute(matchInfos, this, symbolStream, crowd);
+      crowd.endVisit(action, null);
+    }
+  }
+
+  @Override
+  public String toString() {
+    return matcher.toString() + " " + quantifier.getClass().getSimpleName()
+            + (conditions.isEmpty() ? "" : "(" + conditions.toString() + ")" + "\\n")
+            + (actions.isEmpty() ? "" : "{" + actions.toString() + "}");
+  }
+
+  @Override
+  public RuleElementQuantifier getQuantifier() {
+    return quantifier;
+  }
+
+  public TextMarkerMatcher getMatcher() {
+    return matcher;
+  }
+
+  public List<AbstractTextMarkerCondition> getConditions() {
+    return conditions;
+  }
+
+  public List<AbstractTextMarkerAction> getActions() {
+    return actions;
+  }
+
+  public TextMarkerBlock getParent() {
+    return parent;
+  }
+
+}

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/TextMarkerRuleElement.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/TextMarkerRuleElement.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/TextMarkerTypeMatcher.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/TextMarkerTypeMatcher.java?rev=1152824&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/TextMarkerTypeMatcher.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/TextMarkerTypeMatcher.java Mon Aug  1 15:24:44 2011
@@ -0,0 +1,148 @@
+package org.apache.uima.tm.textmarker.kernel.rule;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.uima.cas.ConstraintFactory;
+import org.apache.uima.cas.FSIterator;
+import org.apache.uima.cas.FSTypeConstraint;
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.jcas.tcas.Annotation;
+import org.apache.uima.tm.textmarker.kernel.TextMarkerBlock;
+import org.apache.uima.tm.textmarker.kernel.TextMarkerStream;
+import org.apache.uima.tm.textmarker.kernel.constraint.BasicTypeConstraint;
+import org.apache.uima.tm.textmarker.kernel.expression.TextMarkerExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.type.TypeExpression;
+import org.apache.uima.tm.textmarker.kernel.type.TextMarkerBasic;
+
+
+public class TextMarkerTypeMatcher implements TextMarkerMatcher {
+
+  private final TypeExpression expression;
+
+  public TextMarkerTypeMatcher(TypeExpression expression) {
+    super();
+    this.expression = expression;
+  }
+
+  public FSIterator<AnnotationFS> getMatchingBasics2(TextMarkerStream stream, TextMarkerBlock parent) {
+    String name = getType(parent, stream).getName();
+    if ("uima.tcas.DocumentAnnotation".equals(name)
+            || "uima.tcas.DocumentAnnotation".equals(name)
+            || (stream.getDocumentAnnotationType().getName().equals(name) && stream
+                    .getFirstBasicOfAll().isAnchorOf(name))) {
+      TextMarkerBasic firstBasic = stream.getFirstBasicOfAll();
+      if (firstBasic != null) {
+        return new DummyFSIterator(firstBasic);
+      } else {
+        FSIterator<AnnotationFS> it = stream.getUnfilteredBasicIterator();
+        it.moveToFirst();
+        if (it.isValid()) {
+          TextMarkerBasic first = (TextMarkerBasic) it.get();
+          return new DummyFSIterator(first);
+        }
+      }
+      return new DummyFSIterator(null);
+    } else {
+      FSTypeConstraint anchorConstraint = createAnchorConstraints(parent, stream);
+      FSIterator<AnnotationFS> iterator = stream.getFilteredBasicIterator(anchorConstraint);
+      return iterator;
+    }
+  }
+
+  public List<TextMarkerBasic> getMatchingBasics(TextMarkerStream stream, TextMarkerBlock parent) {
+    List<TextMarkerBasic> result = new ArrayList<TextMarkerBasic>();
+    String name = getType(parent, stream).getName();
+    if ("uima.tcas.DocumentAnnotation".equals(name)
+            || "uima.tcas.DocumentAnnotation".equals(name)
+            || (stream.getDocumentAnnotationType().getName().equals(name) && stream
+                    .getFirstBasicOfAll().isAnchorOf(name))) {
+      TextMarkerBasic firstBasic = stream.getFirstBasicOfAll();
+      if (firstBasic != null) {
+        result.add(firstBasic);
+      } else {
+        FSIterator<AnnotationFS> it = stream.getUnfilteredBasicIterator();
+        it.moveToFirst();
+        if (it.isValid()) {
+          TextMarkerBasic first = (TextMarkerBasic) it.get();
+          result.add(first);
+        }
+      }
+
+    } else {
+      FSTypeConstraint anchorConstraint = createAnchorConstraints(parent, stream);
+      FSIterator<AnnotationFS> iterator = stream.getFilteredBasicIterator(anchorConstraint);
+      iterator.moveToFirst();
+      while (iterator.isValid()) {
+        TextMarkerBasic annotation = (TextMarkerBasic) iterator.get();
+        result.add(annotation);
+        iterator.moveToNext();
+      }
+    }
+    return result;
+  }
+
+  public FSTypeConstraint createAnchorConstraints(TextMarkerBlock block, TextMarkerStream stream) {
+    ConstraintFactory cf = stream.getCas().getConstraintFactory();
+    Type type = getType(block, stream);
+    BasicTypeConstraint anchorConstraint = new BasicTypeConstraint(cf.createTypeConstraint(), type
+            .getName(), null);
+    anchorConstraint.add(type);
+    return anchorConstraint;
+  }
+
+  public List<Annotation> match(List<Annotation> annotations, TextMarkerBlock parent,
+          TextMarkerStream stream) {
+    List<Annotation> result = new ArrayList<Annotation>();
+    for (Annotation annotation : annotations) {
+      if (annotation.getType().equals(getType(parent, stream))) {
+        result.add(annotation);
+      }
+    }
+    return result;
+  }
+
+  public boolean match(TextMarkerBasic annotation, TextMarkerStream stream, TextMarkerBlock parent) {
+    if (annotation == null) {
+      return false;
+    }
+    Type type = getType(parent, stream);
+    String name = type.getName();
+
+    if ("uima.tcas.DocumentAnnotation".equals(name)
+            || stream.getDocumentAnnotationType().getName().equals(name)) {
+      return true;
+    }
+    // if (annotation instanceof TextMarkerBasic) {
+    TextMarkerBasic basic = annotation;
+    return basic.isAnchorOf(name)
+            || stream.getJCas().getTypeSystem().subsumes(type, basic.getType());
+    // }
+    // TypeSystem typeSystem = stream.getJCas().getTypeSystem();
+    // Type basic = stream.getJCas().getCasType(TextMarkerBasic.type);
+    // if (basic != null && typeSystem.subsumes(basic, annotation.getType())) {
+    // TextMarkerBasic b = annotation;
+    // return b.isAnchorOf(name) || b.isPartOf(name);
+    // }
+    // return typeSystem.subsumes(type, annotation.getType());
+  }
+
+  @Override
+  public String toString() {
+    return expression.toString();
+  }
+
+  public TextMarkerExpression getExpression() {
+    return expression;
+  }
+
+  public Type getType(TextMarkerBlock parent, TextMarkerStream stream) {
+    Type type = expression.getType(parent);
+    if ("uima.tcas.DocumentAnnotation".equals(type.getName())) {
+      return stream.getDocumentAnnotationType();
+    }
+    return type;
+  }
+
+}

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/TextMarkerTypeMatcher.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/TextMarkerTypeMatcher.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/quantifier/MinMaxGreedy.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/quantifier/MinMaxGreedy.java?rev=1152824&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/quantifier/MinMaxGreedy.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/quantifier/MinMaxGreedy.java Mon Aug  1 15:24:44 2011
@@ -0,0 +1,65 @@
+package org.apache.uima.tm.textmarker.kernel.rule.quantifier;
+
+import java.util.List;
+
+import org.apache.uima.tm.textmarker.kernel.TextMarkerStatement;
+import org.apache.uima.tm.textmarker.kernel.TextMarkerStream;
+import org.apache.uima.tm.textmarker.kernel.expression.number.NumberExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.number.SimpleNumberExpression;
+import org.apache.uima.tm.textmarker.kernel.rule.RuleElement;
+import org.apache.uima.tm.textmarker.kernel.rule.RuleElementMatch;
+import org.apache.uima.tm.textmarker.kernel.type.TextMarkerBasic;
+import org.apache.uima.tm.textmarker.kernel.visitor.InferenceCrowd;
+
+
+public class MinMaxGreedy implements RuleElementQuantifier {
+
+  private NumberExpression min;
+
+  private NumberExpression max;
+
+  public MinMaxGreedy(NumberExpression min, NumberExpression max, boolean interval) {
+    super();
+    if (!interval) {
+      this.min = min;
+      this.max = min;
+    } else {
+      this.min = min;
+      this.max = max;
+      if (this.max == null) {
+        this.max = new SimpleNumberExpression(Integer.MAX_VALUE);
+      }
+    }
+  }
+
+  public boolean continueMatch(int index, List<RuleElement> elements, TextMarkerBasic next,
+          RuleElementMatch match, List<RuleElementMatch> matches, TextMarkerStream stream,
+          InferenceCrowd crowd) {
+    int minValue = min.getIntegerValue(elements.get(index).getParent());
+    int maxValue = max.getIntegerValue(elements.get(index).getParent());
+    int matchedSize = matches.size();
+    return matchedSize < maxValue
+            || (!match.matched() && matchedSize >= minValue && matchedSize <= maxValue);
+  }
+
+  public List<RuleElementMatch> evaluateMatches(List<RuleElementMatch> matches,
+          TextMarkerStatement element, InferenceCrowd crowd) {
+    int minValue = min.getIntegerValue(element.getParent());
+    int maxValue = max.getIntegerValue(element.getParent());
+    int matchedSize = matches.size();
+    boolean result = matchedSize >= minValue && matchedSize <= maxValue;
+    if (result) {
+      return matches;
+    } else {
+      return null;
+    }
+  }
+
+  public NumberExpression getMin() {
+    return min;
+  }
+
+  public NumberExpression getMax() {
+    return max;
+  }
+}

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/quantifier/MinMaxGreedy.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/quantifier/MinMaxGreedy.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/quantifier/MinMaxReluctant.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/quantifier/MinMaxReluctant.java?rev=1152824&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/quantifier/MinMaxReluctant.java (added)
+++ uima/sandbox/trunk/TextMarker/org.apache.uima.tm.textmarker.engine/src/main/java/org/apache/uima/tm/textmarker/kernel/rule/quantifier/MinMaxReluctant.java Mon Aug  1 15:24:44 2011
@@ -0,0 +1,84 @@
+package org.apache.uima.tm.textmarker.kernel.rule.quantifier;
+
+import java.util.List;
+
+import org.apache.uima.tm.textmarker.kernel.TextMarkerStatement;
+import org.apache.uima.tm.textmarker.kernel.TextMarkerStream;
+import org.apache.uima.tm.textmarker.kernel.expression.number.NumberExpression;
+import org.apache.uima.tm.textmarker.kernel.expression.number.SimpleNumberExpression;
+import org.apache.uima.tm.textmarker.kernel.rule.RuleElement;
+import org.apache.uima.tm.textmarker.kernel.rule.RuleElementMatch;
+import org.apache.uima.tm.textmarker.kernel.type.TextMarkerBasic;
+import org.apache.uima.tm.textmarker.kernel.visitor.InferenceCrowd;
+
+
+public class MinMaxReluctant implements RuleElementQuantifier {
+
+  private NumberExpression min;
+
+  private NumberExpression max;
+
+  public MinMaxReluctant(NumberExpression min, NumberExpression max, boolean interval) {
+    super();
+    if (!interval) {
+      this.min = min;
+      this.max = min;
+    } else {
+      this.min = min;
+      this.max = max;
+      if (this.max == null) {
+        this.max = new SimpleNumberExpression(Integer.MAX_VALUE);
+      }
+    }
+  }
+
+  public NumberExpression getMin() {
+    return min;
+  }
+
+  public NumberExpression getMax() {
+    return max;
+  }
+
+  public boolean continueMatch(int index, List<RuleElement> elements, TextMarkerBasic next,
+          RuleElementMatch match, List<RuleElementMatch> matches, TextMarkerStream stream,
+          InferenceCrowd crowd) {
+    if (next == null)
+      return false;
+    int minValue = min.getIntegerValue(elements.get(index).getParent());
+    int maxValue = max.getIntegerValue(elements.get(index).getParent());
+    int matchedSize = matches.size();
+    boolean result = true;
+    if (index == elements.size() - 1 && matchedSize == minValue) {
+      // reluctant = minimal ... last element needs to match only once.
+      return false;
+    }
+    if (minValue <= matchedSize) {
+      if (index + 1 < elements.size()) {
+        RuleElement element = elements.get(index + 1);
+        RuleElementMatch nextMatch = element.match(next, stream, crowd);
+        if (nextMatch.matched()) {
+          result = false;
+        }
+      }
+    }
+    if (matchedSize >= maxValue) {
+      result = false;
+    }
+    return result;
+
+  }
+
+  public List<RuleElementMatch> evaluateMatches(List<RuleElementMatch> matches,
+          TextMarkerStatement element, InferenceCrowd crowd) {
+    int minValue = min.getIntegerValue(element.getParent());
+    int maxValue = max.getIntegerValue(element.getParent());
+    int matchedSize = matches.size();
+    boolean result = matchedSize >= minValue && matchedSize <= maxValue;
+    if (result) {
+      return matches;
+    } else {
+      return null;
+    }
+  }
+}