You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by pk...@apache.org on 2016/01/04 11:33:50 UTC

svn commit: r1722834 [2/9] - in /uima/ruta/trunk: ./ example-projects/ruta-ep-example-extensions/ example-projects/ruta-ep-example-extensions/src/main/java/org/apache/uima/ruta/example/extensions/ ruta-core-ext/src/main/java/org/apache/uima/ruta/block/...

Modified: uima/ruta/trunk/ruta-core/src/main/antlr3/org/apache/uima/ruta/parser/RutaParser.g
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/antlr3/org/apache/uima/ruta/parser/RutaParser.g?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/antlr3/org/apache/uima/ruta/parser/RutaParser.g (original)
+++ uima/ruta/trunk/ruta-core/src/main/antlr3/org/apache/uima/ruta/parser/RutaParser.g Mon Jan  4 10:33:48 2016
@@ -71,6 +71,7 @@ import org.apache.uima.ruta.expression.I
 import org.apache.uima.ruta.expression.MatchReference;
 import org.apache.uima.ruta.expression.feature.FeatureExpression;
 import org.apache.uima.ruta.expression.feature.FeatureMatchExpression;
+import org.apache.uima.ruta.expression.annotation.IAnnotationExpression;
 import org.apache.uima.ruta.expression.bool.IBooleanExpression;
 import org.apache.uima.ruta.expression.list.BooleanListExpression;
 import org.apache.uima.ruta.expression.list.ListExpression;
@@ -82,7 +83,7 @@ import org.apache.uima.ruta.expression.r
 import org.apache.uima.ruta.expression.resource.WordTableExpression;
 import org.apache.uima.ruta.expression.string.IStringExpression;
 import org.apache.uima.ruta.expression.string.StringFunctionFactory;
-import org.apache.uima.ruta.expression.type.TypeExpression;
+import org.apache.uima.ruta.expression.type.ITypeExpression;
 import org.apache.uima.ruta.extensions.RutaExternalFactory;
 import org.apache.uima.ruta.extensions.RutaParseRuntimeException;
 import org.apache.uima.ruta.rule.AbstractRuleElement;
@@ -398,6 +399,9 @@ public void setExternalFactory(RutaExter
       	private boolean isTypeFunctionExtension(String name) {
       	  return external.getTypeFunctionExtensions().keySet().contains(name);
       	}
+      	private boolean isAnnotationFunctionExtension(String name) {
+      	  return external.getAnnotationFunctionExtensions().keySet().contains(name);
+      	}
       	private boolean isBlockExtension(String name) {
       	  return external.getBlockExtensions().keySet().contains(name);
       	}
@@ -544,6 +548,18 @@ List<String> vars = new ArrayList<String
 	type = TYPELIST 
 	{!isVariableOfType($blockDeclaration::env, input.LT(1).getText(), type.getText())}? 
 	name = Identifier (ASSIGN_EQUAL tl = typeListExpression)? SEMI {addVariable($blockDeclaration::env, name.getText(), type.getText());if(tl != null){setValue($blockDeclaration::env, name.getText(), tl);}} 
+	
+	|
+	type = ANNOTATION 
+	{!isVariableOfType($blockDeclaration::env, input.LT(1).getText(), type.getText())}? 
+	name = Identifier (ASSIGN_EQUAL a = annotationExpression)? SEMI {addVariable($blockDeclaration::env, name.getText(), type.getText());if(a != null){setValue($blockDeclaration::env, name.getText(), a);}} 
+	|
+	type = ANNOTATIONLIST
+	{!isVariableOfType($blockDeclaration::env, input.LT(1).getText(), type.getText())}? 
+	name = Identifier (ASSIGN_EQUAL al = annotationExpression)? SEMI {addVariable($blockDeclaration::env, name.getText(), type.getText());if(al != null){setValue($blockDeclaration::env, name.getText(), al);}} 
+	
+	
+	
 	//|
 	//stmt1 = conditionDeclaration {stmt = stmt1;}
 	//|
@@ -747,7 +763,7 @@ options {
 }
 @init{
 	//RegExpRule rer = null;
-	Map<TypeExpression, IRutaExpression> map = new HashMap<TypeExpression, IRutaExpression>();
+	Map<ITypeExpression, IRutaExpression> map = new HashMap<ITypeExpression, IRutaExpression>();
 }
 	: 
 
@@ -771,8 +787,8 @@ options {
 
 regexpRule returns [RegExpRule stmt = null]
 @init{
-	Map<TypeExpression, INumberExpression> map = new HashMap<TypeExpression, INumberExpression>();
-	Map<TypeExpression, Map<IStringExpression, IRutaExpression>> fa = new HashMap<TypeExpression, Map<IStringExpression, IRutaExpression>>();
+	Map<ITypeExpression, INumberExpression> map = new HashMap<ITypeExpression, INumberExpression>();
+	Map<ITypeExpression, Map<IStringExpression, IRutaExpression>> fa = new HashMap<ITypeExpression, Map<IStringExpression, IRutaExpression>>();
 	Map<IStringExpression, IRutaExpression> fmap = null;
 }
 	:
@@ -847,7 +863,8 @@ String label = null;
 	:
 	(l = Identifier {label = l.getText();} COLON)?
 	start = STARTANCHOR? (
-	re1 = ruleElementType[container] {re = re1;}
+	rea = ruleElementAnnotation[container]{re = rea;}
+	|re1 = ruleElementType[container] {re = re1;}
 	| re2 = ruleElementLiteral[container] {re = re2;}
 	| (ruleElementComposed[null])=>re3 = ruleElementComposed[container] {re = re3;}
 	| (ruleElementWildCard[null])=> re5 = ruleElementWildCard[container] {re = re5;}
@@ -947,6 +964,26 @@ ruleElementType [RuleElementContainer co
 	}
     ;
 
+ruleElementAnnotation [RuleElementContainer container] returns [RutaRuleElement re = null]
+    :
+    
+    (annotationAddressExpression)=>aExpr = annotationAddressExpression 
+     {re = factory.createRuleElement(aExpr, null, null, null, container, $blockDeclaration::env);} 
+    q = quantifierPart? 
+        (LCURLY c = conditions? (THEN a = actions)? RCURLY)?
+   {
+	if(q != null) {
+		re.setQuantifier(q);
+	}
+	if(c!= null) {
+		re.setConditions(c);
+	}
+	if(a != null) {
+		re.setActions(a);
+	}
+	}
+    ;
+
 ruleElementLiteral [RuleElementContainer container] returns [RutaRuleElement re = null]
     :
     
@@ -1101,7 +1138,7 @@ typeListExpression returns [TypeListExpr
 
 simpleTypeListExpression returns [TypeListExpression expr = null]
 @init{
-	List<TypeExpression> list = new ArrayList<TypeExpression>();
+	List<ITypeExpression> list = new ArrayList<ITypeExpression>();
 }	:
 	LCURLY (e = simpleTypeExpression {list.add(e);} (COMMA e = simpleTypeExpression {list.add(e);})*)?  RCURLY
 	{expr = ExpressionFactory.createTypeListExpression(list);}
@@ -1114,19 +1151,19 @@ typeMatchExpression returns [IRutaExpres
 options {
 	backtrack = true;
 }
-	:
-	(typeFunction)=> tf = typeFunction {expr = tf;}
+	:	
+	(featureMatchExpression)=> fme = featureMatchExpression {expr = fme;}
 	|
-	(matchReference)=> mr = matchReference {expr = mr;}
+	(typeExpression)=> te = typeExpression {expr = te;}
 	;
 
 matchReference returns [MatchReference mr = null]
 	:
-	ref = dottedId ((comp = LESS | comp = GREATER | comp = GREATEREQUAL | comp = LESSEQUAL |comp =  EQUAL | comp = NOTEQUAL) arg = argument)?
-	{mr = ExpressionFactory.createMatchReference(ref, comp, arg);}
+	ref = dottedId 
+	{mr = ExpressionFactory.createMatchReference(ref);}
 	;
 
-typeExpression returns [TypeExpression type = null]
+typeExpression returns [ITypeExpression type = null]
 options {
 	backtrack = true;
 }
@@ -1137,13 +1174,13 @@ options {
 	
 
 // not checked
-typeFunction returns [TypeExpression expr = null]
+typeFunction returns [ITypeExpression expr = null]
 	:
 	(e = externalTypeFunction)=> e = externalTypeFunction {expr = e;}
 	;
 
 // not checked
-externalTypeFunction returns [TypeExpression expr = null]
+externalTypeFunction returns [ITypeExpression expr = null]
 	:
 	{isTypeFunctionExtension(input.LT(1).getText())}? 
 	id = Identifier LPAREN
@@ -1153,7 +1190,7 @@ externalTypeFunction returns [TypeExpres
 	}
 	;
 
-simpleTypeExpression returns [TypeExpression type = null]
+simpleTypeExpression returns [ITypeExpression type = null]
 	:
 	{isVariableOfType($blockDeclaration::env,input.LT(1).getText(), "TYPE")}? var = Identifier 
 	{type = ExpressionFactory.createReferenceTypeExpression(var);}
@@ -1162,33 +1199,45 @@ simpleTypeExpression returns [TypeExpres
 	{type = ExpressionFactory.createSimpleTypeExpression(at, $blockDeclaration::env);}
 	;
 
+
+matchExpression returns [FeatureExpression feat = null]
+	:
+	match = dottedId
+	{MatchReference mr = ExpressionFactory.createMatchReference(match);}
+	;
+
 featureExpression returns [FeatureExpression feat = null]
 @init{
 List<Token> fs = new ArrayList<Token>();
-TypeExpression te = null;
+ITypeExpression te = null;
 }
 	:
 	match = dottedId2 
 	{
-	MatchReference mr = ExpressionFactory.createMatchReference(match, null, null);
+	MatchReference mr = ExpressionFactory.createMatchReference(match);
 	feat = ExpressionFactory.createFeatureExpression(mr, $blockDeclaration::env);
 	}
 	;
 
-featureMatchExpression returns [FeatureMatchExpression fme = null]
+featureMatchExpression returns [FeatureExpression fme = null]
 	:
 	match = dottedId2 ((comp = LESS | comp = GREATER | comp = GREATEREQUAL | comp = LESSEQUAL |comp =  EQUAL | comp = NOTEQUAL) arg = argument)?
 	{
-	MatchReference mr = ExpressionFactory.createMatchReference(match, comp, arg);
-	fme = ExpressionFactory.createFeatureMatchExpression(mr, $blockDeclaration::env);}
+	MatchReference mr = ExpressionFactory.createMatchReference(match);
+	if(comp != null) {
+	fme = ExpressionFactory.createFeatureMatchExpression(mr, comp, arg, $blockDeclaration::env);
+	} else {
+	fme = ExpressionFactory.createFeatureExpression(mr, $blockDeclaration::env);
+	}
+	}
 	;
 
 featureMatchExpression2 returns [FeatureMatchExpression fme = null]
 	:
 	match = dottedId2 (comp = LESS | comp = GREATER | comp = GREATEREQUAL | comp = LESSEQUAL |comp =  EQUAL | comp = NOTEQUAL) arg = argument
 	{
-	MatchReference mr = ExpressionFactory.createMatchReference(match, comp, arg);
-	fme = ExpressionFactory.createFeatureMatchExpression(mr, $blockDeclaration::env);}
+	MatchReference mr = ExpressionFactory.createMatchReference(match);
+	fme = ExpressionFactory.createFeatureMatchExpression(mr, comp, arg, $blockDeclaration::env);}
 	;
 
 
@@ -1196,8 +1245,8 @@ featureAssignmentExpression returns [Fea
 	:
 	match = dottedId2 op = ASSIGN_EQUAL arg = argument
 	{
-	MatchReference mr = ExpressionFactory.createMatchReference(match, op, arg);
-	fme = ExpressionFactory.createFeatureMatchExpression(mr, $blockDeclaration::env);
+	MatchReference mr = ExpressionFactory.createMatchReference(match);
+	fme = ExpressionFactory.createFeatureMatchExpression(mr, op, arg, $blockDeclaration::env);
 	}
 	;
 	
@@ -1219,15 +1268,15 @@ listVariable returns [Token var = null]
 	;
 
 
-//typeExpressionOr returns [TypeExpression type = null]
-//@init {List<TypeExpression> exprs = new ArrayList<TypeExpression>();}
+//typeExpressionOr returns [ITypeExpression type = null]
+//@init {List<ITypeExpression> exprs = new ArrayList<ITypeExpression>();}
 //	:
 //	LBRACK e = typeExpressionAnd{exprs.add(e);} ( COMMA e = typeExpressionAnd{exprs.add(e);} )* RBRACK
 //	{type = ExpressionFactory.createOrTypeExpression(exprs);}
 //	;
 
-//typeExpressionAnd returns [TypeExpression type = null]
-//@init {List<TypeExpression> exprs = new ArrayList<TypeExpression>();}
+//typeExpressionAnd returns [ITypeExpression type = null]
+//@init {List<ITypeExpression> exprs = new ArrayList<ITypeExpression>();}
 //	:
 //	LBRACK e = simpleTypeExpression{exprs.add(e);} ( SEMI e = simpleTypeExpression{exprs.add(e);} )* RBRACK
 //	{type = ExpressionFactory.createAndTypeExpression(exprs);}
@@ -1831,7 +1880,7 @@ actionReplace returns [AbstractRutaActio
 
 actionRetainType returns [AbstractRutaAction action = null]
 @init {
-List<TypeExpression> list = new ArrayList<TypeExpression>();
+List<ITypeExpression> list = new ArrayList<ITypeExpression>();
 }
     :   
     RETAINTYPE (LPAREN id = typeExpression {list.add(id);} (COMMA id = typeExpression {list.add(id);})* RPAREN)?
@@ -1842,7 +1891,7 @@ List<TypeExpression> list = new ArrayLis
 
 actionFilterType returns [AbstractRutaAction action = null]
 @init {
-List<TypeExpression> list = new ArrayList<TypeExpression>();
+List<ITypeExpression> list = new ArrayList<ITypeExpression>();
 }
     :   
     FILTERTYPE (LPAREN id = typeExpression {list.add(id);} (COMMA id = typeExpression {list.add(id);})* RPAREN)?
@@ -1939,7 +1988,7 @@ actionGreedyAnchoring returns [AbstractR
 
 actionTrim returns [AbstractRutaAction action = null]
 @init {
-  List<TypeExpression> types = new ArrayList<TypeExpression>();
+  List<ITypeExpression> types = new ArrayList<ITypeExpression>();
 }
     :
     name = TRIM LPAREN 
@@ -2084,7 +2133,7 @@ actionClear returns [AbstractRutaAction
 
 actionAddRetainType returns [AbstractRutaAction action = null]
 @init {
-List<TypeExpression> list = new ArrayList<TypeExpression>();
+List<ITypeExpression> list = new ArrayList<ITypeExpression>();
 }
     :
     ADDRETAINTYPE (LPAREN id = typeExpression {list.add(id);} (COMMA id = typeExpression {list.add(id);})* RPAREN)
@@ -2093,7 +2142,7 @@ List<TypeExpression> list = new ArrayLis
 
 actionRemoveRetainType returns [AbstractRutaAction action = null]
 @init {
-List<TypeExpression> list = new ArrayList<TypeExpression>();
+List<ITypeExpression> list = new ArrayList<ITypeExpression>();
 }
     :
     REMOVERETAINTYPE (LPAREN id = typeExpression {list.add(id);} (COMMA id = typeExpression {list.add(id);})* RPAREN)
@@ -2102,7 +2151,7 @@ List<TypeExpression> list = new ArrayLis
 
 actionAddFilterType returns [AbstractRutaAction action = null]
 @init {
-List<TypeExpression> list = new ArrayList<TypeExpression>();
+List<ITypeExpression> list = new ArrayList<ITypeExpression>();
 }
     :
     ADDFILTERTYPE (LPAREN id = typeExpression {list.add(id);} (COMMA id = typeExpression {list.add(id);})* RPAREN)
@@ -2111,7 +2160,7 @@ List<TypeExpression> list = new ArrayLis
 
 actionRemoveFilterType returns [AbstractRutaAction action = null]
 @init {
-List<TypeExpression> list = new ArrayList<TypeExpression>();
+List<ITypeExpression> list = new ArrayList<ITypeExpression>();
 }
     :
     REMOVEFILTERTYPE (LPAREN id = typeExpression {list.add(id);} (COMMA id = typeExpression {list.add(id);})* RPAREN)
@@ -2134,8 +2183,8 @@ options {
 	| a4 = stringExpression {expr = a4;}
 	| (listExpression)=> l = listExpression {expr = l;}
 	| a5 = nullExpression {expr = a5;}
-	//| a6 = annotationExpression {expr = a6;}
-	| a1 = typeExpression {expr = a1;}
+	| a6 = annotationOrTypeExpression {expr = a6;}
+	//| a1 = typeExpression {expr = a1;}
 	
 	//(a2 = booleanExpression)=> a2 = booleanExpression {expr = a2;}
 	//| (a3 = numberExpression)=> a3 = numberExpression {expr = a3;}
@@ -2143,16 +2192,56 @@ options {
 	//| (a1 = typeExpression)=> a1 = typeExpression {expr = a1;}
 	;
 
+annotationOrTypeExpression returns [IRutaExpression expr = null]
+	:
+	aae = annotationAddressExpression {expr = aae;}
+	|
+	tf = typeFunction {expr = tf;}
+	|
+	af = annotationFunction {expr = af;}	
+	|
+	ref = dottedId
+	{expr = ExpressionFactory.createGenericExpression(ref);}
+	;
 
-//annotationExpression returns [IRutaExpression expr = null]
-	//:
-	//ale = annotationLabelExpression {expr = ale}
-	//;
-	
-//annotationLabelExpression returns [IRutaExpression expr = null]
-	//:
-	//label = Identifier {expr = ExpressionFactory.createRuleElementLabelExpression();}
-	//;
+annotationExpression returns [IRutaExpression expr = null]
+	:
+	{isVariableOfType($blockDeclaration::env,input.LT(1).getText(), "ANNOTATION")	}? 
+	id = Identifier {expr = ExpressionFactory.createAnnotationVariableExpression(id);} 
+	|
+	{isVariableOfType($blockDeclaration::env,input.LT(1).getText(), "ANNOTATIONLIST")	}? 
+	id = Identifier {expr = ExpressionFactory.createAnnotationListVariableExpression(id);} 
+	|
+	aae = annotationAddressExpression {expr = aae;}
+	|
+	ale = annotationLabelExpression {expr = ale;}
+	
+	;
+
+annotationAddressExpression returns [IAnnotationExpression expr = null]
+	:
+	ADDRESS_PREFIX address = DecimalLiteral {expr = ExpressionFactory.createAnnotationAddressExpression(address);}
+	;
+	
+annotationLabelExpression returns [IRutaExpression expr = null]
+	:
+	label = Identifier {expr = ExpressionFactory.createAnnotationLabelExpression(label);}
+	;
+
+annotationFunction returns [IAnnotationExpression expr = null]
+	:
+	(e = externalAnnotationFunction)=> e = externalAnnotationFunction {expr = e;}
+	;
+
+externalAnnotationFunction returns [IAnnotationExpression expr = null]
+	:
+	{isAnnotationFunctionExtension(input.LT(1).getText())}? 
+	id = Identifier LPAREN
+	args = varArgumentList?	RPAREN
+	{
+		expr = external.createExternalAnnotationFunction(id, args);
+	}
+	;
 
 nullExpression returns [IRutaExpression expr = null]
 	:
@@ -2232,6 +2321,7 @@ annotationType returns [Token ref = null
 	did = dottedId {ref = did;}
 	)
 	;
+	
 
 wordListExpression returns [WordListExpression expr = null]
 @init  {

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

Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/FilterManager.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/FilterManager.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/FilterManager.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/FilterManager.java Mon Jan  4 10:33:48 2016
@@ -205,5 +205,4 @@ public class FilterManager {
     return currentHiddenTypes;
   }
 
-  
 }

Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaEnvironment.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaEnvironment.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaEnvironment.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaEnvironment.java Mon Jan  4 10:33:48 2016
@@ -41,6 +41,7 @@ import org.apache.uima.cas.CAS;
 import org.apache.uima.cas.CASException;
 import org.apache.uima.cas.Type;
 import org.apache.uima.cas.TypeSystem;
+import org.apache.uima.cas.text.AnnotationFS;
 import org.apache.uima.fit.factory.TypeSystemDescriptionFactory;
 import org.apache.uima.resource.ResourceAccessException;
 import org.apache.uima.resource.ResourceManager;
@@ -68,6 +69,7 @@ import org.apache.uima.ruta.resource.Rut
 import org.apache.uima.ruta.resource.RutaTable;
 import org.apache.uima.ruta.resource.RutaWordList;
 import org.apache.uima.ruta.resource.TreeWordList;
+import org.apache.uima.ruta.rule.MatchContext;
 import org.apache.uima.util.InvalidXMLException;
 import org.springframework.core.io.Resource;
 import org.springframework.core.io.ResourceLoader;
@@ -168,6 +170,7 @@ public class RutaEnvironment {
     variableTypes = new HashMap<String, Class<?>>();
     variableGenericTypes = new HashMap<String, Class<?>>();
     availableTypes = new HashMap<String, Class<?>>();
+    availableTypes.put("ANNOTATION", AnnotationFS.class);
     availableTypes.put("INT", Integer.class);
     availableTypes.put("STRING", String.class);
     availableTypes.put("DOUBLE", Double.class);
@@ -178,6 +181,7 @@ public class RutaEnvironment {
     availableTypes.put("ACTION", AbstractRutaAction.class);
     availableTypes.put("WORDLIST", RutaWordList.class);
     availableTypes.put("WORDTABLE", RutaTable.class);
+    availableTypes.put("ANNOTATIONLIST", List.class);
     availableTypes.put("BOOLEANLIST", List.class);
     availableTypes.put("INTLIST", List.class);
     availableTypes.put("DOUBLELIST", List.class);
@@ -185,6 +189,7 @@ public class RutaEnvironment {
     availableTypes.put("STRINGLIST", List.class);
     availableTypes.put("TYPELIST", List.class);
     availableListTypes = new HashMap<String, Class<?>>();
+    availableListTypes.put("ANNOTATIONLIST", AnnotationFS.class);
     availableListTypes.put("BOOLEANLIST", Boolean.class);
     availableListTypes.put("INTLIST", Integer.class);
     availableListTypes.put("DOUBLELIST", Double.class);
@@ -571,8 +576,7 @@ public class RutaEnvironment {
     UimaContext context = owner.getContext();
     Boolean dictRemoveWS = false;
     if (context != null) {
-      dictRemoveWS = (Boolean) context
-              .getConfigParameterValue(RutaEngine.PARAM_DICT_REMOVE_WS);
+      dictRemoveWS = (Boolean) context.getConfigParameterValue(RutaEngine.PARAM_DICT_REMOVE_WS);
       if (dictRemoveWS == null) {
         dictRemoveWS = false;
       }
@@ -750,13 +754,14 @@ public class RutaEnvironment {
       return type.cast(cas.getAnnotationType());
     }
     if (result != null) {
-      if(RutaWordList.class.isAssignableFrom(type) && result instanceof WordListExpression) {
+      MatchContext context = new MatchContext(owner);
+      if (RutaWordList.class.isAssignableFrom(type) && result instanceof WordListExpression) {
         WordListExpression wle = (WordListExpression) result;
-        RutaWordList list = wle.getList(owner);
+        RutaWordList list = wle.getList(context);
         return type.cast(list);
-      } else if(RutaTable.class.isAssignableFrom(type) && result instanceof WordTableExpression) {
+      } else if (RutaTable.class.isAssignableFrom(type) && result instanceof WordTableExpression) {
         WordTableExpression wte = (WordTableExpression) result;
-        RutaTable table = wte.getTable(owner);
+        RutaTable table = wte.getTable(context);
         return type.cast(table);
       } else {
         return type.cast(result);
@@ -774,24 +779,25 @@ public class RutaEnvironment {
   @SuppressWarnings("rawtypes")
   public Object getLiteralValue(String var, Object value) {
     if (ownsVariable(var)) {
+      MatchContext context = new MatchContext(owner);
       Class<?> clazz = variableTypes.get(var);
       if (value instanceof INumberExpression) {
         INumberExpression ne = (INumberExpression) value;
         if (clazz.equals(Integer.class)) {
-          return ne.getIntegerValue(owner, null, null);
+          return ne.getIntegerValue(context, null);
         } else if (clazz.equals(Double.class)) {
-          return ne.getDoubleValue(owner, null, null);
+          return ne.getDoubleValue(context, null);
         } else if (clazz.equals(Float.class)) {
-          return ne.getFloatValue(owner, null, null);
+          return ne.getFloatValue(context, null);
         } else if (clazz.equals(String.class)) {
-          return ne.getStringValue(owner, null, null);
+          return ne.getStringValue(context, null);
         }
       } else if (clazz.equals(String.class) && value instanceof IStringExpression) {
         IStringExpression se = (IStringExpression) value;
-        return se.getStringValue(owner, null, null);
+        return se.getStringValue(context, null);
       } else if (clazz.equals(Boolean.class) && value instanceof IBooleanExpression) {
         IBooleanExpression be = (IBooleanExpression) value;
-        return be.getBooleanValue(owner, null, null);
+        return be.getBooleanValue(context, null);
       }
       if (clazz.equals(RutaWordList.class) && value instanceof LiteralWordListExpression) {
         return value;

Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaModule.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaModule.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaModule.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaModule.java Mon Jan  4 10:33:48 2016
@@ -55,20 +55,20 @@ public class RutaModule extends RutaElem
       return rootBlock;
     }
     RutaBlock ownBlock = blocks.get(id);
-    if(ownBlock != null) {
+    if (ownBlock != null) {
       return ownBlock;
     }
     int indexOf = id.indexOf('.');
-    if(indexOf != -1) {
+    if (indexOf != -1) {
       String otherScriptName = id.substring(0, indexOf);
       String tail = id.substring(indexOf + 1, id.length());
       RutaModule otherScript = getScript(otherScriptName);
-      if(otherScript != null) {
+      if (otherScript != null) {
         return otherScript.getBlock(tail);
       }
     } else {
       RutaModule otherScript = getScript(id);
-      if(otherScript != null) {
+      if (otherScript != null) {
         return otherScript.getBlock(null);
       }
     }

Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaScriptFactory.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaScriptFactory.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaScriptFactory.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaScriptFactory.java Mon Jan  4 10:33:48 2016
@@ -29,11 +29,12 @@ import org.apache.uima.UimaContext;
 import org.apache.uima.ruta.action.AbstractRutaAction;
 import org.apache.uima.ruta.condition.AbstractRutaCondition;
 import org.apache.uima.ruta.expression.IRutaExpression;
-import org.apache.uima.ruta.expression.MatchReference;
+import org.apache.uima.ruta.expression.annotation.IAnnotationExpression;
+import org.apache.uima.ruta.expression.feature.FeatureExpression;
 import org.apache.uima.ruta.expression.number.INumberExpression;
 import org.apache.uima.ruta.expression.string.IStringExpression;
+import org.apache.uima.ruta.expression.type.ITypeExpression;
 import org.apache.uima.ruta.expression.type.SimpleTypeExpression;
-import org.apache.uima.ruta.expression.type.TypeExpression;
 import org.apache.uima.ruta.rule.AbstractRuleElement;
 import org.apache.uima.ruta.rule.ComposedRuleElement;
 import org.apache.uima.ruta.rule.ConjunctRulesRuleElement;
@@ -41,6 +42,7 @@ import org.apache.uima.ruta.rule.RegExpR
 import org.apache.uima.ruta.rule.RuleElement;
 import org.apache.uima.ruta.rule.RuleElementContainer;
 import org.apache.uima.ruta.rule.RuleElementIsolator;
+import org.apache.uima.ruta.rule.RutaAnnotationMatcher;
 import org.apache.uima.ruta.rule.RutaLiteralMatcher;
 import org.apache.uima.ruta.rule.RutaMatcher;
 import org.apache.uima.ruta.rule.RutaRule;
@@ -102,8 +104,8 @@ public class RutaScriptFactory {
     RutaScriptBlock result = createScriptBlock(module, null, null, null, defaultNamespace);
     List<RuleElement> ruleElements = new ArrayList<RuleElement>();
     RuleElementIsolator container = new RuleElementIsolator();
-    ruleElements.add(createRuleElement(new MatchReference("uima.tcas.DocumentAnnotation", null,
-            null), null, null, null, container, result));
+    ruleElements.add(createRuleElement(new SimpleTypeExpression("uima.tcas.DocumentAnnotation"), null,
+            null, null, container, result));
     RutaRule createRule = createRule(ruleElements, result);
     container.setContainer(createRule);
 
@@ -121,13 +123,14 @@ public class RutaScriptFactory {
   public RutaStatement createImplicitRule(List<AbstractRutaAction> actions, RutaBlock parent) {
     List<RuleElement> elements = new ArrayList<RuleElement>();
     IRutaExpression documentExpression = new SimpleTypeExpression("Document");
-    RutaRuleElement element = createRuleElement(documentExpression, null, null, actions, null, parent);
+    RutaRuleElement element = createRuleElement(documentExpression, null, null, actions, null,
+            parent);
     elements.add(element);
     RutaRule rule = createRule(elements, parent);
     element.setContainer(rule.getRoot());
     return rule;
   }
-  
+
   public RutaRule createRule(List<RuleElement> elements, RutaBlock parent) {
     return new RutaRule(elements, parent, idCounter++);
   }
@@ -136,14 +139,16 @@ public class RutaScriptFactory {
           RuleElementQuantifier quantifier, List<AbstractRutaCondition> conditions,
           List<AbstractRutaAction> actions, RuleElementContainer container, RutaBlock parent) {
     RutaMatcher matcher = null;
-    if (expression instanceof MatchReference) {
-      matcher = new RutaTypeMatcher((MatchReference) expression);
-    } else if (expression instanceof TypeExpression) {
-      // e.g., for functions
-      MatchReference matchReference = new MatchReference((TypeExpression) expression);
-      matcher = new RutaTypeMatcher(matchReference);
+    if (expression instanceof ITypeExpression) {
+      matcher = new RutaTypeMatcher((ITypeExpression) expression);
+    } else if (expression instanceof FeatureExpression) {
+      matcher = new RutaTypeMatcher((FeatureExpression) expression);
+    } else if (expression instanceof IAnnotationExpression) {
+      matcher = new RutaAnnotationMatcher((IAnnotationExpression) expression);
     } else if (expression instanceof IStringExpression) {
       matcher = new RutaLiteralMatcher((IStringExpression) expression);
+    } else {
+      throw new RuntimeException(expression.getClass().getSimpleName() + " is not a valid expression for a matching condition.");
     }
     return new RutaRuleElement(matcher, quantifier, conditions, actions, container, parent);
   }
@@ -263,5 +268,4 @@ public class RutaScriptFactory {
     this.context = context;
   }
 
-
 }

Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java Mon Jan  4 10:33:48 2016
@@ -24,6 +24,7 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Map;
 import java.util.Map.Entry;
 import java.util.NavigableMap;
 import java.util.NoSuchElementException;
@@ -36,6 +37,7 @@ import org.apache.uima.cas.CASException;
 import org.apache.uima.cas.ConstraintFactory;
 import org.apache.uima.cas.FSIterator;
 import org.apache.uima.cas.FSMatchConstraint;
+import org.apache.uima.cas.Feature;
 import org.apache.uima.cas.FeatureStructure;
 import org.apache.uima.cas.Type;
 import org.apache.uima.cas.impl.FSIteratorImplBase;
@@ -44,10 +46,21 @@ import org.apache.uima.cas.text.Annotati
 import org.apache.uima.jcas.JCas;
 import org.apache.uima.jcas.tcas.Annotation;
 import org.apache.uima.ruta.engine.RutaEngine;
+import org.apache.uima.ruta.expression.AnnotationTypeExpression;
+import org.apache.uima.ruta.expression.IRutaExpression;
+import org.apache.uima.ruta.expression.bool.IBooleanExpression;
+import org.apache.uima.ruta.expression.feature.FeatureExpression;
+import org.apache.uima.ruta.expression.feature.GenericFeatureExpression;
+import org.apache.uima.ruta.expression.feature.SimpleFeatureExpression;
+import org.apache.uima.ruta.expression.number.INumberExpression;
+import org.apache.uima.ruta.expression.string.IStringExpression;
+import org.apache.uima.ruta.expression.type.ITypeExpression;
 import org.apache.uima.ruta.rule.AbstractRule;
 import org.apache.uima.ruta.rule.AbstractRuleMatch;
+import org.apache.uima.ruta.rule.MatchContext;
 import org.apache.uima.ruta.type.RutaAnnotation;
 import org.apache.uima.ruta.type.RutaBasic;
+import org.apache.uima.ruta.utils.UIMAUtils;
 import org.apache.uima.ruta.visitor.InferenceCrowd;
 
 public class RutaStream extends FSIteratorImplBase<AnnotationFS> {
@@ -154,7 +167,7 @@ public class RutaStream extends FSIterat
     AnnotationIndex<AnnotationFS> annotationIndex = cas.getAnnotationIndex();
     final List<AnnotationFS> allAnnotations = new LinkedList<AnnotationFS>();
     for (AnnotationFS a : annotationIndex) {
-      if(a.getBegin() != a.getEnd()) {
+      if (a.getBegin() != a.getEnd()) {
         allAnnotations.add(a);
       }
     }
@@ -178,12 +191,12 @@ public class RutaStream extends FSIterat
             break;
           }
           Integer second = anchors.first();
-          if(first < second) {
-          RutaBasic newTMB = new RutaBasic(getJCas(), first, second);
-          newTMB.setLowMemoryProfile(lowMemoryProfile);
-          beginAnchors.put(first, newTMB);
-          endAnchors.put(second, newTMB);
-          cas.addFsToIndexes(newTMB);
+          if (first < second) {
+            RutaBasic newTMB = new RutaBasic(getJCas(), first, second);
+            newTMB.setLowMemoryProfile(lowMemoryProfile);
+            beginAnchors.put(first, newTMB);
+            endAnchors.put(second, newTMB);
+            cas.addFsToIndexes(newTMB);
           }
         }
       }
@@ -300,7 +313,7 @@ public class RutaStream extends FSIterat
         toSplit = ceiling;
       }
       int newEnd = toSplit.getEnd();
-      if(newEnd == anchor) {
+      if (newEnd == anchor) {
         return false;
       }
       cas.removeFsFromIndexes(toSplit);
@@ -330,7 +343,7 @@ public class RutaStream extends FSIterat
   }
 
   public void removeAnnotation(AnnotationFS annotation, Type type) {
-    if(type.getName().equals(UIMAConstants.TYPE_DOCUMENT)) {
+    if (type.getName().equals(UIMAConstants.TYPE_DOCUMENT)) {
       // do not remove DocumentAnnotation
       return;
     }
@@ -341,11 +354,11 @@ public class RutaStream extends FSIterat
     Type parent = type;
     RutaBasic beginAnchor = getBeginAnchor(annotation.getBegin());
     RutaBasic endAnchor = getEndAnchor(annotation.getEnd());
-    if(beginAnchor != null) {
-    	beginAnchor.removeBegin(annotation, parent);
+    if (beginAnchor != null) {
+      beginAnchor.removeBegin(annotation, parent);
     }
-    if(endAnchor != null) {
-    	endAnchor.removeEnd(annotation, parent);
+    if (endAnchor != null) {
+      endAnchor.removeEnd(annotation, parent);
     }
     if (!(annotation instanceof RutaBasic)) {
       cas.removeFsFromIndexes(annotation);
@@ -369,13 +382,14 @@ public class RutaStream extends FSIterat
             filter.getCurrentFilterTypes(), filter.getCurrentRetainTypes(), windowAnnotation,
             windowType, cas);
 
-//    NavigableMap<Integer, RutaBasic> newBeginAnchors = beginAnchors.subMap(
-//            windowAnnotation.getBegin(), true, windowAnnotation.getEnd(), false);
-//    NavigableMap<Integer, RutaBasic> newEndAnchors = endAnchors.subMap(windowAnnotation.getBegin(),
-//            false, windowAnnotation.getEnd(), true);
+    // NavigableMap<Integer, RutaBasic> newBeginAnchors = beginAnchors.subMap(
+    // windowAnnotation.getBegin(), true, windowAnnotation.getEnd(), false);
+    // NavigableMap<Integer, RutaBasic> newEndAnchors =
+    // endAnchors.subMap(windowAnnotation.getBegin(),
+    // false, windowAnnotation.getEnd(), true);
 
-    RutaStream stream = new RutaStream(cas, basicType, beginAnchors, endAnchors,
-            filterManager, lowMemoryProfile, simpleGreedyForComposed, crowd);
+    RutaStream stream = new RutaStream(cas, basicType, beginAnchors, endAnchors, filterManager,
+            lowMemoryProfile, simpleGreedyForComposed, crowd);
     stream.setDynamicAnchoring(dynamicAnchoring);
     stream.setGreedyRuleElement(greedyRuleElement);
     stream.setGreedyRule(greedyRule);
@@ -403,7 +417,7 @@ public class RutaStream extends FSIterat
     try {
       currentIt.moveTo(fs);
     } catch (Exception e) {
-//      e.printStackTrace();
+      // e.printStackTrace();
     }
   }
 
@@ -468,7 +482,7 @@ public class RutaStream extends FSIterat
     try {
       return cas.getJCas();
     } catch (CASException e) {
-//      e.printStackTrace();
+      // e.printStackTrace();
     }
     return null;
   }
@@ -523,7 +537,8 @@ public class RutaStream extends FSIterat
   }
 
   public List<AnnotationFS> getAnnotationsInWindow(AnnotationFS windowAnnotation, Type type) {
-    if(type == null) return null;
+    if (type == null)
+      return null;
     List<AnnotationFS> result = new ArrayList<AnnotationFS>();
     List<AnnotationFS> inWindow = getAnnotationsInWindow2(windowAnnotation, type);
     result = inWindow;
@@ -561,7 +576,7 @@ public class RutaStream extends FSIterat
       if (isVisible(pointer) || !isValid()) {
         moveToPrevious();
       }
-      if(!isValid()) {
+      if (!isValid()) {
         moveToLast();
       }
       if (isValid()) {
@@ -790,26 +805,26 @@ public class RutaStream extends FSIterat
   public boolean isOnlyOnce() {
     return onlyOnce;
   }
-  
+
   public void setOnlyOnce(Boolean onlyOnce) {
     this.onlyOnce = onlyOnce;
   }
-  
-  
+
   public boolean isVisible(AnnotationFS annotationFS) {
     return isVisible(annotationFS, false);
   }
-  
+
   public boolean isVisible(AnnotationFS annotationFS, boolean ignoreWindow) {
     if (annotationFS == null) {
       return false;
     }
-    if(annotationFS.getBegin() >= annotationFS.getEnd()) {
+    if (annotationFS.getBegin() >= annotationFS.getEnd()) {
       return false;
     }
-    
+
     AnnotationFS windowAnnotation = filter.getWindowAnnotation();
-    if (!ignoreWindow && windowAnnotation != null
+    if (!ignoreWindow
+            && windowAnnotation != null
             && (annotationFS.getBegin() < windowAnnotation.getBegin() || annotationFS.getEnd() > windowAnnotation
                     .getEnd())) {
       return false;
@@ -884,13 +899,124 @@ public class RutaStream extends FSIterat
     StringBuilder result = new StringBuilder();
     List<RutaBasic> basicsInWindow = getBasicsInWindow(annotationFS);
     for (RutaBasic each : basicsInWindow) {
-      if(isVisible(each)) {
+      if (isVisible(each)) {
         result.append(each.getCoveredText());
       }
     }
     return result.toString();
   }
 
+  public void assignFeatureValues(AnnotationFS annotation,
+          Map<IStringExpression, IRutaExpression> map, MatchContext context) {
+    Type type = annotation.getType();
+    Set<Entry<IStringExpression, IRutaExpression>> entrySet = map.entrySet();
+    for (Entry<IStringExpression, IRutaExpression> entry : entrySet) {
+      IStringExpression key = entry.getKey();
+      IRutaExpression value = entry.getValue();
+      String featureName = key.getStringValue(context, this);
+      Feature feature = type.getFeatureByBaseName(featureName);
+      assignFeatureValue(annotation, feature, value, context);
+    }
+  }
+
+  public void assignFeatureValue(AnnotationFS annotation, Feature feature, IRutaExpression value,
+          MatchContext context) {
+    if (feature == null) {
+      throw new IllegalArgumentException("Not able to assign feature value (e.g., coveredText).");
+    }
+    String range = feature.getRange().getName();
+    if (range.equals(UIMAConstants.TYPE_STRING)) {
+      if (value instanceof IStringExpression) {
+        IStringExpression stringExpr = (IStringExpression) value;
+        String string = stringExpr.getStringValue(context, this);
+        annotation.setStringValue(feature, string);
+      }
+    } else if (value instanceof INumberExpression
+            && (range.equals(UIMAConstants.TYPE_INTEGER) || range.equals(UIMAConstants.TYPE_LONG)
+                    || range.equals(UIMAConstants.TYPE_SHORT) || range
+                      .equals(UIMAConstants.TYPE_BYTE))) {
+      INumberExpression numberExpr = (INumberExpression) value;
+      int v = numberExpr.getIntegerValue(context, this);
+      annotation.setIntValue(feature, v);
+    } else if (value instanceof INumberExpression && (range.equals(UIMAConstants.TYPE_DOUBLE))) {
+      INumberExpression numberExpr = (INumberExpression) value;
+      double v = numberExpr.getDoubleValue(context, this);
+      annotation.setDoubleValue(feature, v);
+    } else if (value instanceof INumberExpression && (range.equals(UIMAConstants.TYPE_FLOAT))) {
+      INumberExpression numberExpr = (INumberExpression) value;
+      float v = numberExpr.getFloatValue(context, this);
+      annotation.setFloatValue(feature, v);
+    } else if (value instanceof IBooleanExpression && (range.equals(UIMAConstants.TYPE_BOOLEAN))) {
+      IBooleanExpression booleanExpr = (IBooleanExpression) value;
+      boolean v = booleanExpr.getBooleanValue(context, this);
+      annotation.setBooleanValue(feature, v);
+    } else if (value instanceof IBooleanExpression && (range.equals(UIMAConstants.TYPE_BOOLEAN))) {
+      IBooleanExpression booleanExpr = (IBooleanExpression) value;
+      boolean v = booleanExpr.getBooleanValue(context, this);
+      annotation.setBooleanValue(feature, v);
+    } else if (value instanceof AnnotationTypeExpression && !feature.getRange().isPrimitive()) {
+      AnnotationTypeExpression ate = (AnnotationTypeExpression) value;
+      AnnotationFS a = ate.getAnnotation(context, this);
+      if (a != null) {
+        // TODO support annotation list expressions
+        if (feature.getRange().isArray()) {
+          List<AnnotationFS> c = new ArrayList<AnnotationFS>();
+          c.add(a);
+          annotation.setFeatureValue(feature, UIMAUtils.toFSArray(this.getJCas(), c));
+        } else {
+          annotation.setFeatureValue(feature, a);
+        }
+      } else {
+        Type t = ate.getType(context, this);
+        assignAnnotationByTypeInWindow(annotation, feature, context, t);
+      }
+    } else if (value instanceof ITypeExpression && !feature.getRange().isPrimitive()) {
+      ITypeExpression typeExpr = (ITypeExpression) value;
+      Type t = typeExpr.getType(context, this);
+      assignAnnotationByTypeInWindow(annotation, feature, context, t);
+    } else if (value instanceof GenericFeatureExpression && !feature.getRange().isPrimitive()) {
+      FeatureExpression fe = ((GenericFeatureExpression) value).getFeatureExpression();
+      ITypeExpression typeExpr = fe.getTypeExpr(context, this);
+      Type t = typeExpr.getType(context, this);
+      List<AnnotationFS> inWindow = this.getAnnotationsInWindow(context.getAnnotation(), t);
+      if (fe instanceof SimpleFeatureExpression) {
+        SimpleFeatureExpression sfe = (SimpleFeatureExpression) fe;
+        List<AnnotationFS> featureAnnotations = inWindow;
+        if (fe.getFeatures(context, this) != null) {
+          featureAnnotations = new ArrayList<AnnotationFS>(sfe.getFeatureAnnotations(inWindow,
+                  this, context, false));
+        }
+        if (feature.getRange().isArray()) {
+          annotation.setFeatureValue(feature,
+                  UIMAUtils.toFSArray(this.getJCas(), featureAnnotations));
+        } else if (!featureAnnotations.isEmpty()) {
+          AnnotationFS a = featureAnnotations.get(0);
+          annotation.setFeatureValue(feature, a);
+        }
+      } else {
+        if (feature.getRange().isArray()) {
+          annotation.setFeatureValue(feature, UIMAUtils.toFSArray(this.getJCas(), inWindow));
+        } else {
+          AnnotationFS a = inWindow.get(0);
+          annotation.setFeatureValue(feature, a);
+        }
+      }
+    }
+  }
 
+  private void assignAnnotationByTypeInWindow(AnnotationFS annotation, Feature feature,
+          MatchContext context, Type type) {
 
+    List<AnnotationFS> inWindow = this.getAnnotationsInWindow(context.getAnnotation(), type);
+    if (feature.getRange().isArray()) {
+      annotation.setFeatureValue(feature, UIMAUtils.toFSArray(this.getJCas(), inWindow));
+    } else {
+      if (inWindow != null && !inWindow.isEmpty()) {
+        AnnotationFS a = inWindow.get(0);
+        annotation.setFeatureValue(feature, a);
+      } else {
+        annotation.setFeatureValue(feature, null);
+      }
+    }
+  }
 }

Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/UIMAConstants.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/UIMAConstants.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/UIMAConstants.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/UIMAConstants.java Mon Jan  4 10:33:48 2016
@@ -36,11 +36,11 @@ public class UIMAConstants {
   public static final String TYPE_DOUBLE = "uima.cas.Double";
 
   public static final String TYPE_STRING = "uima.cas.String";
-  
+
   public static final String TYPE_DOCUMENT = "uima.tcas.DocumentAnnotation";
-  
+
   public static final String FEATURE_COVERED_TEXT = "coveredText";
-  
+
   public static final String FEATURE_COVERED_TEXT_SHORT = "ct";
 
 }

Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/AbstractMarkAction.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/AbstractMarkAction.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/AbstractMarkAction.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/AbstractMarkAction.java Mon Jan  4 10:33:48 2016
@@ -27,21 +27,21 @@ import org.apache.uima.cas.text.Annotati
 import org.apache.uima.jcas.tcas.Annotation;
 import org.apache.uima.ruta.RutaStream;
 import org.apache.uima.ruta.expression.number.INumberExpression;
-import org.apache.uima.ruta.expression.type.TypeExpression;
+import org.apache.uima.ruta.expression.type.ITypeExpression;
+import org.apache.uima.ruta.rule.MatchContext;
 import org.apache.uima.ruta.rule.RuleElement;
-import org.apache.uima.ruta.rule.RuleMatch;
 
 public abstract class AbstractMarkAction extends TypeSensitiveAction {
 
-  public AbstractMarkAction(TypeExpression type) {
+  public AbstractMarkAction(ITypeExpression type) {
     super(type);
   }
 
-  protected Annotation createAnnotation(AnnotationFS matchedAnnotation, RuleElement element,
-          RutaStream stream, RuleMatch match) {
-    Type t = type.getType(element.getParent());
-    AnnotationFS newAnnotationFS = stream.getCas().createAnnotation(t,
-            matchedAnnotation.getBegin(), matchedAnnotation.getEnd());
+  protected Annotation createAnnotation(AnnotationFS annotation, MatchContext context,
+          RutaStream stream) {
+    Type t = type.getType(context, stream);
+    AnnotationFS newAnnotationFS = stream.getCas().createAnnotation(t, annotation.getBegin(),
+            annotation.getEnd());
     Annotation newAnnotation = null;
     if (newAnnotationFS instanceof Annotation) {
       newAnnotation = (Annotation) newAnnotationFS;
@@ -49,7 +49,7 @@ public abstract class AbstractMarkAction
     } else {
       return null;
     }
-    stream.addAnnotation(newAnnotation, match);
+    stream.addAnnotation(newAnnotation, context.getRuleMatch());
     return newAnnotation;
   }
 
@@ -58,8 +58,9 @@ public abstract class AbstractMarkAction
     return super.toString() + "," + type.getClass().getSimpleName();
   }
 
-  protected List<Integer> getIndexList(RuleElement element, List<INumberExpression> list,
+  protected List<Integer> getIndexList(MatchContext context, List<INumberExpression> list,
           RutaStream stream) {
+    RuleElement element = context.getElement();
     List<Integer> indexList = new ArrayList<Integer>();
     if (list == null || list.isEmpty()) {
       int self = element.getContainer().getRuleElements().indexOf(element) + 1;
@@ -69,7 +70,7 @@ public abstract class AbstractMarkAction
     int last = Integer.MAX_VALUE - 1;
     for (INumberExpression each : list) {
       // no feature matches allowed
-      int value = each.getIntegerValue(element.getParent(), null, stream);
+      int value = each.getIntegerValue(context, stream);
       for (int i = Math.min(value, last + 1); i < value; i++) {
         indexList.add(i);
       }

Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/AbstractRutaAction.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/AbstractRutaAction.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/AbstractRutaAction.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/AbstractRutaAction.java Mon Jan  4 10:33:48 2016
@@ -19,10 +19,14 @@
 
 package org.apache.uima.ruta.action;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import org.apache.uima.ruta.RutaElement;
 import org.apache.uima.ruta.RutaStream;
+import org.apache.uima.ruta.expression.number.INumberExpression;
+import org.apache.uima.ruta.rule.MatchContext;
 import org.apache.uima.ruta.rule.RuleElement;
-import org.apache.uima.ruta.rule.RuleMatch;
 import org.apache.uima.ruta.visitor.InferenceCrowd;
 
 public abstract class AbstractRutaAction extends RutaElement {
@@ -31,12 +35,31 @@ public abstract class AbstractRutaAction
     super();
   }
 
-  public abstract void execute(RuleMatch match, RuleElement element, RutaStream stream,
-          InferenceCrowd crowd);
+  public abstract void execute(MatchContext context, RutaStream stream, InferenceCrowd crowd);
 
   @Override
   public String toString() {
     return getClass().getSimpleName();
   }
 
+  protected List<Integer> getIndexList(List<INumberExpression> indexes, MatchContext context, RutaStream stream) {
+    RuleElement element = context.getElement();
+    List<Integer> indexList = new ArrayList<Integer>();
+    if (indexes == null || indexes.isEmpty()) {
+      int self = element.getContainer().getRuleElements().indexOf(element) + 1;
+      indexList.add(self);
+      return indexList;
+    }
+    int last = Integer.MAX_VALUE - 1;
+    for (INumberExpression each : indexes) {
+      // no feature matches allowed
+      int value = each.getIntegerValue(context, stream);
+      for (int i = Math.min(value, last + 1); i < value; i++) {
+        indexList.add(i);
+      }
+      indexList.add(value);
+    }
+    return indexList;
+  }
+  
 }

Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/AbstractStructureAction.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/AbstractStructureAction.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/AbstractStructureAction.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/AbstractStructureAction.java Mon Jan  4 10:33:48 2016
@@ -32,7 +32,6 @@ import org.apache.uima.cas.text.Annotati
 import org.apache.uima.jcas.JCas;
 import org.apache.uima.jcas.cas.FSArray;
 import org.apache.uima.jcas.cas.TOP;
-import org.apache.uima.ruta.RutaBlock;
 import org.apache.uima.ruta.RutaStream;
 import org.apache.uima.ruta.UIMAConstants;
 import org.apache.uima.ruta.expression.IRutaExpression;
@@ -41,8 +40,8 @@ import org.apache.uima.ruta.expression.f
 import org.apache.uima.ruta.expression.feature.GenericFeatureExpression;
 import org.apache.uima.ruta.expression.number.INumberExpression;
 import org.apache.uima.ruta.expression.string.IStringExpression;
-import org.apache.uima.ruta.expression.type.TypeExpression;
-import org.apache.uima.ruta.rule.RuleElement;
+import org.apache.uima.ruta.expression.type.ITypeExpression;
+import org.apache.uima.ruta.rule.MatchContext;
 import org.apache.uima.ruta.utils.UIMAUtils;
 
 public abstract class AbstractStructureAction extends AbstractRutaAction {
@@ -51,15 +50,14 @@ public abstract class AbstractStructureA
     super();
   }
 
-  protected void fillFeatures(TOP structure, Map<IStringExpression, IRutaExpression> features,
-          AnnotationFS matchedAnnotation, RuleElement element, RutaStream stream) {
+  protected void fillFeatures2(TOP structure, Map<IStringExpression, IRutaExpression> features,
+          AnnotationFS matchedAnnotation, MatchContext context, RutaStream stream) {
     Map<String, IRutaExpression> map = new HashMap<String, IRutaExpression>();
-    RutaBlock parent = element.getParent();
     for (Entry<IStringExpression, IRutaExpression> each : features.entrySet()) {
-      String value = each.getKey().getStringValue(parent, matchedAnnotation, stream);
+      String value = each.getKey().getStringValue(context, stream);
       map.put(value, each.getValue());
     }
-
+    // TODO use method in RutaStream?
     TypeSystem typeSystem = stream.getCas().getTypeSystem();
     JCas jcas = stream.getJCas();
     List<?> featuresList = structure.getType().getFeatures();
@@ -70,11 +68,11 @@ public abstract class AbstractStructureA
       Object valueObject = map.get(shortFName);
       Type range = targetFeature.getRange();
       if (valueObject != null) {
-        if (valueObject instanceof TypeExpression
+        if (valueObject instanceof ITypeExpression
                 && range.getName().equals(UIMAConstants.TYPE_STRING)) {
-          TypeExpression type = (TypeExpression) valueObject;
+          ITypeExpression type = (ITypeExpression) valueObject;
           List<AnnotationFS> annotationsInWindow = stream.getAnnotationsInWindow(matchedAnnotation,
-                  type.getType(parent));
+                  type.getType(context, stream));
           if (annotationsInWindow != null && !annotationsInWindow.isEmpty()) {
             AnnotationFS annotation = annotationsInWindow.get(0);
             structure.setStringValue(targetFeature, annotation.getCoveredText());
@@ -82,13 +80,13 @@ public abstract class AbstractStructureA
         } else if (valueObject instanceof GenericFeatureExpression && !range.isPrimitive()) {
           GenericFeatureExpression gfe = (GenericFeatureExpression) valueObject;
           FeatureExpression fe = gfe.getFeatureExpression();
-          TypeExpression type = fe.getTypeExpr(parent);
+          ITypeExpression type = fe.getTypeExpr(context, stream);
           List<AnnotationFS> annotationsInWindow = stream.getAnnotationsInWindow(matchedAnnotation,
-                  type.getType(parent));
+                  type.getType(context, stream));
           List<AnnotationFS> featureAnnotations = annotationsInWindow;
-          if (fe.getFeatures(parent) != null) {
+          if (fe.getFeatures(context, stream) != null) {
             featureAnnotations = new ArrayList<AnnotationFS>(fe.getFeatureAnnotations(
-                    annotationsInWindow, stream, parent, false));
+                    annotationsInWindow, stream, context, false));
           }
           if (typeSystem.subsumes(jcas.getCasType(FSArray.type), range)) {
             structure.setFeatureValue(targetFeature, UIMAUtils.toFSArray(jcas, featureAnnotations));
@@ -100,41 +98,41 @@ public abstract class AbstractStructureA
           }
         } else if (valueObject instanceof IStringExpression
                 && range.getName().equals(UIMAConstants.TYPE_STRING)) {
-          structure.setStringValue(targetFeature, ((IStringExpression) valueObject).getStringValue(
-                  parent, matchedAnnotation, stream));
+          structure.setStringValue(targetFeature,
+                  ((IStringExpression) valueObject).getStringValue(context, stream));
 
         } else if (valueObject instanceof INumberExpression) {
           if (range.getName().equals(UIMAConstants.TYPE_DOUBLE)) {
-            structure.setDoubleValue(targetFeature, ((INumberExpression) valueObject)
-                    .getDoubleValue(parent, matchedAnnotation, stream));
+            structure.setDoubleValue(targetFeature,
+                    ((INumberExpression) valueObject).getDoubleValue(context, stream));
           } else if (range.getName().equals(UIMAConstants.TYPE_INTEGER)) {
-            structure.setIntValue(targetFeature, ((INumberExpression) valueObject).getIntegerValue(
-                    parent, matchedAnnotation, stream));
+            structure.setIntValue(targetFeature,
+                    ((INumberExpression) valueObject).getIntegerValue(context, stream));
           } else if (range.getName().equals(UIMAConstants.TYPE_FLOAT)) {
-            structure.setFloatValue(targetFeature, ((INumberExpression) valueObject).getFloatValue(
-                    parent, matchedAnnotation, stream));
+            structure.setFloatValue(targetFeature,
+                    ((INumberExpression) valueObject).getFloatValue(context, stream));
           } else if (range.getName().equals(UIMAConstants.TYPE_BYTE)) {
-            structure.setByteValue(targetFeature, (byte) ((INumberExpression) valueObject)
-                    .getIntegerValue(parent, matchedAnnotation, stream));
+            structure.setByteValue(targetFeature,
+                    (byte) ((INumberExpression) valueObject).getIntegerValue(context, stream));
           } else if (range.getName().equals(UIMAConstants.TYPE_SHORT)) {
-            structure.setShortValue(targetFeature, (short) ((INumberExpression) valueObject)
-                    .getIntegerValue(parent, matchedAnnotation, stream));
+            structure.setShortValue(targetFeature,
+                    (short) ((INumberExpression) valueObject).getIntegerValue(context, stream));
           } else if (range.getName().equals(UIMAConstants.TYPE_LONG)) {
-            structure.setLongValue(targetFeature, (long) ((INumberExpression) valueObject)
-                    .getIntegerValue(parent, matchedAnnotation, stream));
+            structure.setLongValue(targetFeature,
+                    ((INumberExpression) valueObject).getIntegerValue(context, stream));
           }
         } else if (valueObject instanceof IBooleanExpression
                 && range.getName().equals(UIMAConstants.TYPE_BOOLEAN)) {
-          structure.setBooleanValue(targetFeature, ((IBooleanExpression) valueObject)
-                  .getBooleanValue(parent, matchedAnnotation, stream));
-        } else if (valueObject instanceof TypeExpression) {
-          TypeExpression type = (TypeExpression) valueObject;
+          structure.setBooleanValue(targetFeature,
+                  ((IBooleanExpression) valueObject).getBooleanValue(context, stream));
+        } else if (valueObject instanceof ITypeExpression) {
+          ITypeExpression type = (ITypeExpression) valueObject;
           List<AnnotationFS> annotationsInWindow = stream.getAnnotationsInWindow(matchedAnnotation,
-                  type.getType(parent));
+                  type.getType(context, stream));
           if (typeSystem.subsumes(jcas.getCasType(FSArray.type), range)) {
             structure
                     .setFeatureValue(targetFeature, UIMAUtils.toFSArray(jcas, annotationsInWindow));
-          } else if (typeSystem.subsumes(range, type.getType(parent))
+          } else if (typeSystem.subsumes(range, type.getType(context, stream))
                   && !annotationsInWindow.isEmpty()) {
             AnnotationFS annotation = annotationsInWindow.get(0);
             structure.setFeatureValue(targetFeature, annotation);

Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/ActionFactory.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/ActionFactory.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/ActionFactory.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/ActionFactory.java Mon Jan  4 10:33:48 2016
@@ -26,7 +26,6 @@ import java.util.logging.Level;
 import org.antlr.runtime.Token;
 import org.apache.uima.ruta.RutaBlock;
 import org.apache.uima.ruta.expression.IRutaExpression;
-import org.apache.uima.ruta.expression.RutaExpression;
 import org.apache.uima.ruta.expression.bool.IBooleanExpression;
 import org.apache.uima.ruta.expression.feature.FeatureMatchExpression;
 import org.apache.uima.ruta.expression.list.ListExpression;
@@ -36,14 +35,14 @@ import org.apache.uima.ruta.expression.n
 import org.apache.uima.ruta.expression.resource.WordListExpression;
 import org.apache.uima.ruta.expression.resource.WordTableExpression;
 import org.apache.uima.ruta.expression.string.IStringExpression;
-import org.apache.uima.ruta.expression.type.TypeExpression;
+import org.apache.uima.ruta.expression.type.ITypeExpression;
 
 public class ActionFactory {
 
   private ActionFactory() {
   }
 
-  public static AbstractRutaAction createColorAction(TypeExpression typeExpr,
+  public static AbstractRutaAction createColorAction(ITypeExpression typeExpr,
           IStringExpression bgcolor, IStringExpression fgcolor, IBooleanExpression selected,
           RutaBlock parent) {
     return new ColorAction(typeExpr, bgcolor, fgcolor, selected);
@@ -53,23 +52,23 @@ public class ActionFactory {
     return new DelAction();
   }
 
-  public static AbstractRutaAction createMarkFastAction(TypeExpression type,
+  public static AbstractRutaAction createMarkFastAction(ITypeExpression type,
           WordListExpression list, IBooleanExpression ignore, INumberExpression ignoreLength,
           IBooleanExpression ignoreWS, RutaBlock parent) {
     return new MarkFastAction(type, list, ignore, ignoreLength, ignoreWS);
   }
 
-  public static AbstractRutaAction createMarkFastAction(TypeExpression type,
+  public static AbstractRutaAction createMarkFastAction(ITypeExpression type,
           StringListExpression list, IBooleanExpression ignore, INumberExpression ignoreLength,
           IBooleanExpression ignoreWS, RutaBlock env) {
     return new MarkFastAction(type, list, ignore, ignoreLength, ignoreWS);
   }
 
-  public static AbstractRutaAction createMarkLastAction(TypeExpression type, RutaBlock parent) {
+  public static AbstractRutaAction createMarkLastAction(ITypeExpression type, RutaBlock parent) {
     return new MarkLastAction(type);
   }
 
-  public static AbstractRutaAction createRetainTypeAction(List<TypeExpression> types,
+  public static AbstractRutaAction createRetainTypeAction(List<ITypeExpression> types,
           RutaBlock parent) {
     return new RetainTypeAction(types);
   }
@@ -81,13 +80,13 @@ public class ActionFactory {
     return new LogAction(expr, level);
   }
 
-  public static AbstractRutaAction createMarkAction(INumberExpression score, TypeExpression type,
+  public static AbstractRutaAction createMarkAction(INumberExpression score, ITypeExpression type,
           List<INumberExpression> list, RutaBlock parent) {
     return new MarkAction(type, score, list);
   }
 
   public static AbstractRutaAction createMarkOnceAction(INumberExpression score,
-          TypeExpression type, List<INumberExpression> list, RutaBlock env) {
+          ITypeExpression type, List<INumberExpression> list, RutaBlock env) {
     return new MarkOnceAction(type, score, list);
   }
 
@@ -95,19 +94,19 @@ public class ActionFactory {
     return new ReplaceAction(lit);
   }
 
-  public static AbstractRutaAction createCreateAction(TypeExpression typeExpr,
+  public static AbstractRutaAction createCreateAction(ITypeExpression typeExpr,
           Map<IStringExpression, IRutaExpression> map, List<INumberExpression> indexes,
           RutaBlock parent) {
     return new CreateAction(typeExpr, map, indexes);
   }
 
-  public static AbstractRutaAction createGatherAction(TypeExpression typeExpr,
+  public static AbstractRutaAction createGatherAction(ITypeExpression typeExpr,
           Map<IStringExpression, IRutaExpression> map, List<INumberExpression> indexes,
           RutaBlock parent) {
     return new GatherAction(typeExpr, map, indexes);
   }
 
-  public static AbstractRutaAction createFillAction(TypeExpression type,
+  public static AbstractRutaAction createFillAction(ITypeExpression type,
           Map<IStringExpression, IRutaExpression> map, RutaBlock parent) {
     return new FillAction(type, map);
   }
@@ -125,27 +124,27 @@ public class ActionFactory {
     return new AssignAction(nv.getText(), e);
   }
 
-  public static AbstractRutaAction createFilterTypeAction(List<TypeExpression> types,
+  public static AbstractRutaAction createFilterTypeAction(List<ITypeExpression> types,
           RutaBlock parent) {
     return new FilterTypeAction(types);
   }
 
-  public static AbstractRutaAction createAddRetainTypeAction(List<TypeExpression> types,
+  public static AbstractRutaAction createAddRetainTypeAction(List<ITypeExpression> types,
           RutaBlock env) {
     return new AddRetainTypeAction(types);
   }
 
-  public static AbstractRutaAction createRemoveRetainTypeAction(List<TypeExpression> types,
+  public static AbstractRutaAction createRemoveRetainTypeAction(List<ITypeExpression> types,
           RutaBlock env) {
     return new RemoveRetainTypeAction(types);
   }
 
-  public static AbstractRutaAction createAddFilterTypeAction(List<TypeExpression> types,
+  public static AbstractRutaAction createAddFilterTypeAction(List<ITypeExpression> types,
           RutaBlock env) {
     return new AddFilterTypeAction(types);
   }
 
-  public static AbstractRutaAction createRemoveFilterTypeAction(List<TypeExpression> types,
+  public static AbstractRutaAction createRemoveFilterTypeAction(List<ITypeExpression> types,
           RutaBlock env) {
     return new RemoveFilterTypeAction(types);
   }
@@ -155,12 +154,12 @@ public class ActionFactory {
     return new SetFeatureAction(f, v);
   }
 
-  public static AbstractRutaAction createUnmarkAction(TypeExpression f,
+  public static AbstractRutaAction createUnmarkAction(ITypeExpression f,
           List<INumberExpression> list, IBooleanExpression b, RutaBlock env) {
     return new UnmarkAction(f, list, b);
   }
 
-  public static AbstractRutaAction createUnmarkAllAction(TypeExpression f, TypeListExpression list,
+  public static AbstractRutaAction createUnmarkAllAction(ITypeExpression f, TypeListExpression list,
           RutaBlock env) {
     return new UnmarkAllAction(f, list);
   }
@@ -174,7 +173,7 @@ public class ActionFactory {
     return new VariableAction(id.getText());
   }
 
-  public static AbstractRutaAction createTransferAction(TypeExpression f, RutaBlock env) {
+  public static AbstractRutaAction createTransferAction(ITypeExpression f, RutaBlock env) {
     return new TransferAction(f);
   }
 
@@ -190,7 +189,7 @@ public class ActionFactory {
     return new ExecAction(ns, tl, view);
   }
 
-  public static AbstractRutaAction createMarkTableAction(TypeExpression structure,
+  public static AbstractRutaAction createMarkTableAction(ITypeExpression structure,
           INumberExpression index, WordTableExpression table,
           Map<IStringExpression, INumberExpression> map, IBooleanExpression ignoreCase,
           INumberExpression ignoreLength, IStringExpression ignoreChar,
@@ -199,6 +198,7 @@ public class ActionFactory {
             maxIgnoreChar);
   }
 
+  @SuppressWarnings("rawtypes")
   public static AbstractRutaAction createMergeAction(IBooleanExpression union, Token target,
           List<ListExpression> list, RutaBlock env) {
     return new MergeAction(union, target == null ? null : target.getText(), list);
@@ -242,7 +242,7 @@ public class ActionFactory {
     return new ClearAction(var == null ? null : var.getText());
   }
 
-  public static AbstractRutaAction createShiftAction(TypeExpression type,
+  public static AbstractRutaAction createShiftAction(ITypeExpression type,
           List<INumberExpression> list, RutaBlock env) {
     return new ShiftAction(type, list);
   }
@@ -252,7 +252,7 @@ public class ActionFactory {
     return new DynamicAnchoringAction(active, penalty, factor);
   }
 
-  public static AbstractRutaAction createTrimAction(List<TypeExpression> types,
+  public static AbstractRutaAction createTrimAction(List<ITypeExpression> types,
           TypeListExpression typeList, RutaBlock env) {
     return new TrimAction(types, typeList);
   }
@@ -261,11 +261,11 @@ public class ActionFactory {
     return new ImplicitFeatureAction(fae);
   }
 
-  public static AbstractRutaAction createAction(TypeExpression te) {
+  public static AbstractRutaAction createAction(ITypeExpression te) {
     return new ImplicitMarkAction(te);
   }
 
-  public static AbstractRutaAction createMarkFirstAction(TypeExpression type, RutaBlock env) {
+  public static AbstractRutaAction createMarkFirstAction(ITypeExpression type, RutaBlock env) {
     return new MarkFirstAction(type);
   }
 
@@ -274,7 +274,7 @@ public class ActionFactory {
     return new GreedyAnchoringAction(active, active2);
   }
 
-  public static AbstractRutaAction createSplitAction(TypeExpression type,
+  public static AbstractRutaAction createSplitAction(ITypeExpression type,
           IBooleanExpression complete, IBooleanExpression appendToBegin,
           IBooleanExpression appendToEnd, RutaBlock env) {
     return new SplitAction(type, complete, appendToBegin, appendToEnd);

Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/AddAction.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/AddAction.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/AddAction.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/AddAction.java Mon Jan  4 10:33:48 2016
@@ -30,9 +30,9 @@ import org.apache.uima.ruta.expression.b
 import org.apache.uima.ruta.expression.list.ListExpression;
 import org.apache.uima.ruta.expression.number.INumberExpression;
 import org.apache.uima.ruta.expression.string.IStringExpression;
-import org.apache.uima.ruta.expression.type.TypeExpression;
+import org.apache.uima.ruta.expression.type.ITypeExpression;
+import org.apache.uima.ruta.rule.MatchContext;
 import org.apache.uima.ruta.rule.RuleElement;
-import org.apache.uima.ruta.rule.RuleMatch;
 import org.apache.uima.ruta.visitor.InferenceCrowd;
 
 public class AddAction extends AbstractRutaAction {
@@ -57,7 +57,8 @@ public class AddAction extends AbstractR
 
   @SuppressWarnings({ "unchecked", "rawtypes" })
   @Override
-  public void execute(RuleMatch match, RuleElement element, RutaStream stream, InferenceCrowd crowd) {
+  public void execute(MatchContext context, RutaStream stream, InferenceCrowd crowd) {
+    RuleElement element = context.getElement();
     RutaBlock parent = element.getParent();
     RutaEnvironment environment = parent.getEnvironment();
     List list = environment.getVariableValue(var, List.class);
@@ -66,17 +67,17 @@ public class AddAction extends AbstractR
     for (IRutaExpression each : elements) {
       if (each instanceof ListExpression) {
         ListExpression l = (ListExpression) each;
-        list.addAll(l.getList(parent, stream));
+        list.addAll(l.getList(context, stream));
       } else if (vgtype.equals(Boolean.class) && each instanceof IBooleanExpression) {
-        list.add(((IBooleanExpression) each).getBooleanValue(parent, match, element, stream));
+        list.add(((IBooleanExpression) each).getBooleanValue(context, stream));
       } else if (vgtype.equals(Integer.class) && each instanceof INumberExpression) {
-        list.add(((INumberExpression) each).getIntegerValue(parent, match, element, stream));
+        list.add(((INumberExpression) each).getIntegerValue(context, stream));
       } else if (vgtype.equals(Double.class) && each instanceof INumberExpression) {
-        list.add(((INumberExpression) each).getDoubleValue(parent, match, element, stream));
-      } else if (vgtype.equals(Type.class) && each instanceof TypeExpression) {
-        list.add(((TypeExpression) each).getType(parent));
+        list.add(((INumberExpression) each).getDoubleValue(context, stream));
+      } else if (vgtype.equals(Type.class) && each instanceof ITypeExpression) {
+        list.add(((ITypeExpression) each).getType(context, stream));
       } else if (vgtype.equals(String.class) && each instanceof IStringExpression) {
-        list.add(((IStringExpression) each).getStringValue(parent, match, element, stream));
+        list.add(((IStringExpression) each).getStringValue(context, stream));
       }
     }
   }

Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/AddFilterTypeAction.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/AddFilterTypeAction.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/AddFilterTypeAction.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/AddFilterTypeAction.java Mon Jan  4 10:33:48 2016
@@ -24,31 +24,31 @@ import java.util.List;
 
 import org.apache.uima.cas.Type;
 import org.apache.uima.ruta.RutaStream;
-import org.apache.uima.ruta.expression.type.TypeExpression;
-import org.apache.uima.ruta.rule.RuleElement;
-import org.apache.uima.ruta.rule.RuleMatch;
+import org.apache.uima.ruta.expression.type.ITypeExpression;
+import org.apache.uima.ruta.rule.MatchContext;
 import org.apache.uima.ruta.visitor.InferenceCrowd;
 
 public class AddFilterTypeAction extends AbstractRutaAction {
 
-  public List<TypeExpression> getList() {
-    return list;
-  }
-
-  private List<TypeExpression> list;
-
-  public AddFilterTypeAction(List<TypeExpression> list) {
+  public AddFilterTypeAction(List<ITypeExpression> list) {
     super();
     this.list = list;
   }
 
   @Override
-  public void execute(RuleMatch match, RuleElement element, RutaStream stream, InferenceCrowd crowd) {
+  public void execute(MatchContext context, RutaStream stream, InferenceCrowd crowd) {
     List<Type> types = new ArrayList<Type>();
-    for (TypeExpression each : list) {
-      types.add(each.getType(element.getParent()));
+    for (ITypeExpression each : list) {
+      types.add(each.getType(context, stream));
     }
     stream.addFilterTypes(types);
   }
 
+  public List<ITypeExpression> getList() {
+    return list;
+  }
+
+  private List<ITypeExpression> list;
+
+  
 }

Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/AddRetainTypeAction.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/AddRetainTypeAction.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/AddRetainTypeAction.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/AddRetainTypeAction.java Mon Jan  4 10:33:48 2016
@@ -24,31 +24,29 @@ import java.util.List;
 
 import org.apache.uima.cas.Type;
 import org.apache.uima.ruta.RutaStream;
-import org.apache.uima.ruta.expression.type.TypeExpression;
-import org.apache.uima.ruta.rule.RuleElement;
-import org.apache.uima.ruta.rule.RuleMatch;
+import org.apache.uima.ruta.expression.type.ITypeExpression;
+import org.apache.uima.ruta.rule.MatchContext;
 import org.apache.uima.ruta.visitor.InferenceCrowd;
 
 public class AddRetainTypeAction extends AbstractRutaAction {
 
-  public List<TypeExpression> getList() {
-    return list;
-  }
-
-  private List<TypeExpression> list;
-
-  public AddRetainTypeAction(List<TypeExpression> list) {
+  public AddRetainTypeAction(List<ITypeExpression> list) {
     super();
     this.list = list;
   }
 
   @Override
-  public void execute(RuleMatch match, RuleElement element, RutaStream stream, InferenceCrowd crowd) {
+  public void execute(MatchContext context, RutaStream stream, InferenceCrowd crowd) {
     List<Type> types = new ArrayList<Type>();
-    for (TypeExpression each : list) {
-      types.add(each.getType(element.getParent()));
+    for (ITypeExpression each : list) {
+      types.add(each.getType(context, stream));
     }
     stream.addRetainTypes(types);
   }
 
+  public List<ITypeExpression> getList() {
+    return list;
+  }
+  
+  private List<ITypeExpression> list;
 }

Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/AssignAction.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/AssignAction.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/AssignAction.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/AssignAction.java Mon Jan  4 10:33:48 2016
@@ -27,9 +27,9 @@ import org.apache.uima.ruta.expression.I
 import org.apache.uima.ruta.expression.bool.IBooleanExpression;
 import org.apache.uima.ruta.expression.number.INumberExpression;
 import org.apache.uima.ruta.expression.string.IStringExpression;
-import org.apache.uima.ruta.expression.type.TypeExpression;
+import org.apache.uima.ruta.expression.type.ITypeExpression;
+import org.apache.uima.ruta.rule.MatchContext;
 import org.apache.uima.ruta.rule.RuleElement;
-import org.apache.uima.ruta.rule.RuleMatch;
 import org.apache.uima.ruta.visitor.InferenceCrowd;
 
 public class AssignAction extends AbstractRutaAction {
@@ -45,24 +45,25 @@ public class AssignAction extends Abstra
   }
 
   @Override
-  public void execute(RuleMatch match, RuleElement element, RutaStream stream, InferenceCrowd crowd) {
+  public void execute(MatchContext context, RutaStream stream, InferenceCrowd crowd) {
+    RuleElement element = context.getElement();
     RutaBlock parent = element.getParent();
     RutaEnvironment environment = parent.getEnvironment();
     Class<?> clazz = environment.getVariableType(var);
     if (clazz.equals(Double.class) && expression instanceof INumberExpression) {
-      double v = ((INumberExpression) expression).getDoubleValue(parent, match, element, stream);
+      double v = ((INumberExpression) expression).getDoubleValue(context, stream);
       environment.setVariableValue(var, v);
     } else if (clazz.equals(Integer.class) && expression instanceof INumberExpression) {
-      int v = ((INumberExpression) expression).getIntegerValue(parent, match, element, stream);
+      int v = ((INumberExpression) expression).getIntegerValue(context, stream);
       environment.setVariableValue(var, v);
-    } else if (clazz.equals(Type.class) && expression instanceof TypeExpression) {
-      Type v = ((TypeExpression) expression).getType(parent);
+    } else if (clazz.equals(Type.class) && expression instanceof ITypeExpression) {
+      Type v = ((ITypeExpression) expression).getType(context, stream);
       environment.setVariableValue(var, v);
     } else if (clazz.equals(Boolean.class) && expression instanceof IBooleanExpression) {
-      boolean v = ((IBooleanExpression) expression).getBooleanValue(parent, match, element, stream);
+      boolean v = ((IBooleanExpression) expression).getBooleanValue(context, stream);
       environment.setVariableValue(var, v);
     } else if (clazz.equals(String.class) && expression instanceof IStringExpression) {
-      String v = ((IStringExpression) expression).getStringValue(parent, match, element, stream);
+      String v = ((IStringExpression) expression).getStringValue(context, stream);
       environment.setVariableValue(var, v);
     }
   }

Modified: uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/CallAction.java
URL: http://svn.apache.org/viewvc/uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/CallAction.java?rev=1722834&r1=1722833&r2=1722834&view=diff
==============================================================================
--- uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/CallAction.java (original)
+++ uima/ruta/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/CallAction.java Mon Jan  4 10:33:48 2016
@@ -39,6 +39,7 @@ import org.apache.uima.ruta.RutaBlock;
 import org.apache.uima.ruta.RutaModule;
 import org.apache.uima.ruta.RutaStream;
 import org.apache.uima.ruta.ScriptApply;
+import org.apache.uima.ruta.rule.MatchContext;
 import org.apache.uima.ruta.rule.RuleElement;
 import org.apache.uima.ruta.rule.RuleMatch;
 import org.apache.uima.ruta.type.RutaBasic;
@@ -54,12 +55,13 @@ public class CallAction extends Abstract
   }
 
   @Override
-  public void execute(RuleMatch match, RuleElement element, RutaStream stream, InferenceCrowd crowd) {
+  public void execute(MatchContext context, RutaStream stream, InferenceCrowd crowd) {
+    RuleElement element = context.getElement();
     RutaModule thisScript = element.getParent().getScript();
     AnalysisEngine targetEngine = thisScript.getEngine(namespace);
     if (targetEngine != null) {
       try {
-        callEngine(match, crowd, targetEngine, element, stream);
+        callEngine(context, crowd, targetEngine, stream);
       } catch (AnalysisEngineProcessException e) {
         e.printStackTrace();
       } catch (ResourceInitializationException e) {
@@ -68,7 +70,7 @@ public class CallAction extends Abstract
     } else {
       RutaBlock block = thisScript.getBlock(namespace);
       if (block != null) {
-        callScript(block, match, element, stream, crowd);
+        callScript(block, context, stream, crowd);
       } else {
         System.out.println("Found no script/block: " + namespace);
       }
@@ -76,8 +78,10 @@ public class CallAction extends Abstract
 
   }
 
-  protected void callScript(RutaBlock block, RuleMatch match, RuleElement element,
-          RutaStream stream, InferenceCrowd crowd) {
+  protected void callScript(RutaBlock block, MatchContext context, RutaStream stream,
+          InferenceCrowd crowd) {
+    RuleElement element = context.getElement();
+    RuleMatch match = context.getRuleMatch();
     List<AnnotationFS> matchedAnnotationsOf = match.getMatchedAnnotationsOfElement(element);
     for (AnnotationFS annotationFS : matchedAnnotationsOf) {
       RutaStream windowStream = stream.getWindowStream(annotationFS,
@@ -88,10 +92,13 @@ public class CallAction extends Abstract
 
   }
 
-  protected void callEngine(RuleMatch match, InferenceCrowd crowd, AnalysisEngine targetEngine,
-          RuleElement element, RutaStream stream) throws ResourceInitializationException,
+  protected void callEngine(MatchContext context, InferenceCrowd crowd,
+          AnalysisEngine targetEngine, RutaStream stream) throws ResourceInitializationException,
           AnalysisEngineProcessException {
 
+    RuleElement element = context.getElement();
+    RuleMatch match = context.getRuleMatch();
+
     List<AnnotationFS> matchedAnnotations = match.getMatchedAnnotations(null,
             element.getContainer());
     for (AnnotationFS matchedAnnotation : matchedAnnotations) {