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

svn commit: r1157040 [16/23] - in /uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine: ./ .settings/ META-INF/ desc/ lib/ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/uima/ src/main/java/org/...

Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/resource/TextMarkerTable.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/resource/TextMarkerTable.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/resource/TextMarkerTable.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/resource/TextMarkerTable.java Fri Aug 12 10:44:04 2011
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+*/
+
+package org.apache.uima.textmarker.resource;
+
+import java.util.List;
+
+public interface TextMarkerTable {
+
+  TextMarkerWordList getWordList(int index);
+
+  String getEntry(int row, int column);
+
+  List<String> getRowWhere(int column, String value);
+
+}

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/resource/TextMarkerTable.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/resource/TextMarkerTable.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/resource/TextMarkerWordList.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/resource/TextMarkerWordList.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/resource/TextMarkerWordList.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/resource/TextMarkerWordList.java Fri Aug 12 10:44:04 2011
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.textmarker.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.textmarker.TextMarkerStream;
+
+public interface TextMarkerWordList {
+
+  boolean contains(String string, boolean ignoreCase, int size, char[] ignoreChars,
+          int maxIgnoreChars);
+
+  boolean containsFragment(String string, boolean ignoreCase, int size, char[] ignoreChars,
+          int maxIgnoreChars);
+
+  Collection<String> contains(String string, boolean ignoreCase, int ignoreLength, boolean edit,
+          double distance, String ignoreToken);
+
+  Collection<String> containsFragment(String string, boolean ignoreCase, int ignoreLength,
+          boolean edit, double distance, String ignoreToken);
+
+  Collection<AnnotationFS> find(TextMarkerStream stream, boolean ignoreCase, int size,
+          char[] ignoreToken, int maxIgnoredTokens);
+
+  Collection<AnnotationFS> find(TextMarkerStream stream, Map<String, Type> typeMap,
+          boolean ignoreCase, int ignoreLength, boolean edit, double distance, String ignoreToken);
+
+}

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/resource/TextMarkerWordList.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/resource/TextMarkerWordList.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/resource/TextNode.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/resource/TextNode.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/resource/TextNode.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/resource/TextNode.java Fri Aug 12 10:44:04 2011
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+*/
+
+package org.apache.uima.textmarker.resource;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class TextNode {
+
+  private char value;
+
+  private boolean isWordEnd;
+
+  private Map<Character, TextNode> children;
+
+  public TextNode() {
+    this.value = ' ';
+    this.isWordEnd = false;
+    this.children = new HashMap<Character, TextNode>();
+  }
+
+  public TextNode(char value, boolean isWordEnd) {
+    this.value = value;
+    this.isWordEnd = isWordEnd;
+    this.children = new HashMap<Character, TextNode>(5);
+  }
+
+  public boolean contains(char c) {
+    if (value == c) {
+      return true;
+    }
+    return false;
+  }
+
+  public void addChild(char c, boolean isWordEnd) {
+    children.put(c, new TextNode(c, isWordEnd));
+  }
+
+  public void addChild(TextNode n) {
+    children.put(n.getValue(), n);
+  }
+
+  public void setWordEnd(boolean b) {
+    this.isWordEnd = b;
+  }
+
+  public TextNode getChildNode(char c) {
+    return children.get(c);
+  }
+
+  public char getValue() {
+    return this.value;
+  }
+
+  public boolean isWordEnd() {
+    return this.isWordEnd;
+  }
+
+  public Map<Character, TextNode> getChildren() {
+    return this.children;
+  }
+}

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/resource/TextNode.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/resource/TextNode.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/resource/TreeWordList.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/resource/TreeWordList.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/resource/TreeWordList.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/resource/TreeWordList.java Fri Aug 12 10:44:04 2011
@@ -0,0 +1,367 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.textmarker.resource;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Scanner;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
+import org.apache.uima.cas.FSIterator;
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.jcas.tcas.Annotation;
+import org.apache.uima.textmarker.TextMarkerStream;
+import org.apache.uima.textmarker.type.TextMarkerBasic;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+import org.xml.sax.XMLReader;
+
+public class TreeWordList implements TextMarkerWordList {
+  private TextNode root;
+
+  private String name;
+
+  /**
+   * Default constructor
+   */
+  public TreeWordList() {
+    this.root = null;
+  }
+
+  /**
+   * Constructs a TreeWordList from a file with path = filename
+   * 
+   * @param filename
+   *          path of the file to create a TextWordList from
+   */
+  public TreeWordList(String pathname) {
+    if (pathname.endsWith(".twl")) {
+      readXML(pathname, "UTF-8");
+    }
+    if (pathname.endsWith(".txt")) {
+      buildNewTree(pathname);
+    }
+    this.name = new File(pathname).getName();
+  }
+
+  public TreeWordList(List<String> data) {
+    buildNewTree(data);
+    name = "local";
+  }
+
+  public void buildNewTree(List<String> data) {
+    this.root = new TextNode();
+    for (String s : data) {
+      addWord(s);
+    }
+  }
+
+  /**
+   * Creates a new Tree in the existing treeWordList from a file with path pathname
+   * 
+   * @param pathname
+   *          Absolut path of the file containing the word for the treeWordList
+   */
+  public void buildNewTree(String pathname) {
+    try {
+      // reading the file
+      File f = new File(pathname);
+      FileInputStream fstream = new FileInputStream(f);
+      Scanner scan = new Scanner(fstream, "UTF-8");
+      // creating a new tree
+      this.root = new TextNode();
+      while (scan.hasNextLine()) {
+        String s = scan.nextLine().trim();
+
+        if (s.endsWith("=")) {
+          s = s.substring(0, s.length() - 1);
+          s = s.trim();
+        }
+        addWord(s);
+      }
+      fstream.close();
+
+    } catch (FileNotFoundException e) {
+      e.printStackTrace();
+    } catch (IOException e) {
+      e.printStackTrace();
+    }
+  }
+
+  /**
+   * Returns the root node of the tree
+   * 
+   * @return the root node
+   */
+  public TextNode getRoot() {
+    return this.root;
+  }
+
+  /**
+   * Add a new String into the TreeWordList
+   * 
+   * @param s
+   *          The String to add
+   */
+  public void addWord(String s) {
+    // Create Nodes from all chars of the strings besides the last one
+    TextNode pointer = root;
+    for (Character each : s.toCharArray()) {
+      if (Character.isWhitespace(each))
+        continue;
+      TextNode childNode = pointer.getChildNode(each);
+      if (childNode == null) {
+        childNode = new TextNode(each, false);
+        pointer.addChild(childNode);
+      }
+      pointer = childNode;
+    }
+    pointer.setWordEnd(s.length() > 0);
+  }
+
+  /**
+   * Checks if TreeWordList contains String s
+   */
+  public boolean contains(String s, boolean ignoreCase, int size, char[] ignoreChars,
+          int maxIgnoreChars) {
+    TextNode pointer = root;
+    return recursiveContains(pointer, s, 0, ignoreCase && s.length() > size, false, ignoreChars,
+            maxIgnoreChars);
+  }
+
+  public boolean containsFragment(String s, boolean ignoreCase, int size, char[] ignoreChars,
+          int maxIgnoreChars) {
+    TextNode pointer = root;
+    return recursiveContains(pointer, s, 0, ignoreCase && s.length() > size, true, ignoreChars,
+            maxIgnoreChars);
+  }
+
+  private boolean recursiveContains(TextNode pointer, String text, int index, boolean ignoreCase,
+          boolean fragment, char[] ignoreChars, int maxIgnoreChars) {
+    if (pointer == null) {
+      return false;
+    }
+    if (index == text.length()) {
+      return fragment || pointer.isWordEnd();
+    }
+    char charAt = text.charAt(index);
+    boolean charAtIgnored = false;
+    if (ignoreChars != null) {
+      for (char each : ignoreChars) {
+        if (each == charAt) {
+          charAtIgnored = true;
+          break;
+        }
+      }
+      charAtIgnored &= index != 0;
+    }
+    int next = ++index;
+
+    if (ignoreCase) {
+      TextNode childNodeL = pointer.getChildNode(Character.toLowerCase(charAt));
+      TextNode childNodeU = pointer.getChildNode(Character.toUpperCase(charAt));
+      if (charAtIgnored && childNodeL == null && childNodeU == null) {
+        return recursiveContains(pointer, text, next, ignoreCase, fragment, ignoreChars,
+                maxIgnoreChars);
+      } else {
+        return recursiveContains(childNodeL, text, next, ignoreCase, fragment, ignoreChars,
+                maxIgnoreChars)
+                | recursiveContains(childNodeU, text, next, ignoreCase, fragment, ignoreChars,
+                        maxIgnoreChars);
+      }
+    } else {
+      TextNode childNode = pointer.getChildNode(charAt);
+      if (charAtIgnored && childNode == null) {
+        return recursiveContains(pointer, text, next, ignoreCase, fragment, ignoreChars,
+                maxIgnoreChars);
+      } else {
+        return recursiveContains(childNode, text, next, ignoreCase, fragment, ignoreChars,
+                maxIgnoreChars);
+      }
+    }
+  }
+
+  public List<AnnotationFS> find(TextMarkerStream stream, boolean ignoreCase, int size,
+          char[] ignoreChars, int maxIgnoredChars) {
+    ArrayList<AnnotationFS> results = new ArrayList<AnnotationFS>();
+    stream.moveToFirst();
+    FSIterator<AnnotationFS> streamPointer = stream.copy();
+    while (stream.isValid()) {
+      TextMarkerBasic anchorBasic = (TextMarkerBasic) stream.get();
+      streamPointer.moveTo(anchorBasic);
+
+      List<TextMarkerBasic> basicsToAdd = new ArrayList<TextMarkerBasic>();
+      basicsToAdd.add(anchorBasic);
+      String text = anchorBasic.getCoveredText();
+      StringBuilder candidate = new StringBuilder(text);
+      // String lastCandidate = candidate.toString();
+      Annotation interResult = null;
+      while (streamPointer.isValid()) {
+        if (containsFragment(candidate.toString(), ignoreCase, size, ignoreChars, maxIgnoredChars)) {
+          streamPointer.moveToNext();
+          if (streamPointer.isValid()) {
+            TextMarkerBasic next = (TextMarkerBasic) streamPointer.get();
+            if (contains(candidate.toString(), ignoreCase, size, ignoreChars, maxIgnoredChars)) {
+              interResult = new Annotation(stream.getJCas(), basicsToAdd.get(0).getBegin(),
+                      basicsToAdd.get(basicsToAdd.size() - 1).getEnd());
+            }
+            // lastCandidate = candidate.toString();
+            candidate.append(next.getCoveredText());
+            basicsToAdd.add(next);
+          } else {
+            tryToCreateAnnotation(stream, ignoreCase, size, results, basicsToAdd,
+                    candidate.toString(), interResult, ignoreChars, maxIgnoredChars);
+          }
+        } else {
+          basicsToAdd.remove(basicsToAdd.size() - 1);
+          tryToCreateAnnotation(stream, ignoreCase, size, results, basicsToAdd,
+                  candidate.toString(), interResult, ignoreChars, maxIgnoredChars);
+          break;
+        }
+
+      }
+      stream.moveToNext();
+    }
+    return results;
+  }
+
+  public List<AnnotationFS> find(TextMarkerStream stream, boolean ignoreCase, int size) {
+    return find(stream, ignoreCase, size, null, 0);
+  }
+
+  private void tryToCreateAnnotation(TextMarkerStream stream, boolean ignoreCase, int size,
+          ArrayList<AnnotationFS> results, List<TextMarkerBasic> basicsToAdd, String lastCandidate,
+          Annotation interResult, char[] ignoreChars, int maxIgnoredChars) {
+    if (basicsToAdd.size() >= 1
+            && contains(lastCandidate, ignoreCase, size, ignoreChars, maxIgnoredChars)) {
+
+      results.add(new Annotation(stream.getJCas(), basicsToAdd.get(0).getBegin(), basicsToAdd.get(
+              basicsToAdd.size() - 1).getEnd()));
+    } else if (interResult != null) {
+      results.add(interResult);
+    }
+  }
+
+  public void readXML(String path, String encoding) {
+    try {
+      FileInputStream input = new FileInputStream(path);
+      InputStreamReader stream = new InputStreamReader(input, encoding);
+      this.root = new TextNode();
+      XMLEventHandler handler = new XMLEventHandler(root);
+      SAXParserFactory factory = SAXParserFactory.newInstance();
+      SAXParser parser = factory.newSAXParser();
+      XMLReader reader = parser.getXMLReader();
+      // XMLReader reader = XMLReaderFactory.createXMLReader();
+      reader.setContentHandler(handler);
+      reader.setErrorHandler(handler);
+      reader.parse(new InputSource(stream));
+    } catch (SAXParseException spe) {
+      StringBuffer sb = new StringBuffer(spe.toString());
+      sb.append("\n  Line number: " + spe.getLineNumber());
+      sb.append("\n Column number: " + spe.getColumnNumber());
+      sb.append("\n Public ID: " + spe.getPublicId());
+      sb.append("\n System ID: " + spe.getSystemId() + "\n");
+      System.out.println(sb.toString());
+    } catch (SAXException se) {
+      System.out.println("loadDOM threw " + se);
+      se.printStackTrace(System.out);
+    } catch (IOException e) {
+      e.printStackTrace();
+    } catch (ParserConfigurationException e) {
+      e.printStackTrace();
+    }
+  }
+
+  public void createXMLFile(String path, String encoding) {
+    try {
+      FileOutputStream output = new FileOutputStream(path);
+      OutputStreamWriter writer = new OutputStreamWriter(output, encoding);
+      writer.write("<?xml version=\"1.0\" ?>");
+      writer.write("<root>");
+      for (TextNode child : root.getChildren().values()) {
+        writeNode(writer, child);
+      }
+      writer.write("</root>");
+      writer.close();
+    } catch (FileNotFoundException e) {
+      e.printStackTrace();
+    } catch (IOException e) {
+      e.printStackTrace();
+    }
+  }
+
+  public void writeNode(Writer writer, TextNode node) {
+    try {
+      String output = "<node char=\"" + node.getValue() + "\" isWordEnd=\""
+              + Boolean.toString(node.isWordEnd()) + "\">";
+      writer.write(output);
+      for (TextNode child : node.getChildren().values()) {
+        writeNode(writer, child);
+
+      }
+      writer.write("</node>");
+    } catch (IOException e) {
+      e.printStackTrace();
+    }
+  }
+
+  @Override
+  public String toString() {
+    return name;
+  }
+
+  public List<AnnotationFS> find(TextMarkerStream stream, Map<String, Type> typeMap,
+          boolean ignoreCase, int ignoreLength, boolean edit, double distance, String ignoreToken) {
+    return null;
+  }
+
+  public List<String> contains(String string, boolean ignoreCase, int ignoreLength, boolean edit,
+          double distance, String ignoreToken) {
+    return null;
+  }
+
+  public List<String> containsFragment(String string, boolean ignoreCase, int ignoreLength,
+          boolean edit, double distance, String ignoreToken) {
+    return null;
+  }
+
+  public void startDocument() {
+
+  }
+
+  public void endDocument() {
+
+  }
+
+}

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/resource/TreeWordList.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/resource/TreeWordList.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/resource/TrieXMLEventHandler.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/resource/TrieXMLEventHandler.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/resource/TrieXMLEventHandler.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/resource/TrieXMLEventHandler.java Fri Aug 12 10:44:04 2011
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+*/
+
+package org.apache.uima.textmarker.resource;
+
+import java.util.Stack;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.helpers.DefaultHandler;
+
+public class TrieXMLEventHandler extends DefaultHandler {
+
+  private Stack<MultiTextNode> stack;
+
+  // boolean listeningState;
+
+  boolean inContent;
+
+  boolean inType;
+
+  public TrieXMLEventHandler(MultiTextNode root) {
+    super();
+    this.stack = new Stack<MultiTextNode>();
+    stack.add(root);
+    // this.listeningState = false;
+  }
+
+  @Override
+  public void startDocument() {
+  }
+
+  @Override
+  public void endDocument() {
+  }
+
+  @Override
+  public void startElement(String namespaceURI, String localName, String qualifiedName,
+          Attributes atts) {
+    if ("n".equals(localName) || "n".equals(qualifiedName)) {
+      // char c = atts.getValue("c").charAt(0);
+      // boolean e = Boolean.valueOf(atts.getValue("e"));
+      MultiTextNode newNode = new MultiTextNode();
+      // newNode.setWordEnd(e);
+      // stack.peek().addChild(newNode);
+      stack.add(newNode);
+      inContent = false;
+      inType = false;
+    }
+    if ("t".equals(localName) || "t".equals(qualifiedName)) {
+      inType = true;
+      inContent = false;
+    }
+    if ("c".equals(localName) || "c".equals(qualifiedName)) {
+      // listeningState = true;
+      inType = false;
+      inContent = true;
+    }
+  }
+
+  @Override
+  public void endElement(String namespaceURI, String localName, String qualifiedName) {
+    if ("n".equals(localName) || "n".equals(qualifiedName)) {
+      MultiTextNode pop = stack.pop();
+      stack.peek().addChild(pop);
+    }
+    if ("t".equals(localName) || "t".equals(qualifiedName)) {
+      inType = false;
+    }
+    if ("c".equals(localName) || "c".equals(qualifiedName)) {
+      inContent = false;
+    }
+  }
+
+  @Override
+  public void characters(char ch[], int start, int length) {
+    // if (listeningState == true) {
+    if (stack.isEmpty()) {
+      return;
+    }
+    MultiTextNode peek = stack.peek();
+    if (inType) {
+      StringBuilder type = new StringBuilder();
+      for (int i = start; i < start + length; i++) {
+        type.append(String.valueOf(ch[i]));
+      }
+      peek.addType(type.toString());
+    } else if (inContent) {
+      if (ch.length > 0) {
+        peek.setValue(ch[0]);
+      } else {
+        peek.setValue(' ');
+      }
+    }
+    // }
+
+  }
+}

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/resource/TrieXMLEventHandler.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/resource/TrieXMLEventHandler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/resource/XMLEventHandler.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/resource/XMLEventHandler.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/resource/XMLEventHandler.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/resource/XMLEventHandler.java Fri Aug 12 10:44:04 2011
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+*/
+
+package org.apache.uima.textmarker.resource;
+
+import java.util.Stack;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.helpers.DefaultHandler;
+
+public class XMLEventHandler extends DefaultHandler {
+
+  Stack<TextNode> stack;
+
+  public XMLEventHandler(TextNode root) {
+    super();
+    stack = new Stack<TextNode>();
+    stack.add(root);
+  }
+
+  @Override
+  public void startDocument() {
+  }
+
+  @Override
+  public void endDocument() {
+  }
+
+  @Override
+  public void startElement(String namespaceURI, String localName, String qualifiedName,
+          Attributes atts) {
+    if ("node".equals(localName) || "node".equals(qualifiedName)) {
+      char c = atts.getValue("char").charAt(0);
+      boolean isWordEnd = Boolean.valueOf(atts.getValue("isWordEnd"));
+      TextNode newNode = new TextNode(c, isWordEnd);
+      stack.peek().addChild(newNode);
+      stack.add(newNode);
+    }
+
+  }
+
+  @Override
+  public void endElement(String namespaceURI, String localName, String qualifiedName) {
+    if ("node".equals(localName) || "node".equals(qualifiedName)) {
+      stack.pop();
+    }
+  }
+
+}

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/resource/XMLEventHandler.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/resource/XMLEventHandler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/AbstractRuleElement.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/AbstractRuleElement.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/AbstractRuleElement.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/AbstractRuleElement.java Fri Aug 12 10:44:04 2011
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+*/
+
+package org.apache.uima.textmarker.rule;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.uima.textmarker.TextMarkerBlock;
+import org.apache.uima.textmarker.TextMarkerElement;
+import org.apache.uima.textmarker.TextMarkerStream;
+import org.apache.uima.textmarker.rule.quantifier.RuleElementQuantifier;
+import org.apache.uima.textmarker.type.TextMarkerBasic;
+import org.apache.uima.textmarker.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/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/AbstractRuleElement.java
------------------------------------------------------------------------------
    svn:executable = *

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

Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/ComposedRuleElement.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/ComposedRuleElement.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/ComposedRuleElement.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/ComposedRuleElement.java Fri Aug 12 10:44:04 2011
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+*/
+
+package org.apache.uima.textmarker.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.textmarker.TextMarkerBlock;
+import org.apache.uima.textmarker.TextMarkerStream;
+import org.apache.uima.textmarker.rule.quantifier.RuleElementQuantifier;
+import org.apache.uima.textmarker.type.TextMarkerBasic;
+import org.apache.uima.textmarker.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/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/ComposedRuleElement.java
------------------------------------------------------------------------------
    svn:executable = *

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

Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/DummyFSIterator.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/DummyFSIterator.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/DummyFSIterator.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/DummyFSIterator.java Fri Aug 12 10:44:04 2011
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.textmarker.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.textmarker.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/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/DummyFSIterator.java
------------------------------------------------------------------------------
    svn:executable = *

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

Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/EvaluatedCondition.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/EvaluatedCondition.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/EvaluatedCondition.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/EvaluatedCondition.java Fri Aug 12 10:44:04 2011
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+*/
+
+package org.apache.uima.textmarker.rule;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.uima.textmarker.condition.AbstractTextMarkerCondition;
+import org.apache.uima.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/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/EvaluatedCondition.java
------------------------------------------------------------------------------
    svn:executable = *

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

Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/RuleApply.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/RuleApply.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/RuleApply.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/RuleApply.java Fri Aug 12 10:44:04 2011
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+*/
+
+package org.apache.uima.textmarker.rule;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.uima.textmarker.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/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/RuleApply.java
------------------------------------------------------------------------------
    svn:executable = *

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

Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/RuleElement.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/RuleElement.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/RuleElement.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/RuleElement.java Fri Aug 12 10:44:04 2011
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+*/
+
+package org.apache.uima.textmarker.rule;
+
+import java.util.List;
+
+import org.apache.uima.cas.FSIterator;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.textmarker.TextMarkerBlock;
+import org.apache.uima.textmarker.TextMarkerStream;
+import org.apache.uima.textmarker.type.TextMarkerBasic;
+import org.apache.uima.textmarker.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/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/RuleElement.java
------------------------------------------------------------------------------
    svn:executable = *

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

Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/RuleElementMatch.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/RuleElementMatch.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/RuleElementMatch.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/RuleElementMatch.java Fri Aug 12 10:44:04 2011
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+*/
+
+package org.apache.uima.textmarker.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/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/RuleElementMatch.java
------------------------------------------------------------------------------
    svn:executable = *

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

Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/RuleMatch.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/RuleMatch.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/RuleMatch.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/RuleMatch.java Fri Aug 12 10:44:04 2011
@@ -0,0 +1,162 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.textmarker.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.textmarker.ScriptApply;
+import org.apache.uima.textmarker.TextMarkerStream;
+import org.apache.uima.textmarker.action.AbstractTextMarkerAction;
+import org.apache.uima.textmarker.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/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/RuleMatch.java
------------------------------------------------------------------------------
    svn:executable = *

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

Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/TextMarkerLiteralMatcher.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/TextMarkerLiteralMatcher.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/TextMarkerLiteralMatcher.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/TextMarkerLiteralMatcher.java Fri Aug 12 10:44:04 2011
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.textmarker.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.textmarker.TextMarkerBlock;
+import org.apache.uima.textmarker.TextMarkerStream;
+import org.apache.uima.textmarker.expression.TextMarkerExpression;
+import org.apache.uima.textmarker.expression.string.StringExpression;
+import org.apache.uima.textmarker.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/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/TextMarkerLiteralMatcher.java
------------------------------------------------------------------------------
    svn:executable = *

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

Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/TextMarkerMatcher.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/TextMarkerMatcher.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/TextMarkerMatcher.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/TextMarkerMatcher.java Fri Aug 12 10:44:04 2011
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.textmarker.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.textmarker.TextMarkerBlock;
+import org.apache.uima.textmarker.TextMarkerStream;
+import org.apache.uima.textmarker.expression.TextMarkerExpression;
+import org.apache.uima.textmarker.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/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/TextMarkerMatcher.java
------------------------------------------------------------------------------
    svn:executable = *

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

Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/TextMarkerRule.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/TextMarkerRule.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/TextMarkerRule.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/TextMarkerRule.java Fri Aug 12 10:44:04 2011
@@ -0,0 +1,148 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+*/
+
+package org.apache.uima.textmarker.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.textmarker.TextMarkerBlock;
+import org.apache.uima.textmarker.TextMarkerEnvironment;
+import org.apache.uima.textmarker.TextMarkerStatement;
+import org.apache.uima.textmarker.TextMarkerStream;
+import org.apache.uima.textmarker.type.TextMarkerBasic;
+import org.apache.uima.textmarker.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/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/TextMarkerRule.java
------------------------------------------------------------------------------
    svn:executable = *

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

Added: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/TextMarkerRuleElement.java
URL: http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/TextMarkerRuleElement.java?rev=1157040&view=auto
==============================================================================
--- uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/TextMarkerRuleElement.java (added)
+++ uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/TextMarkerRuleElement.java Fri Aug 12 10:44:04 2011
@@ -0,0 +1,136 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.textmarker.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.textmarker.TextMarkerBlock;
+import org.apache.uima.textmarker.TextMarkerStream;
+import org.apache.uima.textmarker.action.AbstractTextMarkerAction;
+import org.apache.uima.textmarker.condition.AbstractTextMarkerCondition;
+import org.apache.uima.textmarker.rule.quantifier.RuleElementQuantifier;
+import org.apache.uima.textmarker.type.TextMarkerBasic;
+import org.apache.uima.textmarker.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/uimaj-ep-textmarker-engine/src/main/java/org/apache/uima/textmarker/rule/TextMarkerRuleElement.java
------------------------------------------------------------------------------
    svn:executable = *

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