Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java?rev=1851430&r1=1851429&r2=1851430&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/RutaStream.java Wed Jan 16 11:45:02 2019 @@ -52,6 +52,7 @@ import org.apache.uima.cas.Type; import org.apache.uima.cas.TypeSystem; import org.apache.uima.cas.text.AnnotationFS; import org.apache.uima.cas.text.AnnotationIndex; +import org.apache.uima.fit.util.CasUtil; import org.apache.uima.fit.util.FSCollectionFactory; import org.apache.uima.jcas.JCas; import org.apache.uima.jcas.tcas.Annotation; @@ -65,6 +66,7 @@ import org.apache.uima.ruta.expression.b import org.apache.uima.ruta.expression.bool.IBooleanListExpression; import org.apache.uima.ruta.expression.feature.FeatureExpression; import org.apache.uima.ruta.expression.feature.GenericFeatureExpression; +import org.apache.uima.ruta.expression.feature.LazyFeature; import org.apache.uima.ruta.expression.feature.SimpleFeatureExpression; import org.apache.uima.ruta.expression.number.INumberExpression; import org.apache.uima.ruta.expression.number.INumberListExpression; @@ -128,6 +130,10 @@ public class RutaStream { private boolean emptyIsInvisible; + private long maxRuleMatches; + + private long maxRuleElementMatches; + public RutaStream(CAS cas, Type basicType, FilterManager filter, boolean lowMemoryProfile, boolean simpleGreedyForComposed, boolean emptyIsInvisible, TypeUsageInformation typeUsage, InferenceCrowd crowd) { @@ -482,6 +488,8 @@ public class RutaStream { stream.setDynamicAnchoring(dynamicAnchoring); stream.setGreedyRuleElement(greedyRuleElement); stream.setGreedyRule(greedyRule); + stream.setMaxRuleMatches(maxRuleMatches); + stream.setMaxRuleElementMatches(maxRuleElementMatches); return stream; } @@ -491,6 +499,8 @@ public class RutaStream { stream.setDynamicAnchoring(dynamicAnchoring); stream.setGreedyRuleElement(greedyRuleElement); stream.setGreedyRule(greedyRule); + stream.setMaxRuleMatches(maxRuleMatches); + stream.setMaxRuleElementMatches(maxRuleElementMatches); return stream; } @@ -510,6 +520,14 @@ public class RutaStream { } } + public boolean hasNext() { + return currentIt.hasNext(); + } + + public AnnotationFS next() { + return currentIt.next(); + } + public void moveToFirst() { currentIt.moveToFirst(); } @@ -587,51 +605,17 @@ public class RutaStream { return result; } - private List<AnnotationFS> getAnnotationsInWindow2(AnnotationFS windowAnnotation, Type type) { - List<AnnotationFS> result = new ArrayList<AnnotationFS>(); - windowAnnotation = cas.createAnnotation(type, windowAnnotation.getBegin(), - windowAnnotation.getEnd() + 1); - FSIterator<AnnotationFS> completeIt = getCas().getAnnotationIndex(type).iterator(); - if (getDocumentAnnotation().getEnd() < windowAnnotation.getEnd()) { - completeIt.moveToLast(); - } else { - completeIt.moveTo(windowAnnotation); - } - while (completeIt.isValid() - && ((Annotation) completeIt.get()).getBegin() >= windowAnnotation.getBegin()) { - completeIt.moveToPrevious(); - } - - if (completeIt.isValid()) { - completeIt.moveToNext(); - } else { - completeIt.moveToFirst(); - } - - while (completeIt.isValid() - && ((Annotation) completeIt.get()).getBegin() < windowAnnotation.getBegin()) { - completeIt.moveToNext(); - } - - while (completeIt.isValid() - && ((Annotation) completeIt.get()).getBegin() >= windowAnnotation.getBegin()) { - Annotation annotation = (Annotation) completeIt.get(); - if (getCas().getTypeSystem().subsumes(type, annotation.getType()) - && annotation.getEnd() <= windowAnnotation.getEnd()) { - result.add(annotation); - } - completeIt.moveToNext(); - } - return result; - } - public List<AnnotationFS> getAnnotationsInWindow(AnnotationFS windowAnnotation, Type type) { + if (windowAnnotation == null || type == null) { return Collections.emptyList(); } + TypeSystem typeSystem = this.getCas().getTypeSystem(); List<AnnotationFS> result = new ArrayList<AnnotationFS>(); - List<AnnotationFS> inWindow = getAnnotationsInWindow2(windowAnnotation, type); - result = inWindow; + if (typeSystem.subsumes(type, windowAnnotation.getType())) { + result.add(windowAnnotation); + } + result.addAll(CasUtil.selectCovered(this.cas, type, windowAnnotation)); return result; } @@ -657,45 +641,43 @@ public class RutaStream { } public RutaBasic getBasicNextTo(boolean before, AnnotationFS annotation) { + if (annotation == null) { - return beginAnchors.get(0); + return null; } + if (before) { - RutaBasic pointer = beginAnchors.get(annotation.getBegin()); - moveTo(pointer); - if (isVisible(pointer) || !isValid()) { - moveToPrevious(); - } - if (!isValid()) { - moveToLast(); - } - if (isValid()) { - RutaBasic nextBasic = (RutaBasic) get(); - // TODO HOTFIX for annotation of length 0 - while (isValid() && nextBasic.getEnd() > annotation.getBegin()) { - moveToPrevious(); - if (isValid()) { - nextBasic = (RutaBasic) get(); - } + + RutaBasic pointer = endAnchors.get(annotation.getBegin()); + while (pointer != null && pointer.getBegin() >= documentAnnotation.getBegin()) { + + if (isVisible(pointer)) { + return pointer; + } + + Entry<Integer, RutaBasic> lowerEntry = endAnchors.lowerEntry(pointer.getEnd()); + if (lowerEntry != null) { + pointer = lowerEntry.getValue(); + } else { + pointer = null; } - return nextBasic; } + } else { - RutaBasic pointer = endAnchors.get(annotation.getEnd()); - moveTo(pointer); - if (isVisible(pointer)) { - moveToNext(); - } - if (isValid()) { - RutaBasic nextBasic = (RutaBasic) get(); - // TODO HOTFIX for annotation of length 0 - while (isValid() && nextBasic.getBegin() < annotation.getEnd()) { - moveToNext(); - if (isValid()) { - nextBasic = (RutaBasic) get(); - } + + RutaBasic pointer = beginAnchors.get(annotation.getEnd()); + while (pointer != null && pointer.getEnd() <= documentAnnotation.getEnd()) { + + if (isVisible(pointer)) { + return pointer; + } + + Entry<Integer, RutaBasic> higherEntry = beginAnchors.higherEntry(pointer.getBegin()); + if (higherEntry != null) { + pointer = higherEntry.getValue(); + } else { + pointer = null; } - return nextBasic; } } return null; @@ -746,23 +728,12 @@ public class RutaStream { return basicIt; } - public AnnotationFS getDocumentAnnotation() { - return documentAnnotation; + public FSIterator<AnnotationFS> getCurrentIterator() { + return currentIt; } - public RutaAnnotation getCorrectTMA(List<AnnotationFS> annotationsInWindow, - RutaAnnotation heuristicAnnotation) { - for (AnnotationFS annotation : annotationsInWindow) { - if (annotation instanceof RutaAnnotation) { - RutaAnnotation tma = (RutaAnnotation) annotation; - if (tma.getBegin() == heuristicAnnotation.getBegin() - && tma.getEnd() == heuristicAnnotation.getEnd() && tma.getAnnotation().getType() - .equals(heuristicAnnotation.getAnnotation().getType())) { - return tma; - } - } - } - return null; + public AnnotationFS getDocumentAnnotation() { + return documentAnnotation; } public void retainTypes(List<Type> list) { @@ -1006,7 +977,8 @@ public class RutaStream { Feature feature = type.getFeatureByBaseName(featureName); if (feature == null) { throw new IllegalArgumentException("Not able to assign feature value for feature '" - + featureName + "'. Feature is not defined for type '" + type.getName() + "'"); + + featureName + "'. Feature is not defined for type '" + type.getName() + "'" + + " in script " + context.getParent().getName()); } assignFeatureValue(annotation, feature, value, context); } @@ -1015,12 +987,21 @@ public class RutaStream { public void assignFeatureValue(FeatureStructure annotation, Feature feature, IRutaExpression value, MatchContext context) { if (feature == null) { - throw new IllegalArgumentException("Not able to assign feature value (e.g., coveredText)."); + throw new IllegalArgumentException( + "Not able to assign feature value (e.g., coveredText) in script " + + context.getParent().getName()); + } + if (feature instanceof LazyFeature) { + LazyFeature lazyFeature = (LazyFeature) feature; + feature = lazyFeature.initialize(annotation); } + CAS cas = annotation.getCAS(); + TypeSystem typeSystem = cas.getTypeSystem(); Type range = feature.getRange(); String rangeName = range.getName(); - if (rangeName.equals(CAS.TYPE_NAME_STRING)) { + + if (typeSystem.subsumes(typeSystem.getType(CAS.TYPE_NAME_STRING), range)) { if (value instanceof IStringExpression) { IStringExpression stringExpr = (IStringExpression) value; String string = stringExpr.getStringValue(context, this); @@ -1269,7 +1250,7 @@ public class RutaStream { public List<AnnotationFS> getBestGuessedAnnotationsAt(AnnotationFS window, Type type) { List<AnnotationFS> result = new ArrayList<AnnotationFS>(); - if (window == null) { + if (window == null || type == null) { return result; } TypeSystem typeSystem = getCas().getTypeSystem(); @@ -1371,8 +1352,39 @@ public class RutaStream { return cas.getAnnotationType(); } - public FSIterator<AnnotationFS> getCurrentIt() { - return currentIt; + public RutaAnnotation getRutaAnnotationFor(AnnotationFS annotation, boolean create, + RutaStream stream) { + Type heuristicType = this.cas.getTypeSystem().getType(RutaAnnotation.class.getName()); + List<AnnotationFS> ras = CasUtil.selectAt(this.cas, heuristicType, annotation.getBegin(), + annotation.getEnd()); + for (AnnotationFS each : ras) { + if (((RutaAnnotation) each).getAnnotation() == annotation) { + return (RutaAnnotation) each; + } + } + if (create) { + JCas jCas = stream.getJCas(); + RutaAnnotation result = new RutaAnnotation(jCas, annotation.getBegin(), annotation.getEnd()); + result.setAnnotation((Annotation) annotation); + result.addToIndexes(); + return result; + } + return null; + } + + public void setMaxRuleMatches(long maxRuleMatches) { + this.maxRuleMatches = maxRuleMatches; + } + + public void setMaxRuleElementMatches(long maxRuleElementMatches) { + this.maxRuleElementMatches = maxRuleElementMatches; + } + + public long getMaxRuleMatches() { + return this.maxRuleMatches; } + public long getMaxRuleElementMatches() { + return this.maxRuleElementMatches; + } }
Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/AbstractMarkAction.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/AbstractMarkAction.java?rev=1851430&r1=1851429&r2=1851430&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/AbstractMarkAction.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/AbstractMarkAction.java Wed Jan 16 11:45:02 2019 @@ -40,6 +40,10 @@ public abstract class AbstractMarkAction protected Annotation createAnnotation(AnnotationFS annotation, MatchContext context, RutaStream stream) { Type t = type.getType(context, stream); + if (t == null) { + return null; + } + AnnotationFS newAnnotationFS = stream.getCas().createAnnotation(t, annotation.getBegin(), annotation.getEnd()); Annotation newAnnotation = null; @@ -50,6 +54,7 @@ public abstract class AbstractMarkAction return null; } stream.addAnnotation(newAnnotation, context.getRuleMatch()); + addAnnotationToLabel(newAnnotation, context); return newAnnotation; } Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/AbstractRutaAction.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/AbstractRutaAction.java?rev=1851430&r1=1851429&r2=1851430&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/AbstractRutaAction.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/AbstractRutaAction.java Wed Jan 16 11:45:02 2019 @@ -20,9 +20,13 @@ package org.apache.uima.ruta.action; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; +import org.apache.commons.lang3.StringUtils; +import org.apache.uima.cas.text.AnnotationFS; import org.apache.uima.ruta.RutaElement; +import org.apache.uima.ruta.RutaEnvironment; import org.apache.uima.ruta.RutaStream; import org.apache.uima.ruta.expression.number.INumberExpression; import org.apache.uima.ruta.rule.MatchContext; @@ -31,6 +35,8 @@ import org.apache.uima.ruta.visitor.Infe public abstract class AbstractRutaAction extends RutaElement { + private String label; + public AbstractRutaAction() { super(); } @@ -42,7 +48,8 @@ public abstract class AbstractRutaAction return getClass().getSimpleName(); } - protected List<Integer> getIndexList(List<INumberExpression> indexes, MatchContext context, RutaStream stream) { + 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()) { @@ -61,5 +68,28 @@ public abstract class AbstractRutaAction } return indexList; } - + + public void setLabel(String label) { + this.label = label; + } + + public String getLabel() { + return this.label; + } + + protected void addAnnotationToLabel(AnnotationFS annotation, MatchContext context) { + if (StringUtils.isBlank(label)) { + return; + } + RutaEnvironment environment = context.getParent().getEnvironment(); + + Class<?> variableType = environment.getVariableType(label); + if (List.class.equals(variableType) + && AnnotationFS.class.equals(environment.getVariableGenericType(label))) { + environment.setVariableValue(label, Arrays.asList(annotation)); + } else if (AnnotationFS.class.equals(variableType)) { + environment.setVariableValue(label, annotation); + } + } + } Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/ActionFactory.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/ActionFactory.java?rev=1851430&r1=1851429&r2=1851430&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/ActionFactory.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/ActionFactory.java Wed Jan 16 11:45:02 2019 @@ -48,7 +48,7 @@ public class ActionFactory { private TypeUsageInformation typeUsage; private RutaVerbalizer verbalizer; - + public ActionFactory(TypeUsageInformation typeUsage) { super(); this.typeUsage = typeUsage; @@ -180,7 +180,8 @@ public class ActionFactory { if (a instanceof AnnotationTypeExpression) { return new UnmarkAction((AnnotationTypeExpression) a); } - throw new IllegalArgumentException("Expression " + a + " is nto a valid argument for UNMARK."); + throw new IllegalArgumentException("Expression " + a + + " is not a valid argument for UNMARK in script " + env.getName() + "."); } public AbstractRutaAction createUnmarkAllAction(ITypeExpression f, @@ -322,18 +323,19 @@ public class ActionFactory { List<AbstractRutaAction> actions = macroActionDefinition.getMiddle(); Set<String> vars = macroActionDefinition.getRight(); if (definition.size() != argSize) { - throw new RutaParseRuntimeException("Arguments of macro action '" + name - + "' do not match its definition: " + definition.values()); + throw new RutaParseRuntimeException( + "Arguments of macro action '" + name + "' do not match its definition: " + + definition.values() + " (in script " + env.getName() + ")"); } return new MacroAction(name, definition, actions, vars, args); } private void removeMention(ITypeExpression type) { - if(typeUsage != null) { + if (typeUsage != null) { String verbalize = verbalizer.verbalize(type); typeUsage.removeMentionedType(verbalize); } } - + } Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/AddFilterTypeAction.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/AddFilterTypeAction.java?rev=1851430&r1=1851429&r2=1851430&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/AddFilterTypeAction.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/AddFilterTypeAction.java Wed Jan 16 11:45:02 2019 @@ -39,7 +39,10 @@ public class AddFilterTypeAction extends public void execute(MatchContext context, RutaStream stream, InferenceCrowd crowd) { List<Type> types = new ArrayList<Type>(); for (ITypeExpression each : list) { - types.add(each.getType(context, stream)); + Type type = each.getType(context, stream); + if (type != null) { + types.add(type); + } } stream.addFilterTypes(types); } @@ -50,5 +53,4 @@ public class AddFilterTypeAction extends private List<ITypeExpression> list; - } Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/AddRetainTypeAction.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/AddRetainTypeAction.java?rev=1851430&r1=1851429&r2=1851430&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/AddRetainTypeAction.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/AddRetainTypeAction.java Wed Jan 16 11:45:02 2019 @@ -39,7 +39,10 @@ public class AddRetainTypeAction extends public void execute(MatchContext context, RutaStream stream, InferenceCrowd crowd) { List<Type> types = new ArrayList<Type>(); for (ITypeExpression each : list) { - types.add(each.getType(context, stream)); + Type type = each.getType(context, stream); + if (type != null) { + types.add(type); + } } stream.addRetainTypes(types); } @@ -47,6 +50,6 @@ public class AddRetainTypeAction extends public List<ITypeExpression> getList() { return list; } - + private List<ITypeExpression> list; } Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/CallAction.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/CallAction.java?rev=1851430&r1=1851429&r2=1851430&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/CallAction.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/CallAction.java Wed Jan 16 11:45:02 2019 @@ -73,7 +73,7 @@ public class CallAction extends Abstract callScript(block, context, stream, crowd); } else { if(targetEngine == null) { - throw new IllegalArgumentException("Analysis Engine or Script/Block with name '"+namespace+"' is unknown."); + throw new IllegalArgumentException("Analysis Engine or Script/Block with name '"+namespace+"' is unknown in script " + context.getParent().getName() + "."); } } } Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/ConfigureAction.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/ConfigureAction.java?rev=1851430&r1=1851429&r2=1851430&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/ConfigureAction.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/ConfigureAction.java Wed Jan 16 11:45:02 2019 @@ -64,8 +64,9 @@ public class ConfigureAction extends Abs RutaBlock parent = element.getParent(); RutaModule thisScript = parent.getScript(); AnalysisEngine targetEngine = thisScript.getEngine(namespace); - if(targetEngine == null) { - throw new IllegalArgumentException("Analysis Engine with name '"+namespace+"' is unknown."); + if (targetEngine == null) { + throw new IllegalArgumentException("Analysis Engine with name '" + namespace + + "' is unknown in script " + context.getParent().getName() + "."); } ConfigurationParameterDeclarations configurationParameterDeclarations = targetEngine .getAnalysisEngineMetaData().getConfigurationParameterDeclarations(); @@ -102,7 +103,9 @@ public class ConfigureAction extends Abs } else if (value instanceof ITypeExpression) { ITypeExpression te = (ITypeExpression) value; Type t = te.getType(context, stream); - targetEngine.setConfigParameterValue(stringValue, t.getName()); + if (t != null) { + targetEngine.setConfigParameterValue(stringValue, t.getName()); + } } } } else if (type.equals("Float")) { Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/CreateAction.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/CreateAction.java?rev=1851430&r1=1851429&r2=1851430&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/CreateAction.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/CreateAction.java Wed Jan 16 11:45:02 2019 @@ -65,14 +65,17 @@ public class CreateAction extends Abstra return; } Type type = structureType.getType(context, stream); - AnnotationFS annotation = stream.getCas().createAnnotation(type, 0, 0); - if (annotation instanceof Annotation) { - Annotation a = (Annotation) annotation; - a.setBegin(matchedAnnotation.getBegin()); - a.setEnd(matchedAnnotation.getEnd()); - context.setAnnotation(matchedAnnotation); - stream.assignFeatureValues(annotation, features, context); - stream.addAnnotation(a, true, match); + if (type != null) { + AnnotationFS annotation = stream.getCas().createAnnotation(type, 0, 0); + if (annotation instanceof Annotation) { + Annotation a = (Annotation) annotation; + a.setBegin(matchedAnnotation.getBegin()); + a.setEnd(matchedAnnotation.getEnd()); + context.setAnnotation(matchedAnnotation); + stream.assignFeatureValues(annotation, features, context); + stream.addAnnotation(a, true, match); + addAnnotationToLabel(a, context); + } } } } Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/ExecAction.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/ExecAction.java?rev=1851430&r1=1851429&r2=1851430&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/ExecAction.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/ExecAction.java Wed Jan 16 11:45:02 2019 @@ -19,6 +19,8 @@ package org.apache.uima.ruta.action; +import static org.apache.uima.util.Level.SEVERE; + import java.util.Collection; import java.util.LinkedList; import java.util.List; @@ -67,25 +69,26 @@ public class ExecAction extends CallActi } @Override - protected void callEngine(MatchContext context, InferenceCrowd crowd, - AnalysisEngine targetEngine, RutaStream stream) throws ResourceInitializationException, - AnalysisEngineProcessException { + protected void callEngine(MatchContext context, InferenceCrowd crowd, AnalysisEngine targetEngine, + RutaStream stream) + throws ResourceInitializationException, AnalysisEngineProcessException { CAS cas = stream.getCas(); if (view != null) { String viewName = view.getStringValue(context, stream); - if (!viewName.equals(CAS.NAME_DEFAULT_SOFA)) { + if (viewName != null && !viewName.equals(CAS.NAME_DEFAULT_SOFA)) { cas = cas.getView(viewName); AnalysisEngineMetaData metaData = targetEngine.getAnalysisEngineMetaData(); try { String sourceUrlString = metaData.getSourceUrlString(); if (sourceUrlString != null) { - AnalysisEngineDescription aed = (AnalysisEngineDescription) UIMAFramework - .getXMLParser().parseResourceSpecifier(new XMLInputSource(sourceUrlString)); + AnalysisEngineDescription aed = (AnalysisEngineDescription) UIMAFramework.getXMLParser() + .parseResourceSpecifier(new XMLInputSource(sourceUrlString)); AnalysisEngine createEngine = AnalysisEngineFactory.createEngine(aed, viewName); targetEngine = createEngine; } } catch (Exception e) { - e.printStackTrace(); + UIMAFramework.getLogger(getClass()).log(SEVERE, "Failed to initialize AnalysisEngine.", + e); } } } Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/FillAction.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/FillAction.java?rev=1851430&r1=1851429&r2=1851430&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/FillAction.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/FillAction.java Wed Jan 16 11:45:02 2019 @@ -39,7 +39,8 @@ public class FillAction extends Abstract private ITypeExpression structureType; - public FillAction(ITypeExpression structureType, Map<IStringExpression, IRutaExpression> features) { + public FillAction(ITypeExpression structureType, + Map<IStringExpression, IRutaExpression> features) { super(); this.structureType = structureType; this.features = features; @@ -49,12 +50,16 @@ public class FillAction extends Abstract public void execute(MatchContext context, RutaStream stream, InferenceCrowd crowd) { RuleMatch match = context.getRuleMatch(); RuleElement element = context.getElement(); + Type type = getStructureType().getType(context, stream); + if (type == null) { + return; + } + List<AnnotationFS> matchedAnnotations = match.getMatchedAnnotationsOfElement(element); for (AnnotationFS matchedAnnotation : matchedAnnotations) { if (matchedAnnotation == null) { return; } - Type type = getStructureType().getType(context, stream); List<AnnotationFS> list = stream.getAnnotationsInWindow(matchedAnnotation, type); if (list.isEmpty()) { list = stream.getOverappingAnnotations(matchedAnnotation, type); @@ -77,6 +82,7 @@ public class FillAction extends Abstract context.setAnnotation(matchedAnnotation); stream.assignFeatureValues(annotationFS, features, context); stream.getCas().addFsToIndexes(annotationFS); + addAnnotationToLabel(annotationFS, context); } } Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/FilterTypeAction.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/FilterTypeAction.java?rev=1851430&r1=1851429&r2=1851430&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/FilterTypeAction.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/FilterTypeAction.java Wed Jan 16 11:45:02 2019 @@ -30,7 +30,6 @@ import org.apache.uima.ruta.visitor.Infe public class FilterTypeAction extends AbstractRutaAction { - public FilterTypeAction(List<ITypeExpression> list) { super(); this.list = list; @@ -41,7 +40,10 @@ public class FilterTypeAction extends Ab context.getElement(); List<Type> types = new ArrayList<Type>(); for (ITypeExpression each : list) { - types.add(each.getType(context, stream)); + Type type = each.getType(context, stream); + if (type != null) { + types.add(type); + } } stream.filterTypes(types); } @@ -49,7 +51,7 @@ public class FilterTypeAction extends Ab public List<ITypeExpression> getList() { return list; } - + private List<ITypeExpression> list; } Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/GatherAction.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/GatherAction.java?rev=1851430&r1=1851429&r2=1851430&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/GatherAction.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/GatherAction.java Wed Jan 16 11:45:02 2019 @@ -71,6 +71,12 @@ public class GatherAction extends Abstra public void execute(MatchContext context, RutaStream stream, InferenceCrowd crowd) { RuleMatch match = context.getRuleMatch(); RuleElement element = context.getElement(); + Type type = structureType.getType(context, stream); + + if (type == null) { + return; + } + List<Integer> indexList = getIndexList(indexes, context, stream); List<AnnotationFS> matchedAnnotations = match.getMatchedAnnotations(indexList, element.getContainer()); @@ -78,13 +84,13 @@ public class GatherAction extends Abstra if (matchedAnnotation == null) { return; } - Type type = structureType.getType(context, stream); FeatureStructure newFS = stream.getCas().createFS(type); if (newFS instanceof Annotation) { Annotation a = (Annotation) newFS; a.setBegin(matchedAnnotation.getBegin()); a.setEnd(matchedAnnotation.getEnd()); stream.addAnnotation(a, match); + addAnnotationToLabel(a, context); } TOP newStructure = null; if (newFS instanceof TOP) { @@ -144,8 +150,8 @@ public class GatherAction extends Abstra // search for Collection<AnnotationFS> beginAnchors = stream.getBeginAnchor(fs.getBegin()) .getBeginAnchors(range); - Collection<AnnotationFS> endAnchors = stream.getEndAnchor(fs.getEnd()).getEndAnchors( - range); + Collection<AnnotationFS> endAnchors = stream.getEndAnchor(fs.getEnd()) + .getEndAnchors(range); @SuppressWarnings("unchecked") Collection<AnnotationFS> intersection = CollectionUtils.intersection(beginAnchors, endAnchors); @@ -209,7 +215,6 @@ public class GatherAction extends Abstra return result; } - public ITypeExpression getStructureType() { return structureType; } Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/GetFeatureAction.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/GetFeatureAction.java?rev=1851430&r1=1851429&r2=1851430&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/GetFeatureAction.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/GetFeatureAction.java Wed Jan 16 11:45:02 2019 @@ -24,6 +24,7 @@ import java.util.List; import org.apache.uima.cas.CAS; import org.apache.uima.cas.Feature; import org.apache.uima.cas.Type; +import org.apache.uima.cas.TypeSystem; import org.apache.uima.cas.text.AnnotationFS; import org.apache.uima.ruta.RutaEnvironment; import org.apache.uima.ruta.RutaStream; @@ -58,20 +59,27 @@ public class GetFeatureAction extends Ab if (element instanceof RutaRuleElement) { type = ((RutaRuleElement) element).getMatcher().getType(parent, stream); } + if (type == null) { + return; + } + String stringValue = featureStringExpression.getStringValue(context, stream); Feature featureByBaseName = type.getFeatureByBaseName(stringValue); RutaEnvironment environment = parent.getEnvironment(); List<AnnotationFS> matchedAnnotations = match.getMatchedAnnotationsOfElement(element); for (AnnotationFS annotationFS : matchedAnnotations) { if (annotationFS.getType().getFeatureByBaseName(stringValue) == null) { + // TODO replace syso by logger System.out.println("Can't access feature " + stringValue + ", because it's not defined in the matched type: " + annotationFS.getType()); return; } - String featName = featureByBaseName.getRange().getName(); + TypeSystem typeSystem = stream.getCas().getTypeSystem(); + Type range = featureByBaseName.getRange(); + String featName = range.getName(); if (environment.getVariableType(variable).equals(String.class) - && featName.equals(CAS.TYPE_NAME_STRING)) { + && typeSystem.subsumes(typeSystem.getType(CAS.TYPE_NAME_STRING), range)) { Object value = annotationFS.getStringValue(featureByBaseName); environment.setVariableValue(variable, value); } else if (Number.class.isAssignableFrom(environment.getVariableType(variable))) { @@ -95,7 +103,7 @@ public class GetFeatureAction extends Ab Object value = annotationFS.getBooleanValue(featureByBaseName); environment.setVariableValue(variable, value); } else if (environment.getVariableType(variable).equals(Type.class) - && featName.equals(CAS.TYPE_NAME_STRING)) { + && typeSystem.subsumes(typeSystem.getType(CAS.TYPE_NAME_STRING), range)) { Object value = annotationFS.getStringValue(featureByBaseName); Type t = stream.getCas().getTypeSystem().getType((String) value); if (t != null) { Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/MarkAction.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/MarkAction.java?rev=1851430&r1=1851429&r2=1851430&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/MarkAction.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/MarkAction.java Wed Jan 16 11:45:02 2019 @@ -23,6 +23,7 @@ import java.util.List; import org.apache.uima.cas.Type; import org.apache.uima.cas.text.AnnotationFS; +import org.apache.uima.fit.util.CasUtil; import org.apache.uima.jcas.tcas.Annotation; import org.apache.uima.ruta.RutaStream; import org.apache.uima.ruta.expression.number.INumberExpression; @@ -39,7 +40,8 @@ public class MarkAction extends Abstract protected final List<INumberExpression> list; - public MarkAction(ITypeExpression type, INumberExpression scoreValue, List<INumberExpression> list) { + public MarkAction(ITypeExpression type, INumberExpression scoreValue, + List<INumberExpression> list) { super(type); this.score = scoreValue; this.list = list; @@ -68,35 +70,33 @@ public class MarkAction extends Abstract protected void updateHeuristicAnnotation(MatchContext context, RutaStream stream, AnnotationFS matchedAnnotation, double deltaScore) { - Type heuristicType = stream.getJCas().getCasType(RutaAnnotation.type); - RutaAnnotation heuristicAnnotation = (RutaAnnotation) stream.getCas().createAnnotation( - heuristicType, matchedAnnotation.getBegin(), matchedAnnotation.getEnd()); - Annotation newAnnotation = (Annotation) stream.getCas().createAnnotation( - type.getType(context, stream), heuristicAnnotation.getBegin(), - heuristicAnnotation.getEnd()); - heuristicAnnotation.setScore(deltaScore); - heuristicAnnotation.setAnnotation(newAnnotation); - List<AnnotationFS> annotationsInWindow = stream.getAnnotationsInWindow(heuristicAnnotation, - heuristicType); - - if (annotationsInWindow.isEmpty()) { - heuristicAnnotation.addToIndexes(); - newAnnotation.addToIndexes(); - stream.addAnnotation(newAnnotation, context.getRuleMatch()); + + Annotation targetAnnotation = null; + + Type t = this.type.getType(context, stream); + + if (t == null) { + return; + } + List<AnnotationFS> annotationsInSpan = CasUtil.selectAt(stream.getCas(), t, + matchedAnnotation.getBegin(), matchedAnnotation.getEnd()); + if (annotationsInSpan.isEmpty()) { + targetAnnotation = this.createAnnotation(matchedAnnotation, context, stream); } else { - RutaAnnotation tma = stream.getCorrectTMA(annotationsInWindow, heuristicAnnotation); - if (tma != null) { - tma.removeFromIndexes(); - double newScore = tma.getScore() + deltaScore; - tma.setScore(newScore); - tma.addToIndexes(); - } else { - heuristicAnnotation.addToIndexes(); - newAnnotation.addToIndexes(); - stream.addAnnotation(newAnnotation, context.getRuleMatch()); - } + targetAnnotation = (Annotation) annotationsInSpan.get(0); + + } + + if (targetAnnotation == null) { + return; } + RutaAnnotation rutaAnnotation = stream.getRutaAnnotationFor(targetAnnotation, true, stream); + stream.removeAnnotation(rutaAnnotation); + double newScore = rutaAnnotation.getScore() + deltaScore; + rutaAnnotation.setScore(newScore); + rutaAnnotation.addToIndexes(); + stream.addAnnotation(rutaAnnotation, context.getRuleMatch()); } public INumberExpression getScore() { Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/MarkOnceAction.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/MarkOnceAction.java?rev=1851430&r1=1851429&r2=1851430&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/MarkOnceAction.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/MarkOnceAction.java Wed Jan 16 11:45:02 2019 @@ -47,6 +47,11 @@ public class MarkOnceAction extends Mark List<AnnotationFS> matchedAnnotations = match.getMatchedAnnotations(indexList, element.getContainer()); Type targetType = type.getType(context, stream); + + if (targetType == null) { + return; + } + for (AnnotationFS matchedAnnotation : matchedAnnotations) { boolean partof = false; List<RutaBasic> basicsInWindow = stream.getBasicsInWindow(matchedAnnotation); Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/MarkTableAction.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/MarkTableAction.java?rev=1851430&r1=1851429&r2=1851430&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/MarkTableAction.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/MarkTableAction.java Wed Jan 16 11:45:02 2019 @@ -29,12 +29,13 @@ import org.apache.uima.cas.CAS; import org.apache.uima.cas.Feature; import org.apache.uima.cas.FeatureStructure; import org.apache.uima.cas.Type; +import org.apache.uima.cas.TypeSystem; import org.apache.uima.cas.text.AnnotationFS; import org.apache.uima.jcas.cas.TOP; import org.apache.uima.jcas.tcas.Annotation; import org.apache.uima.ruta.RutaStream; +import org.apache.uima.ruta.engine.RutaEngine; import org.apache.uima.ruta.expression.bool.IBooleanExpression; -import org.apache.uima.ruta.expression.bool.SimpleBooleanExpression; import org.apache.uima.ruta.expression.number.INumberExpression; import org.apache.uima.ruta.expression.resource.WordTableExpression; import org.apache.uima.ruta.expression.string.IStringExpression; @@ -64,7 +65,7 @@ public class MarkTableAction extends Abs private final INumberExpression maxIgnoreChar; - private IBooleanExpression ignoreWS = new SimpleBooleanExpression(true); + private IBooleanExpression ignoreWS; public MarkTableAction(ITypeExpression typeExpr, INumberExpression indexExpr, WordTableExpression tableExpr, Map<IStringExpression, INumberExpression> featureMap, @@ -91,11 +92,16 @@ public class MarkTableAction extends Abs RuleElement element = context.getElement(); element.getParent(); RutaTable table = tableExpr.getTable(context, stream); - if(table == null) { + if (table == null) { return; } int index = indexExpr.getIntegerValue(context, stream); Type type = typeExpr.getType(context, stream); + + if (type == null) { + return; + } + Map<String, Integer> map = new HashMap<String, Integer>(); for (IStringExpression each : featureMap.keySet()) { map.put(each.getStringValue(context, stream), @@ -109,7 +115,8 @@ public class MarkTableAction extends Abs String ignoreCharValue = ignoreChar != null ? ignoreChar.getStringValue(context, stream) : ""; int maxIgnoreCharValue = maxIgnoreChar != null ? maxIgnoreChar.getIntegerValue(context, stream) : 0; - boolean ignoreWSValue = ignoreWS != null ? ignoreWS.getBooleanValue(context, stream) : false; + boolean ignoreWSValue = ignoreWS != null ? ignoreWS.getBooleanValue(context, stream) + : getDictWSParamValue(context); RutaWordList wordList = table.getWordList(index, element.getParent()); Collection<AnnotationFS> found = wordList.find(stream, ignoreCaseValue, ignoreLengthValue, @@ -122,10 +129,10 @@ public class MarkTableAction extends Abs candidate = candidate.replaceFirst("[" + ignoreCharValue + "]", ""); } } - List<String> rowWhere = table.getRowWhere(index - 1, candidate); + List<String> rowWhere = table.getRowWhere(index - 1, candidate, false); if (rowWhere.isEmpty() && ignoreCaseValue && candidate.length() > ignoreLengthValue) { // TODO: does not cover all variants - rowWhere = table.getRowWhere(index - 1, candidate.toLowerCase()); + rowWhere = table.getRowWhere(index - 1, candidate, true); } FeatureStructure newFS = stream.getCas().createFS(type); if (newFS instanceof Annotation) { @@ -143,9 +150,16 @@ public class MarkTableAction extends Abs } } + private boolean getDictWSParamValue(MatchContext context) { + return (Boolean) context.getParent().getContext() + .getConfigParameterValue(RutaEngine.PARAM_DICT_REMOVE_WS); + } + private void fillFeatures(TOP structure, Map<String, Integer> map, AnnotationFS annotationFS, RuleElement element, List<String> row, RutaStream stream) { List<?> featuresList = structure.getType().getFeatures(); + TypeSystem typeSystem = stream.getCas().getTypeSystem(); + for (int i = 0; i < featuresList.size(); i++) { Feature targetFeature = (Feature) featuresList.get(i); String name = targetFeature.getName(); @@ -154,7 +168,7 @@ public class MarkTableAction extends Abs Type range = targetFeature.getRange(); if (entryIndex != null && row.size() >= entryIndex) { String value = row.get(entryIndex - 1); - if (range.getName().equals(CAS.TYPE_NAME_STRING)) { + if (typeSystem.subsumes(typeSystem.getType(CAS.TYPE_NAME_STRING), range)) { structure.setStringValue(targetFeature, value); } else if (range.getName().equals(CAS.TYPE_NAME_INTEGER)) { Integer integer = Integer.parseInt(value); Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/RemoveFilterTypeAction.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/RemoveFilterTypeAction.java?rev=1851430&r1=1851429&r2=1851430&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/RemoveFilterTypeAction.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/RemoveFilterTypeAction.java Wed Jan 16 11:45:02 2019 @@ -40,7 +40,10 @@ public class RemoveFilterTypeAction exte context.getElement(); List<Type> types = new ArrayList<Type>(); for (ITypeExpression each : list) { - types.add(each.getType(context, stream)); + Type type = each.getType(context, stream); + if (type != null) { + types.add(type); + } } stream.removeFilterTypes(types); } @@ -48,7 +51,7 @@ public class RemoveFilterTypeAction exte public List<ITypeExpression> getList() { return list; } - + private List<ITypeExpression> list; } Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/RemoveRetainTypeAction.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/RemoveRetainTypeAction.java?rev=1851430&r1=1851429&r2=1851430&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/RemoveRetainTypeAction.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/RemoveRetainTypeAction.java Wed Jan 16 11:45:02 2019 @@ -40,7 +40,10 @@ public class RemoveRetainTypeAction exte context.getElement(); List<Type> types = new ArrayList<Type>(); for (ITypeExpression each : list) { - types.add(each.getType(context, stream)); + Type type = each.getType(context, stream); + if (type != null) { + types.add(type); + } } stream.removeRetainTypes(types); } @@ -48,7 +51,7 @@ public class RemoveRetainTypeAction exte public List<ITypeExpression> getList() { return list; } - + private List<ITypeExpression> list; } Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/SetFeatureAction.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/SetFeatureAction.java?rev=1851430&r1=1851429&r2=1851430&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/SetFeatureAction.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/SetFeatureAction.java Wed Jan 16 11:45:02 2019 @@ -61,7 +61,7 @@ public class SetFeatureAction extends Ab stream.assignFeatureValue(annotationFS, feature, expr, context); stream.getCas().addFsToIndexes(annotationFS); } else { - throw new IllegalArgumentException("Not able to assign feature value (e.g., coveredText)."); + throw new IllegalArgumentException("Not able to assign feature value (e.g., coveredText) in script "+context.getParent().getName()); } } } Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/ShiftAction.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/ShiftAction.java?rev=1851430&r1=1851429&r2=1851430&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/ShiftAction.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/ShiftAction.java Wed Jan 16 11:45:02 2019 @@ -52,7 +52,11 @@ public class ShiftAction extends MarkAct RuleMatch match = context.getRuleMatch(); RuleElement element = context.getElement(); Type targetType = type.getType(context, stream); - + + if (targetType == null) { + return; + } + List<Integer> indexList = getIndexList(context, list, stream); List<AnnotationFS> destinationAnnotationSpans = match.getMatchedAnnotations(indexList, element.getContainer()); @@ -62,7 +66,7 @@ public class ShiftAction extends MarkAct destinationAnnotationSpans.size()); boolean expandAll = all == null ? false : all.getBooleanValue(context, stream); - + RutaBasic firstBasicOfAll = stream.getFirstBasicOfAll(); RutaBasic lastBasicOfAll = stream.getLastBasicOfAll(); int windowBegin = firstBasicOfAll == null ? 0 : firstBasicOfAll.getBegin(); @@ -72,22 +76,23 @@ public class ShiftAction extends MarkAct AnnotationFS eachDestination = destinationAnnotationSpans.get(i); Set<AnnotationFS> allAnchoredAnnotations = new TreeSet<AnnotationFS>( new AnnotationComparator()); - - if(expandAll) { - Collection<AnnotationFS> beginAnchors = stream.getBeginAnchor(eachMatched.getBegin()) - .getBeginAnchors(targetType); - Collection<AnnotationFS> endAnchors = stream.getEndAnchor(eachMatched.getEnd()) - .getEndAnchors(targetType); - allAnchoredAnnotations.addAll(beginAnchors); - allAnchoredAnnotations.addAll(endAnchors); + + if (expandAll) { + Collection<AnnotationFS> beginAnchors = stream.getBeginAnchor(eachMatched.getBegin()) + .getBeginAnchors(targetType); + Collection<AnnotationFS> endAnchors = stream.getEndAnchor(eachMatched.getEnd()) + .getEndAnchors(targetType); + allAnchoredAnnotations.addAll(beginAnchors); + allAnchoredAnnotations.addAll(endAnchors); } else { allAnchoredAnnotations.addAll(stream.getBestGuessedAnnotationsAt(eachMatched, targetType)); } - + for (AnnotationFS eachAnchored : allAnchoredAnnotations) { if (eachAnchored.getBegin() >= windowBegin && eachAnchored.getEnd() <= windowEnd) { Annotation a = (Annotation) eachAnchored; stream.changeOffsets(a, eachDestination.getBegin(), eachDestination.getEnd(), match); + addAnnotationToLabel(a, context); } } } Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/SplitAction.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/SplitAction.java?rev=1851430&r1=1851429&r2=1851430&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/SplitAction.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/SplitAction.java Wed Jan 16 11:45:02 2019 @@ -65,6 +65,11 @@ public class SplitAction extends Abstrac List<AnnotationFS> matchedAnnotationsOf = match.getMatchedAnnotationsOfElement(element); element.getParent(); Type typeToSplit = splitOnType.getType(context, stream); + + if (typeToSplit == null) { + return; + } + boolean splitOnCompleteAnnotation = complete.getBooleanValue(context, stream); boolean addToBegin = appendToBegin.getBooleanValue(context, stream); boolean addToEnd = appendToEnd.getBooleanValue(context, stream); @@ -81,11 +86,11 @@ public class SplitAction extends Abstrac if (annotation instanceof Annotation) { if (splitOnCompleteAnnotation) { - splitAnnotationOnComplete((Annotation) annotation, typeToSplit, addToBegin, addToEnd, - match, stream); + splitAnnotationOnComplete((Annotation) annotation, typeToSplit, addToBegin, addToEnd, match, + stream); } else { - splitAnnotationOnBoundary((Annotation) annotation, typeToSplit, addToBegin, addToEnd, - match, stream); + splitAnnotationOnBoundary((Annotation) annotation, typeToSplit, addToBegin, addToEnd, match, + stream); } } } Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/TransferAction.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/TransferAction.java?rev=1851430&r1=1851429&r2=1851430&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/TransferAction.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/TransferAction.java Wed Jan 16 11:45:02 2019 @@ -47,6 +47,11 @@ public class TransferAction extends Type List<List<RuleElementMatch>> list = match.getMatchInfo(element); CAS cas = stream.getCas(); Type t = type.getType(context, stream); + + if (t == null) { + return; + } + for (List<RuleElementMatch> eachList : list) { for (RuleElementMatch each : eachList) { List<AnnotationFS> matched = each.getTextsMatched(); @@ -55,6 +60,7 @@ public class TransferAction extends Type copyFeatures(annotationFS, createFS, cas); if (createFS instanceof AnnotationFS) { stream.addAnnotation((AnnotationFS) createFS, match); + addAnnotationToLabel((AnnotationFS) createFS, context); } cas.addFsToIndexes(createFS); } Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/TrieAction.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/TrieAction.java?rev=1851430&r1=1851429&r2=1851430&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/TrieAction.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/TrieAction.java Wed Jan 16 11:45:02 2019 @@ -80,7 +80,9 @@ public class TrieAction extends Abstract IRutaExpression expression = map.get(eachKey); if (expression instanceof ITypeExpression) { Type typeValue = ((ITypeExpression) expression).getType(context, stream); - typeMap.put(stringValue, typeValue); + if (typeValue != null) { + typeMap.put(stringValue, typeValue); + } } else if (expression instanceof UntypedListExpression) { List<Object> innerList = ((UntypedListExpression) expression).getList(context, stream); typeMap.put(stringValue, innerList); Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/TrimAction.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/TrimAction.java?rev=1851430&r1=1851429&r2=1851430&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/TrimAction.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/TrimAction.java Wed Jan 16 11:45:02 2019 @@ -114,7 +114,10 @@ public class TrimAction extends Abstract List<Type> result = new ArrayList<Type>(); if (types != null) { for (ITypeExpression each : types) { - result.add(each.getType(context, stream)); + Type type = each.getType(context, stream); + if (type != null) { + result.add(type); + } } } else if (typeList != null) { result = typeList.getList(context, stream); Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/UnmarkAction.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/UnmarkAction.java?rev=1851430&r1=1851429&r2=1851430&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/UnmarkAction.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/UnmarkAction.java Wed Jan 16 11:45:02 2019 @@ -62,14 +62,17 @@ public class UnmarkAction extends TypeSe if (expression != null) { List<AnnotationFS> annotationList = expression.getAnnotationList(context, stream); - if(expression.getTypeExpression() != null && expression.getFeatureExpression() == null && expression.getAnnotationExpression() == null && expression.getAnnotationListExpression()== null) { + if (expression.getTypeExpression() != null && expression.getFeatureExpression() == null + && expression.getAnnotationExpression() == null + && expression.getAnnotationListExpression() == null) { // type-based like old behavior Type t = expression.getTypeExpression().getType(context, stream); removeTypeBased(context, stream, match, element, t); } else { - for (AnnotationFS annotationFS : annotationList) { - stream.removeAnnotation(annotationFS); - } + for (AnnotationFS annotationFS : annotationList) { + stream.removeAnnotation(annotationFS); + addAnnotationToLabel(annotationFS, context); + } } } else { Type t = type.getType(context, stream); @@ -79,6 +82,11 @@ public class UnmarkAction extends TypeSe private void removeTypeBased(MatchContext context, RutaStream stream, RuleMatch match, RuleElement element, Type t) { + + if (t == null) { + return; + } + boolean allAtAnchor = false; if (allAnchor != null) { allAtAnchor = allAnchor.getBooleanValue(context, stream); @@ -91,6 +99,7 @@ public class UnmarkAction extends TypeSe boolean subsumes = stream.getCas().getTypeSystem().subsumes(t, matchedType); if (subsumes && !allAtAnchor) { stream.removeAnnotation(annotationFS, matchedType); + addAnnotationToLabel(annotationFS, context); } else { RutaBasic beginAnchor = stream.getBeginAnchor(annotationFS.getBegin()); Collection<AnnotationFS> beginAnchors = beginAnchor.getBeginAnchors(t); @@ -98,6 +107,7 @@ public class UnmarkAction extends TypeSe for (AnnotationFS each : new ArrayList<AnnotationFS>(beginAnchors)) { if (allAtAnchor || each.getEnd() == annotationFS.getEnd()) { stream.removeAnnotation(each, t); + addAnnotationToLabel(annotationFS, context); } } } Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/UnmarkAllAction.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/UnmarkAllAction.java?rev=1851430&r1=1851429&r2=1851430&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/UnmarkAllAction.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/action/UnmarkAllAction.java Wed Jan 16 11:45:02 2019 @@ -55,6 +55,10 @@ public class UnmarkAllAction extends Typ retainList = list.getList(context, stream); } Type t = type.getType(context, stream); + if (t == null) { + return; + } + TypeSystem typeSystem = stream.getCas().getTypeSystem(); List<AnnotationFS> toRemove = new LinkedList<AnnotationFS>(); List<List<RuleElementMatch>> matchInfo = match.getMatchInfo(element); Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/AfterCondition.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/AfterCondition.java?rev=1851430&r1=1851429&r2=1851430&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/AfterCondition.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/AfterCondition.java Wed Jan 16 11:45:02 2019 @@ -62,6 +62,9 @@ public class AfterCondition extends Type } private boolean check(AnnotationFS annotation, RutaStream stream, Type t) { + if (annotation == null || t == null) { + return false; + } boolean result = false; FSIterator<AnnotationFS> it = stream.getCas().getAnnotationIndex(t).iterator(annotation); if (!it.isValid()) { Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/BeforeCondition.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/BeforeCondition.java?rev=1851430&r1=1851429&r2=1851430&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/BeforeCondition.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/BeforeCondition.java Wed Jan 16 11:45:02 2019 @@ -62,6 +62,9 @@ public class BeforeCondition extends Typ } private boolean check(AnnotationFS annotation, RutaStream stream, Type t) { + if (annotation == null || t == null) { + return false; + } boolean result = false; FSIterator<AnnotationFS> it = stream.getCas().getAnnotationIndex(t).iterator(annotation); while (it.isValid()) { Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/ConditionFactory.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/ConditionFactory.java?rev=1851430&r1=1851429&r2=1851430&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/ConditionFactory.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/ConditionFactory.java Wed Jan 16 11:45:02 2019 @@ -128,7 +128,8 @@ public class ConditionFactory { } throw new RutaParseRuntimeException( - "The condition CONTAINS does not support the following arguments: " + sb.toString()); + "The condition CONTAINS does not support the following arguments in script " + + parent.getName() + ": " + sb.toString()); } public AbstractRutaCondition createConditionContains(ITypeExpression typeExpr, @@ -259,10 +260,6 @@ public class ConditionFactory { return new ParseCondition(var, localeExpr); } - public AbstractRutaCondition createConditionVariable(Token id) { - return new VariableCondition(id.getText()); - } - public AbstractRutaCondition createConditionIs(ITypeExpression type, AbstractTypeListExpression list, RutaBlock env) { if (type != null) { @@ -352,8 +349,9 @@ public class ConditionFactory { List<AbstractRutaCondition> conditions = macroConditionDefinition.getMiddle(); Set<String> vars = macroConditionDefinition.getRight(); if (definition.size() != argSize) { - throw new RutaParseRuntimeException("Arguments of macro action '" + name - + "' do not match its definition: " + definition.values()); + throw new RutaParseRuntimeException( + "Arguments of macro action '" + name + "' do not match its definition in script " + + env.getName() + ": " + definition.values()); } return new MacroCondition(name, definition, conditions, vars, args); Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/ContainsCondition.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/ContainsCondition.java?rev=1851430&r1=1851429&r2=1851430&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/ContainsCondition.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/ContainsCondition.java Wed Jan 16 11:45:02 2019 @@ -20,6 +20,7 @@ package org.apache.uima.ruta.condition; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import org.apache.uima.cas.FSIterator; @@ -89,20 +90,24 @@ public class ContainsCondition extends T int anchorCount = 0; int totalCount = 0; + boolean usePredefinedBoundaries = minIntValue == 1 && maxIntValue == Integer.MAX_VALUE ? false + : true; + if (type != null) { - if (annotation != null) { - if (minIntValue == 1 && maxIntValue == Integer.MAX_VALUE && !usePercentage) { + Type t = type.getType(context, stream); + if (annotation != null && t != null) { + if (!usePredefinedBoundaries && !usePercentage) { // shortcut for simple CONTAINS(Type) - Type t = type.getType(context, stream); boolean annotationExsits = checkExistingAnnotation(t, annotation, stream); return new EvaluatedCondition(this, annotationExsits); } else { List<RutaBasic> annotations = stream.getBasicsInWindow(annotation); for (RutaBasic each : annotations) { totalCount++; - Type t = type.getType(context, stream); if (each.beginsWith(t) || stream.getCas().getTypeSystem().subsumes(t, each.getType())) { - anchorCount += each.getBeginAnchors(t).size(); + Collection<AnnotationFS> beginAnchors = each.getBeginAnchors(t); + anchorCount = incrementAnchorsWithinStrictBoundaries(annotation, anchorCount, + beginAnchors); basicCount++; } else if (each.isPartOf(t)) { basicCount++; @@ -165,7 +170,7 @@ public class ContainsCondition extends T } anchorCount = basicCount; } - + if (usePercentage) { double percentValue = 0; if (totalCount != 0) { @@ -180,10 +185,20 @@ public class ContainsCondition extends T } } + private int incrementAnchorsWithinStrictBoundaries(AnnotationFS annotation, int anchorCount, + Collection<AnnotationFS> beginAnchors) { + for (AnnotationFS eachBegin : beginAnchors) { + if (eachBegin.getEnd() <= annotation.getEnd()) { + anchorCount++; + } + } + return anchorCount; + } + private boolean checkExistingAnnotation(Type type, AnnotationFS annotation, RutaStream stream) { int begin = annotation.getBegin(); int end = annotation.getEnd(); - + FSIterator<AnnotationFS> it = stream.getCas().getAnnotationIndex(type).iterator(); it.moveTo(annotation); if (!it.isValid()) { @@ -217,7 +232,7 @@ public class ContainsCondition extends T if (a.getEnd() > end) { continue; } - if(stream.isVisible(a)) { + if (stream.isVisible(a)) { return true; } Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/ContextCountCondition.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/ContextCountCondition.java?rev=1851430&r1=1851429&r2=1851430&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/ContextCountCondition.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/ContextCountCondition.java Wed Jan 16 11:45:02 2019 @@ -57,6 +57,11 @@ public class ContextCountCondition exten RuleElement element = context.getElement(); Type contextType = type.getType(context, stream); + + if (contextType == null) { + return new EvaluatedCondition(this, false); + } + stream.moveToFirst(); List<AnnotationFS> visibleContexts = new ArrayList<AnnotationFS>(); while (stream.isValid()) { @@ -68,27 +73,30 @@ public class ContextCountCondition exten } List<AnnotationFS> overlappingContexts = new ArrayList<AnnotationFS>(); for (AnnotationFS eachContext : visibleContexts) { - if (eachContext.getBegin() <= annotation.getBegin() + if (annotation != null && eachContext.getBegin() <= annotation.getBegin() && eachContext.getEnd() >= annotation.getEnd()) { overlappingContexts.add(eachContext); } } boolean result = false; + for (AnnotationFS eachContext : overlappingContexts) { int index = 0; int counter = 0; - List<RutaBasic> basicsInWindow = stream.getBasicsInWindow(eachContext); - for (RutaBasic eachBasic : basicsInWindow) { - Collection<AnnotationFS> beginAnchors = eachBasic.getBeginAnchors(annotation.getType()); - if (beginAnchors != null) { - for (AnnotationFS each : beginAnchors) { - counter++; - if (each.getBegin() == annotation.getBegin() - && each.getEnd() == annotation.getEnd() - && (each.getType().equals(annotation.getType()) || stream.getCas() - .getTypeSystem().subsumes(annotation.getType(), each.getType()))) { - index = counter; + + if (annotation != null) { + List<RutaBasic> basicsInWindow = stream.getBasicsInWindow(eachContext); + for (RutaBasic eachBasic : basicsInWindow) { + Collection<AnnotationFS> beginAnchors = eachBasic.getBeginAnchors(annotation.getType()); + if (beginAnchors != null) { + for (AnnotationFS each : beginAnchors) { + counter++; + if (each.getBegin() == annotation.getBegin() && each.getEnd() == annotation.getEnd() + && (each.getType().equals(annotation.getType()) || stream.getCas() + .getTypeSystem().subsumes(annotation.getType(), each.getType()))) { + index = counter; + } } } } Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/CountCondition.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/CountCondition.java?rev=1851430&r1=1851429&r2=1851430&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/CountCondition.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/CountCondition.java Wed Jan 16 11:45:02 2019 @@ -62,8 +62,8 @@ public class CountCondition extends Type this.var = var; } - public CountCondition(@SuppressWarnings("rawtypes") ListExpression list, IRutaExpression a, INumberExpression min, - INumberExpression max, String var) { + public CountCondition(@SuppressWarnings("rawtypes") ListExpression list, IRutaExpression a, + INumberExpression min, INumberExpression max, String var) { super((ITypeExpression) null); this.list = list; this.arg = a; @@ -78,8 +78,12 @@ public class CountCondition extends Type RuleElement element = context.getElement(); if (arg == null) { - List<AnnotationFS> annotationsInWindow = stream.getAnnotationsInWindow(annotation, - type.getType(context, stream)); + Type t = type.getType(context, stream); + if (t == null) { + return new EvaluatedCondition(this, false); + } + + List<AnnotationFS> annotationsInWindow = stream.getAnnotationsInWindow(annotation, t); int count = annotationsInWindow.size(); if (var != null) { element.getParent().getEnvironment().setVariableValue(var, count); Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/CurrentCountCondition.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/CurrentCountCondition.java?rev=1851430&r1=1851429&r2=1851430&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/CurrentCountCondition.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/CurrentCountCondition.java Wed Jan 16 11:45:02 2019 @@ -21,6 +21,7 @@ package org.apache.uima.ruta.condition; import java.util.Iterator; +import org.apache.uima.cas.Type; import org.apache.uima.cas.text.AnnotationFS; import org.apache.uima.ruta.RutaStream; import org.apache.uima.ruta.expression.number.INumberExpression; @@ -51,15 +52,21 @@ public class CurrentCountCondition exten AnnotationFS annotation = context.getAnnotation(); RuleElement element = context.getElement(); + Type t = type.getType(context, stream); + if (t == null) { + return new EvaluatedCondition(this, false); + } + int count = 0; - Iterator<AnnotationFS> it = stream.getCas().getAnnotationIndex(type.getType(context, stream)) - .iterator(); - while (it.hasNext()) { - AnnotationFS next = it.next(); - if (next.getBegin() < annotation.getBegin()) { - count++; - } else { - break; + if (annotation != null) { + Iterator<AnnotationFS> it = stream.getCas().getAnnotationIndex(t).iterator(); + while (it.hasNext()) { + AnnotationFS next = it.next(); + if (next.getBegin() < annotation.getBegin()) { + count++; + } else { + break; + } } } if (var != null) { Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/EndsWithCondition.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/EndsWithCondition.java?rev=1851430&r1=1851429&r2=1851430&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/EndsWithCondition.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/EndsWithCondition.java Wed Jan 16 11:45:02 2019 @@ -62,8 +62,11 @@ public class EndsWithCondition extends T } } - private boolean check(RutaStream stream, AnnotationFS matched, Type givenType) { - RutaBasic endAnchor = stream.getEndAnchor(matched.getEnd()); + private boolean check(RutaStream stream, AnnotationFS annotation, Type givenType) { + if (annotation == null || givenType == null) { + return false; + } + RutaBasic endAnchor = stream.getEndAnchor(annotation.getEnd()); if (endAnchor != null) { return endAnchor.endsWith(givenType); } else { Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/FeatureCondition.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/FeatureCondition.java?rev=1851430&r1=1851429&r2=1851430&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/FeatureCondition.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/FeatureCondition.java Wed Jan 16 11:45:02 2019 @@ -44,7 +44,9 @@ public class FeatureCondition extends Ab @Override public EvaluatedCondition eval(MatchContext context, RutaStream stream, InferenceCrowd crowd) { AnnotationFS annotation = context.getAnnotation(); - + if (annotation == null) { + return new EvaluatedCondition(this, false); + } String typeWithFeature = annotation.getType().getName() + "." + featureStringExpression.getStringValue(context, stream); MatchReference mf = new MatchReference(typeWithFeature); Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/ImplicitCondition.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/ImplicitCondition.java?rev=1851430&r1=1851429&r2=1851430&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/ImplicitCondition.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/ImplicitCondition.java Wed Jan 16 11:45:02 2019 @@ -21,6 +21,7 @@ package org.apache.uima.ruta.condition; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.List; import org.apache.commons.collections.CollectionUtils; @@ -57,22 +58,24 @@ public class ImplicitCondition extends A return new EvaluatedCondition(this, be.getBooleanValue(context, stream)); } else if (expr instanceof FeatureMatchExpression) { FeatureMatchExpression fme = (FeatureMatchExpression) expr; - List<AnnotationFS> annotations =new ArrayList<>(); + List<AnnotationFS> annotations = new ArrayList<>(); MatchReference matchReference = fme.getMatchReference(); // TODO refactor ITypeExpression typeExpr = matchReference.getTypeExpression(context, stream); - IAnnotationListExpression annotationListExpr = matchReference.getAnnotationListExpression(context, stream); - IAnnotationExpression annotationExpr = matchReference.getAnnotationExpression(context, stream); + IAnnotationListExpression annotationListExpr = matchReference + .getAnnotationListExpression(context, stream); + IAnnotationExpression annotationExpr = matchReference.getAnnotationExpression(context, + stream); if (typeExpr != null) { Type type = typeExpr.getType(context, stream); annotations = getAnnotationsToCheck(annotation, type, fme, stream); - } else if(annotationListExpr!=null) { + } else if (annotationListExpr != null) { annotations.addAll(annotationListExpr.getAnnotationList(context, stream)); - } else if(annotationExpr!=null) { + } else if (annotationExpr != null) { annotations.add(annotationExpr.getAnnotation(context, stream)); } - Collection<? extends FeatureStructure> featureAnnotations = fme.getFeatureStructures(annotations, true, - context, stream); + Collection<? extends FeatureStructure> featureAnnotations = fme + .getFeatureStructures(annotations, true, context, stream); return new EvaluatedCondition(this, !featureAnnotations.isEmpty()); } return new EvaluatedCondition(this, false); @@ -80,6 +83,11 @@ public class ImplicitCondition extends A private List<AnnotationFS> getAnnotationsToCheck(AnnotationFS annotation, Type type, FeatureMatchExpression fme, RutaStream stream) { + + if (annotation == null || type == null) { + return Collections.emptyList(); + } + List<AnnotationFS> result = new ArrayList<AnnotationFS>(); TypeSystem typeSystem = stream.getCas().getTypeSystem(); if (typeSystem.subsumes(type, annotation.getType())) { Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/InListCondition.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/InListCondition.java?rev=1851430&r1=1851429&r2=1851430&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/InListCondition.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/InListCondition.java Wed Jan 16 11:45:02 2019 @@ -54,6 +54,11 @@ public class InListCondition extends Ter @Override public EvaluatedCondition eval(MatchContext context, RutaStream stream, InferenceCrowd crowd) { AnnotationFS annotation = context.getAnnotation(); + + if (annotation == null) { + return new EvaluatedCondition(this, false); + } + String text = annotation.getCoveredText(); if (arg != null) { text = arg.getStringValue(context, stream); @@ -64,7 +69,7 @@ public class InListCondition extends Ter if (stringList == null) { RutaWordList wordList = listExpr.getList(context, stream); boolean contains = false; - if(wordList != null) { + if (wordList != null) { contains = wordList.contains(text, false, 0, null, 0, true); } return new EvaluatedCondition(this, contains); Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/IsCondition.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/IsCondition.java?rev=1851430&r1=1851429&r2=1851430&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/IsCondition.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/IsCondition.java Wed Jan 16 11:45:02 2019 @@ -45,16 +45,23 @@ public class IsCondition extends TypeSen @Override public EvaluatedCondition eval(MatchContext context, RutaStream stream, InferenceCrowd crowd) { AnnotationFS annotation = context.getAnnotation(); + + if (annotation == null) { + return new EvaluatedCondition(this, false); + } + RutaBasic beginAnchor = stream.getBeginAnchor(annotation.getBegin()); if (!isWorkingOnList()) { - Collection<AnnotationFS> beginAnchors = beginAnchor.getBeginAnchors(type.getType(context, - stream)); + Type t = type.getType(context, stream); boolean result = false; - if (beginAnchors != null) { - for (AnnotationFS annotationFS : beginAnchors) { - result |= check(annotation, annotationFS); - if (result == true) { - break; + if (t != null) { + Collection<AnnotationFS> beginAnchors = beginAnchor.getBeginAnchors(t); + if (beginAnchors != null) { + for (AnnotationFS annotationFS : beginAnchors) { + result |= check(annotation, annotationFS); + if (result == true) { + break; + } } } } Modified: uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/LastCondition.java URL: http://svn.apache.org/viewvc/uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/LastCondition.java?rev=1851430&r1=1851429&r2=1851430&view=diff ============================================================================== --- uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/LastCondition.java (original) +++ uima/uv3/ruta-v3/trunk/ruta-core/src/main/java/org/apache/uima/ruta/condition/LastCondition.java Wed Jan 16 11:45:02 2019 @@ -37,8 +37,18 @@ public class LastCondition extends TypeS @Override public EvaluatedCondition eval(MatchContext context, RutaStream stream, InferenceCrowd crowd) { AnnotationFS annotation = context.getAnnotation(); + + if (annotation == null) { + return new EvaluatedCondition(this, false); + } + RutaBasic endAnchor = stream.getEndAnchor(annotation.getEnd()); Type t = type.getType(context, stream); + + if (t == null) { + return new EvaluatedCondition(this, false); + } + boolean result = endAnchor.beginsWith(t) && endAnchor.endsWith(t); return new EvaluatedCondition(this, result); }