Author: pkluegl
Date: Mon Jul  9 15:45:31 2012
New Revision: 1359228

URL: http://svn.apache.org/viewvc?rev=1359228&view=rev
Log:
UIMA-2331
- enabled matching on string literals, also for disjunctive expressions

Added:
    
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/antlr3/org/apache/uima/textmarker/parser/TextMarkerLexer.tokens
    
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/rule/TextMarkerDisjunctiveMatcher.java
      - copied, changed from r1357559, 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/rule/TextMarkerDisjunctiveTypeMatcher.java
    
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/LiteralStringMatchTest.java
    
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/LiteralStringMatchTest.tm
    
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/LiteralStringMatchTest.txt
Removed:
    
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/rule/TextMarkerDisjunctiveTypeMatcher.java
Modified:
    uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-caseditor/   (props 
changed)
    uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/   (props changed)
    
uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/antlr3/org/apache/uima/textmarker/ide/core/parser/TextMarkerParser.g
    
uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/formatter/TextMarkerFormatter.java
    uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/   (props 
changed)
    
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/antlr3/org/apache/uima/textmarker/parser/TextMarkerParser.g
    
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/TextMarkerScriptFactory.java
    
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/TextMarkerStream.java
    
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/expression/string/SimpleStringExpression.java
    
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/rule/TextMarkerLiteralMatcher.java
    
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/verbalize/ScriptVerbalizer.java

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-caseditor/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Jul  9 15:45:31 2012
@@ -0,0 +1,4 @@
+.settings
+.classpath
+.project
+META-INF

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-engine/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Jul  9 15:45:31 2012
@@ -0,0 +1,5 @@
+.settings
+target
+.classpath
+.project
+META-INF

Modified: 
uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/antlr3/org/apache/uima/textmarker/ide/core/parser/TextMarkerParser.g
URL: 
http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/antlr3/org/apache/uima/textmarker/ide/core/parser/TextMarkerParser.g?rev=1359228&r1=1359227&r2=1359228&view=diff
==============================================================================
--- 
uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/antlr3/org/apache/uima/textmarker/ide/core/parser/TextMarkerParser.g
 (original)
+++ 
uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/antlr3/org/apache/uima/textmarker/ide/core/parser/TextMarkerParser.g
 Mon Jul  9 15:45:31 2012
@@ -592,9 +592,14 @@ ruleElementComposed returns [ComposedRul
        :
        LPAREN
         
-       ((ruleElementType VBAR)=> re1 = ruleElementType {disjunctive = true; 
res = new ArrayList<Expression>(); res.add(re1);} 
-       VBAR re2 = ruleElementType {res.add(re2);}
-       (VBAR re3 = ruleElementType {res.add(re3);})*
+       (((ruleElementType | ruleElementLiteral) VBAR)=>  (re11 
=ruleElementType| re12 = ruleElementLiteral) 
+       {disjunctive = true; res = new ArrayList<Expression>(); if(re11!=null) 
res.add(re11);if(re12!=null) res.add(re12);} 
+       VBAR (re21 = ruleElementType| re22 = ruleElementLiteral) 
+       { if(re21!=null) res.add(re21);if(re22!=null) res.add(re22);}
+       (
+       VBAR (re31 = ruleElementType| re32 = ruleElementLiteral) 
+       { if(re31!=null) res.add(re31);if(re32!=null) res.add(re32);}
+       )*
         |(ruleElements)=>res = ruleElements)
        
        RPAREN q = quantifierPart? (LCURLY c = conditions? (THEN a = actions)? 
RCURLY)?

Modified: 
uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/formatter/TextMarkerFormatter.java
URL: 
http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/formatter/TextMarkerFormatter.java?rev=1359228&r1=1359227&r2=1359228&view=diff
==============================================================================
--- 
uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/formatter/TextMarkerFormatter.java
 (original)
+++ 
uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-ide/src/main/java/org/apache/uima/textmarker/ide/formatter/TextMarkerFormatter.java
 Mon Jul  9 15:45:31 2012
@@ -78,7 +78,7 @@ public class TextMarkerFormatter extends
     String input = source;
     // TODO implement useful format for code snippets
     // final String input = source.substring(offset, offset + length);
-    if (input == "") {
+    if (input.equals("")) {
       return null;
     }
     TextMarkerSourceParser tmsp = new TextMarkerSourceParser();

Propchange: uima/sandbox/trunk/TextMarker/uimaj-ep-textmarker-textruler/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Jul  9 15:45:31 2012
@@ -0,0 +1,4 @@
+.settings
+.classpath
+.project
+META-INF

Added: 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/antlr3/org/apache/uima/textmarker/parser/TextMarkerLexer.tokens
URL: 
http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/antlr3/org/apache/uima/textmarker/parser/TextMarkerLexer.tokens?rev=1359228&view=auto
==============================================================================
--- 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/antlr3/org/apache/uima/textmarker/parser/TextMarkerLexer.tokens
 (added)
+++ 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/antlr3/org/apache/uima/textmarker/parser/TextMarkerLexer.tokens
 Mon Jul  9 15:45:31 2012
@@ -0,0 +1,151 @@
+STAR=138
+FloatTypeSuffix=113
+OctalLiteral=111
+LOG=37
+CONTAINS=8
+REMOVE=65
+GREATEREQUAL=151
+MARKFAST=41
+MATCHEDTEXT=71
+CONDITION=91
+COUNT=14
+LOGN=100
+DYNAMICANCHORING=57
+NOT=63
+Identifier=123
+ACTION=92
+NOTEQUAL=148
+CLEAR=73
+VBAR=140
+DOUBLELIST=95
+ENDSWITH=62
+RPAREN=125
+CREATE=31
+GREATER=143
+SIN=101
+EXP=99
+CURRENTCOUNT=16
+COS=102
+TAN=103
+TYPELIST=98
+FloatString=86
+LESS=142
+REGEXP=25
+GET=68
+PARTOF=22
+UNMARK=53
+LAST=18
+COMMENT=153
+REMOVEDUPLICATE=66
+UNMARKALL=54
+RBRACK=127
+NEAR=20
+LINE_COMMENT=154
+IntegerTypeSuffix=108
+MARKSCORE=39
+REMOVESTRING=72
+TRANSFER=55
+LCURLY=128
+TRIE=7
+FILTERTYPE=46
+STRINGLIST=97
+MARKONCE=40
+ScriptString=79
+EngineString=80
+WS=152
+WORDTABLE=11
+WORDLIST=10
+AutomataBlockString=82
+FloatingPointLiteral=114
+INTLIST=94
+OR=21
+JavaIDDigit=122
+FLOATLIST=96
+CALL=47
+Annotation=5
+FALSE=106
+LESSEQUAL=150
+RessourceLiteral=118
+VOTE=27
+Letter=121
+EscapeSequence=115
+SIZE=70
+BasicAnnotationType=75
+LBRACK=126
+CharacterLiteral=116
+DEL=36
+ATTRIBUTE=34
+TypeString=83
+Exponent=112
+ASSIGN_EQUAL=144
+RETAINTYPE=45
+AND=12
+TypeSystemString=89
+EXPAND=56
+BlockString=81
+IntString=84
+HexDigit=107
+COLOR=35
+LPAREN=124
+POSITION=24
+IF=28
+AT=131
+LogLevel=76
+CONFIGURE=49
+SLASH=139
+THEN=74
+FILL=33
+COMMA=134
+IS=60
+AMPER=141
+REPLACE=44
+GETLIST=69
+EQUAL=147
+GATHER=32
+INLIST=17
+PLUS=136
+BooleanString=88
+GETFEATURE=52
+DOT=132
+ListIdentifier=6
+PARTOFNEQ=23
+BOOLEANLIST=93
+ADD=64
+MARKTABLE=42
+HexLiteral=109
+XOR=104
+PERCENT=145
+MARK=38
+PARSE=30
+PackageString=78
+OldColor=77
+MARKLAST=43
+MERGE=67
+CONTEXTCOUNT=13
+BEFORE=58
+EXEC=48
+MINUS=137
+AFTER=59
+DecimalLiteral=110
+SEMI=135
+TRUE=105
+FEATURE=29
+SymbolString=90
+COLON=133
+StringLiteral=117
+StringString=87
+SCORE=26
+QUESTION=146
+UnicodeEscape=119
+RCURLY=129
+STARTSWITH=61
+ASSIGN=50
+TOTALCOUNT=15
+DECLARE=9
+DocComment=4
+MOFN=19
+OctalEscape=120
+SETFEATURE=51
+DoubleString=85
+CIRCUMFLEX=130
+ALT_NOTEQUAL=149

Modified: 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/antlr3/org/apache/uima/textmarker/parser/TextMarkerParser.g
URL: 
http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/antlr3/org/apache/uima/textmarker/parser/TextMarkerParser.g?rev=1359228&r1=1359227&r2=1359228&view=diff
==============================================================================
--- 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/antlr3/org/apache/uima/textmarker/parser/TextMarkerParser.g
 (original)
+++ 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/antlr3/org/apache/uima/textmarker/parser/TextMarkerParser.g
 Mon Jul  9 15:45:31 2012
@@ -522,15 +522,20 @@ ruleElement[RuleElementContainer contain
 
 ruleElementDisjunctive [RuleElementContainer container] returns 
[TextMarkerRuleElement re = null]
 @init{
-       List<TypeExpression> typeExprs = new ArrayList<TypeExpression>();
+       List<TextMarkerExpression> exprs = new 
ArrayList<TextMarkerExpression>();
 }
     :
     LPAREN
-    (typeExpression VBAR)=>type1 = typeExpression {typeExprs.add(type1);} 
-    VBAR type2 = typeExpression{typeExprs.add(type2);} 
-    (VBAR type3 = typeExpression{typeExprs.add(type3);})?
+    ((typeExpression | simpleStringExpression) VBAR)=>  (e11 =typeExpression | 
e12 =simpleStringExpression) 
+    {if(e11 != null) exprs.add(e11);if(e12 != null) exprs.add(e12);} 
+    VBAR (e21 =typeExpression | e22 =simpleStringExpression) 
+    {if(e21 != null) exprs.add(e21);if(e22 != null) exprs.add(e22);} 
+    (
+    VBAR  (e31 =typeExpression | e32 =simpleStringExpression) 
+    {if(e31 != null) exprs.add(e31);if(e32 != null) exprs.add(e32);} 
+    )*
     RPAREN
-     { re = factory.createRuleElement(typeExprs, null, null, null, container, 
$blockDeclaration::env);}   
+     { re = factory.createRuleElement(exprs, null, null, null, container, 
$blockDeclaration::env);}   
     
      q = quantifierPart? 
         (LCURLY c = conditions? (THEN a = actions)? RCURLY)?

Modified: 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/TextMarkerScriptFactory.java
URL: 
http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/TextMarkerScriptFactory.java?rev=1359228&r1=1359227&r2=1359228&view=diff
==============================================================================
--- 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/TextMarkerScriptFactory.java
 (original)
+++ 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/TextMarkerScriptFactory.java
 Mon Jul  9 15:45:31 2012
@@ -26,6 +26,7 @@ import org.antlr.runtime.Token;
 import org.apache.uima.resource.metadata.TypeSystemDescription;
 import org.apache.uima.textmarker.action.AbstractTextMarkerAction;
 import org.apache.uima.textmarker.condition.AbstractTextMarkerCondition;
+import org.apache.uima.textmarker.expression.TextMarkerExpression;
 import org.apache.uima.textmarker.expression.number.NumberExpression;
 import org.apache.uima.textmarker.expression.string.StringExpression;
 import org.apache.uima.textmarker.expression.type.SimpleTypeExpression;
@@ -34,7 +35,7 @@ import org.apache.uima.textmarker.rule.C
 import org.apache.uima.textmarker.rule.RuleElement;
 import org.apache.uima.textmarker.rule.RuleElementContainer;
 import org.apache.uima.textmarker.rule.RuleElementIsolator;
-import org.apache.uima.textmarker.rule.TextMarkerDisjunctiveTypeMatcher;
+import org.apache.uima.textmarker.rule.TextMarkerDisjunctiveMatcher;
 import org.apache.uima.textmarker.rule.TextMarkerLiteralMatcher;
 import org.apache.uima.textmarker.rule.TextMarkerRule;
 import org.apache.uima.textmarker.rule.TextMarkerRuleElement;
@@ -114,16 +115,15 @@ public class TextMarkerScriptFactory {
           RuleElementQuantifier quantifier, List<AbstractTextMarkerCondition> 
conditions,
           List<AbstractTextMarkerAction> actions, RuleElementContainer 
container,
           TextMarkerBlock parent) {
-
     TextMarkerTypeMatcher matcher = new TextMarkerTypeMatcher(typeExpression);
     return new TextMarkerRuleElement(matcher, quantifier, conditions, actions, 
container, parent);
   }
 
-  public TextMarkerRuleElement createRuleElement(List<TypeExpression> 
typeExprs,
+  public TextMarkerRuleElement createRuleElement(List<TextMarkerExpression> 
exprs,
           RuleElementQuantifier quantifier, List<AbstractTextMarkerCondition> 
conditions,
           List<AbstractTextMarkerAction> actions, RuleElementContainer 
container,
           TextMarkerBlock parent) {
-    TextMarkerDisjunctiveTypeMatcher matcher = new 
TextMarkerDisjunctiveTypeMatcher(typeExprs);
+    TextMarkerDisjunctiveMatcher matcher = new 
TextMarkerDisjunctiveMatcher(exprs);
     return new TextMarkerRuleElement(matcher, quantifier, conditions, actions, 
container, parent);
   }
 

Modified: 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/TextMarkerStream.java
URL: 
http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/TextMarkerStream.java?rev=1359228&r1=1359227&r2=1359228&view=diff
==============================================================================
--- 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/TextMarkerStream.java
 (original)
+++ 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/TextMarkerStream.java
 Mon Jul  9 15:45:31 2012
@@ -442,6 +442,26 @@ public class TextMarkerStream extends FS
     // return result;
   }
 
+  public TextMarkerBasic getBasicNextTo(boolean before, AnnotationFS 
annotation) {
+    if(before) {
+      TextMarkerBasic pointer = beginAnchors.get(annotation.getBegin());
+      moveTo(pointer);
+      moveToPrevious();
+      if(isValid()) {
+        return (TextMarkerBasic)get();
+      }
+    } else {
+      TextMarkerBasic pointer = endAnchors.get(annotation.getEnd());
+      moveTo(pointer);
+      moveToNext();
+      if(isValid()) {
+        return (TextMarkerBasic)get();
+      }
+    }
+    return null;
+  }
+  
+  
   public List<TextMarkerBasic> getBasicsInWindow(AnnotationFS 
windowAnnotation) {
     List<TextMarkerBasic> result = new ArrayList<TextMarkerBasic>();
     if (windowAnnotation instanceof TextMarkerBasic) {

Modified: 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/expression/string/SimpleStringExpression.java
URL: 
http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/expression/string/SimpleStringExpression.java?rev=1359228&r1=1359227&r2=1359228&view=diff
==============================================================================
--- 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/expression/string/SimpleStringExpression.java
 (original)
+++ 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/expression/string/SimpleStringExpression.java
 Mon Jul  9 15:45:31 2012
@@ -15,7 +15,7 @@
  * KIND, either express or implied.  See the License for the
  * specific language governing permissions and limitations
  * under the License.
-*/
+ */
 
 package org.apache.uima.textmarker.expression.string;
 
@@ -47,4 +47,8 @@ public class SimpleStringExpression exte
     return value;
   }
 
+  public String toString() {
+    return value;
+  }
+
 }

Copied: 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/rule/TextMarkerDisjunctiveMatcher.java
 (from r1357559, 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/rule/TextMarkerDisjunctiveTypeMatcher.java)
URL: 
http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/rule/TextMarkerDisjunctiveMatcher.java?p2=uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/rule/TextMarkerDisjunctiveMatcher.java&p1=uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/rule/TextMarkerDisjunctiveTypeMatcher.java&r1=1357559&r2=1359228&rev=1359228&view=diff
==============================================================================
--- 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/rule/TextMarkerDisjunctiveTypeMatcher.java
 (original)
+++ 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/rule/TextMarkerDisjunctiveMatcher.java
 Mon Jul  9 15:45:31 2012
@@ -20,49 +20,97 @@
 package org.apache.uima.textmarker.rule;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 
 import org.apache.uima.cas.Type;
+import org.apache.uima.cas.text.AnnotationFS;
 import org.apache.uima.textmarker.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.expression.type.TypeExpression;
 
-public class TextMarkerDisjunctiveTypeMatcher extends TextMarkerTypeMatcher {
-  private final List<TypeExpression> expressions;
-
-  public TextMarkerDisjunctiveTypeMatcher(List<TypeExpression> expressions) {
-    super(null);
+public class TextMarkerDisjunctiveMatcher implements TextMarkerMatcher {
+  private final List<TextMarkerExpression> expressions;
+  
+  private List<TextMarkerMatcher> matchers ;
+  
+  public TextMarkerDisjunctiveMatcher(List<TextMarkerExpression> expressions) {
+    super();
     this.expressions = expressions;
+    matchers = new ArrayList<TextMarkerMatcher>();
+    for (TextMarkerExpression each : expressions) {
+      if(each instanceof TypeExpression) {
+        matchers.add(new TextMarkerTypeMatcher((TypeExpression) each));
+      } else if(each instanceof StringExpression) {
+        matchers.add(new TextMarkerLiteralMatcher((StringExpression) each));
+      }
+    }
+    
+    
+  }
+
+  public Collection<AnnotationFS> getMatchingAnnotations(TextMarkerStream 
stream,
+          TextMarkerBlock parent) {
+    Collection<AnnotationFS> result = new ArrayList<AnnotationFS>();
+    for (TextMarkerMatcher each : matchers) {
+      result.addAll(each.getMatchingAnnotations(stream, parent));
+    }
+    return result;
+  }
+
+  public boolean match(AnnotationFS annotation, TextMarkerStream stream, 
TextMarkerBlock parent) {
+    for (TextMarkerMatcher each : matchers) {
+      boolean match = each.match(annotation, stream, parent);
+      if(match) {
+        return true;
+      }
+    }
+    return false;
   }
 
-  @Override
   public List<Type> getTypes(TextMarkerBlock parent, TextMarkerStream stream) {
     List<Type> result = new ArrayList<Type>();
-    for (TypeExpression expr : expressions) {
-      Type type = getType(expr, parent, stream);
-      result.add(type);
+    for (TextMarkerMatcher each : matchers) {
+      result.addAll(each.getTypes(parent, stream));
     }
     return result;
   }
 
-  @Override
+  public TextMarkerExpression getExpression() {
+    return null;
+  }
+
   public int estimateAnchors(TextMarkerBlock parent, TextMarkerStream stream) {
-    int count = 0;
-    List<Type> types = getTypes(parent, stream);
-    for (Type type : types) {
-      count += stream.getHistogram(type);
+    int result = 0;
+    for (TextMarkerMatcher each : matchers) {
+      result += each.estimateAnchors(parent, stream);
+    }
+    return result;
+  }
 
+  public Collection<AnnotationFS> getAnnotationsAfter(TextMarkerRuleElement 
ruleElement,
+          AnnotationFS annotation, TextMarkerStream stream, TextMarkerBlock 
parent) {
+    Collection<AnnotationFS> result = new ArrayList<AnnotationFS>();
+    for (TextMarkerMatcher each : matchers) {
+      result.addAll(each.getAnnotationsAfter(ruleElement, annotation, stream, 
parent));
     }
-    return count;
+    return result;
   }
 
-  @Override
-  public String toString() {
-    return expressions.toString();
+  public Collection<AnnotationFS> getAnnotationsBefore(TextMarkerRuleElement 
ruleElement,
+          AnnotationFS annotation, TextMarkerStream stream, TextMarkerBlock 
parent) {
+    Collection<AnnotationFS> result = new ArrayList<AnnotationFS>();
+    for (TextMarkerMatcher each : matchers) {
+      result.addAll(each.getAnnotationsBefore(ruleElement, annotation, stream, 
parent));
+    }
+    return result;
   }
 
-  public List<TypeExpression> getExpressions() {
+  public List<TextMarkerExpression> getExpressions() {
     return expressions;
   }
 
+ 
 }

Modified: 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/rule/TextMarkerLiteralMatcher.java
URL: 
http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/rule/TextMarkerLiteralMatcher.java?rev=1359228&r1=1359227&r2=1359228&view=diff
==============================================================================
--- 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/rule/TextMarkerLiteralMatcher.java
 (original)
+++ 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/rule/TextMarkerLiteralMatcher.java
 Mon Jul  9 15:45:31 2012
@@ -72,18 +72,32 @@ public class TextMarkerLiteralMatcher im
     return Integer.MAX_VALUE;
   }
 
-  public List<AnnotationFS> getAnnotationsAfter(TextMarkerRuleElement 
ruleElement,
+  public Collection<AnnotationFS> getAnnotationsAfter(TextMarkerRuleElement 
ruleElement,
           AnnotationFS annotation, TextMarkerStream stream, TextMarkerBlock 
parent) {
-    return null;
+    return getNextAnnotations(false, annotation, stream, parent);
   }
 
   public Collection<AnnotationFS> getAnnotationsBefore(TextMarkerRuleElement 
ruleElement,
           AnnotationFS annotation, TextMarkerStream stream, TextMarkerBlock 
parent) {
-    return null;
+    return getNextAnnotations(true, annotation, stream, parent);
+  }
+
+  private Collection<AnnotationFS> getNextAnnotations(boolean before, 
AnnotationFS annotation, TextMarkerStream stream,
+          TextMarkerBlock parent) {
+    List<AnnotationFS> result = new ArrayList<AnnotationFS>(1);
+    TextMarkerBasic basicNextTo = stream.getBasicNextTo(before, annotation);
+    if(basicNextTo == null) { 
+      return result;
+    }
+    String stringValue = expression.getStringValue(parent);
+    if(stringValue.equals(basicNextTo.getCoveredText())) {
+      result.add(basicNextTo);
+    }
+    return result;
   }
 
   public List<Type> getTypes(TextMarkerBlock parent, TextMarkerStream stream) {
-    return null;
+    return new ArrayList<Type>();
   }
 
 }

Modified: 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/verbalize/ScriptVerbalizer.java
URL: 
http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/verbalize/ScriptVerbalizer.java?rev=1359228&r1=1359227&r2=1359228&view=diff
==============================================================================
--- 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/verbalize/ScriptVerbalizer.java
 (original)
+++ 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/main/java/org/apache/uima/textmarker/verbalize/ScriptVerbalizer.java
 Mon Jul  9 15:45:31 2012
@@ -27,10 +27,11 @@ import org.apache.uima.textmarker.TextMa
 import org.apache.uima.textmarker.TextMarkerStatement;
 import org.apache.uima.textmarker.action.AbstractTextMarkerAction;
 import org.apache.uima.textmarker.condition.AbstractTextMarkerCondition;
+import org.apache.uima.textmarker.expression.TextMarkerExpression;
 import org.apache.uima.textmarker.expression.type.TypeExpression;
 import org.apache.uima.textmarker.rule.ComposedRuleElement;
 import org.apache.uima.textmarker.rule.RuleElement;
-import org.apache.uima.textmarker.rule.TextMarkerDisjunctiveTypeMatcher;
+import org.apache.uima.textmarker.rule.TextMarkerDisjunctiveMatcher;
 import org.apache.uima.textmarker.rule.TextMarkerMatcher;
 import org.apache.uima.textmarker.rule.TextMarkerRule;
 import org.apache.uima.textmarker.rule.TextMarkerRuleElement;
@@ -147,11 +148,11 @@ public class ScriptVerbalizer {
   public String verbalizeMatcher(TextMarkerRuleElement tmre) {
     StringBuilder result = new StringBuilder();
     TextMarkerMatcher matcher = tmre.getMatcher();
-    if (matcher instanceof TextMarkerDisjunctiveTypeMatcher) {
-      TextMarkerDisjunctiveTypeMatcher dmatcher = 
(TextMarkerDisjunctiveTypeMatcher) matcher;
-      List<TypeExpression> expressions = dmatcher.getExpressions();
+    if (matcher instanceof TextMarkerDisjunctiveMatcher) {
+      TextMarkerDisjunctiveMatcher dmatcher = (TextMarkerDisjunctiveMatcher) 
matcher;
+      List<TextMarkerExpression> expressions = dmatcher.getExpressions();
       result.append("(");
-      for (TypeExpression each : expressions) {
+      for (TextMarkerExpression each : expressions) {
         if (expressions.indexOf(each) != 0) {
           result.append(" | ");
         }

Added: 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/LiteralStringMatchTest.java
URL: 
http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/LiteralStringMatchTest.java?rev=1359228&view=auto
==============================================================================
--- 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/LiteralStringMatchTest.java
 (added)
+++ 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/java/org/apache/uima/textmarker/LiteralStringMatchTest.java
 Mon Jul  9 15:45:31 2012
@@ -0,0 +1,146 @@
+/*
+ * Licensed to the Apache Software FoSWation (ASF) SWer 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 SWer 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 SWer 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
+ * SWer the License.
+ */
+
+package org.apache.uima.textmarker;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.FSIterator;
+import org.apache.uima.cas.Type;
+import org.apache.uima.cas.text.AnnotationFS;
+import org.apache.uima.cas.text.AnnotationIndex;
+import org.junit.Test;
+
+public class LiteralStringMatchTest {
+
+  @Test
+  public void test() {
+    String name = this.getClass().getSimpleName();
+    String namespace = 
this.getClass().getPackage().getName().replaceAll("\\.", "/");
+    CAS cas = null;
+    try {
+      cas = TextMarkerTestUtils.process(namespace + "/" + name + ".tm", 
namespace + "/" + name
+              + ".txt", 50);
+    } catch (Exception e) {
+      e.printStackTrace();
+      assert (false);
+    }
+    Type t = null;
+    AnnotationIndex<AnnotationFS> ai = null;
+    FSIterator<AnnotationFS> iterator = null;
+
+ 
+    t = TextMarkerTestUtils.getTestType(cas, 1);
+    ai = cas.getAnnotationIndex(t);
+    assertEquals(4, ai.size());
+    iterator = ai.iterator();
+    assertEquals("CW", iterator.next().getCoveredText());
+    assertEquals("CW", iterator.next().getCoveredText());
+    assertEquals("CW", iterator.next().getCoveredText());
+    assertEquals("CW", iterator.next().getCoveredText());
+
+    t = TextMarkerTestUtils.getTestType(cas, 2);
+    ai = cas.getAnnotationIndex(t);
+    iterator = ai.iterator();
+    assertEquals(1, ai.size());
+    assertEquals("SW", iterator.next().getCoveredText());
+
+    t = TextMarkerTestUtils.getTestType(cas, 3);
+    ai = cas.getAnnotationIndex(t);
+    iterator = ai.iterator();
+    assertEquals(0, ai.size());
+
+   
+    t = TextMarkerTestUtils.getTestType(cas, 6);
+    ai = cas.getAnnotationIndex(t);
+    iterator = ai.iterator();
+    assertEquals(2, ai.size());
+    assertEquals("CW COMMA CW COMMA", iterator.next().getCoveredText());
+    assertEquals("CW COMMA", iterator.next().getCoveredText());
+
+    t = TextMarkerTestUtils.getTestType(cas, 7);
+    ai = cas.getAnnotationIndex(t);
+    iterator = ai.iterator();
+    assertEquals(5, ai.size());
+    assertEquals("CW", iterator.next().getCoveredText());
+    assertEquals("CW", iterator.next().getCoveredText());
+    assertEquals("CW", iterator.next().getCoveredText());
+    assertEquals("SW", iterator.next().getCoveredText());
+    assertEquals("CW", iterator.next().getCoveredText());
+
+    t = TextMarkerTestUtils.getTestType(cas, 8);
+    ai = cas.getAnnotationIndex(t);
+    iterator = ai.iterator();
+    assertEquals(5, ai.size());
+    assertEquals("CW", iterator.next().getCoveredText());
+    assertEquals("CW", iterator.next().getCoveredText());
+    assertEquals("CW SW CW", iterator.next().getCoveredText());
+    assertEquals("SW CW", iterator.next().getCoveredText());
+    assertEquals("CW", iterator.next().getCoveredText());
+
+    t = TextMarkerTestUtils.getTestType(cas, 9);
+    ai = cas.getAnnotationIndex(t);
+    iterator = ai.iterator();
+    assertEquals(2, ai.size());
+    assertEquals("CW COMMA CW COMMA CW", iterator.next().getCoveredText());
+    assertEquals("CW COMMA CW", iterator.next().getCoveredText());
+
+    t = TextMarkerTestUtils.getTestType(cas, 10);
+    ai = cas.getAnnotationIndex(t);
+    iterator = ai.iterator();
+    assertEquals(3, ai.size());
+    assertEquals("CW COMMA CW COMMA CW SW", iterator.next().getCoveredText());
+    assertEquals("CW COMMA CW SW", iterator.next().getCoveredText());
+    assertEquals("CW SW", iterator.next().getCoveredText());
+
+    t = TextMarkerTestUtils.getTestType(cas, 11);
+    ai = cas.getAnnotationIndex(t);
+    iterator = ai.iterator();
+    assertEquals(3, ai.size());
+    assertEquals("CW COMMA CW COMMA CW SW CW PERIOD", 
iterator.next().getCoveredText());
+    assertEquals("CW COMMA CW SW CW PERIOD", iterator.next().getCoveredText());
+    assertEquals("CW SW CW PERIOD", iterator.next().getCoveredText());
+
+    t = TextMarkerTestUtils.getTestType(cas, 13);
+    ai = cas.getAnnotationIndex(t);
+    iterator = ai.iterator();
+    assertEquals(6, ai.size());
+    assertEquals("CW COMMA", iterator.next().getCoveredText());
+    assertEquals("CW COMMA", iterator.next().getCoveredText());
+    assertEquals("CW COMMA", iterator.next().getCoveredText());
+    assertEquals("CW SW", iterator.next().getCoveredText());
+    assertEquals("CW SW", iterator.next().getCoveredText());
+    assertEquals("CW SW", iterator.next().getCoveredText());
+
+    t = TextMarkerTestUtils.getTestType(cas, 14);
+    ai = cas.getAnnotationIndex(t);
+    iterator = ai.iterator();
+    assertEquals(3, ai.size());
+    assertEquals("CW COMMA CW COMMA CW SW", iterator.next().getCoveredText());
+    assertEquals("CW COMMA CW SW", iterator.next().getCoveredText());
+    assertEquals("CW SW", iterator.next().getCoveredText());
+
+
+    if (cas != null) {
+      cas.release();
+    }
+
+  }
+}

Added: 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/LiteralStringMatchTest.tm
URL: 
http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/LiteralStringMatchTest.tm?rev=1359228&view=auto
==============================================================================
--- 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/LiteralStringMatchTest.tm
 (added)
+++ 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/LiteralStringMatchTest.tm
 Mon Jul  9 15:45:31 2012
@@ -0,0 +1,27 @@
+PACKAGE org.apache.uima;
+
+DECLARE 
T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19,T20,T21,T22,T23,T24,T25;
+
+
+"CW"{-> MARK(T1)};
+
+"CW" "SW"{-> MARK(T2)};
+
+"SW" "SW"{-> MARK(T3)};
+
+("CW" "COMMA")+{-> MARK(T6)};
+
+("CW" | "SW"){->MARK(T7)};
+
+("CW" | "SW")+{->MARK(T8)};
+
+("CW" "COMMA")+ "CW"{-> MARK(T9,1,2)};
+
+("CW" ("COMMA" | "SW"))+{-> MARK(T10)};
+
+("CW" ("COMMA" | "SW"))+ "CW" "PERIOD"+{-> MARK(T11,1,2,3)};
+
+("CW" ("COMMA" | "SW"){-> MARK(T12), MARK(T13,1,2)})+{-> MARK(T14)} 
+    "CW" "PERIOD"+;
+
+         
\ No newline at end of file

Added: 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/LiteralStringMatchTest.txt
URL: 
http://svn.apache.org/viewvc/uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/LiteralStringMatchTest.txt?rev=1359228&view=auto
==============================================================================
--- 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/LiteralStringMatchTest.txt
 (added)
+++ 
uima/sandbox/trunk/TextMarker/uimaj-textmarker/src/test/resources/org/apache/uima/textmarker/LiteralStringMatchTest.txt
 Mon Jul  9 15:45:31 2012
@@ -0,0 +1 @@
+CW COMMA CW COMMA CW SW CW PERIOD
\ No newline at end of file


Reply via email to