@Test public void testConditionMacro() throws Exception { String script = "CONDITION isSmall() = REGEXP(\".\");\n"; script += "BLOCK(num) NUM{} {\n"; script += "Document{isSmall()-> T1};"; script += "}"; CAS cas = RutaTestUtils.getCAS("1 22 333"); Ruta.apply(cas, script); RutaTestUtils.assertAnnotationsEquals(cas, 1, 1, "1"); }
@Override public ScriptApply apply(RutaStream stream, InferenceCrowd crowd) { BlockApply result = new BlockApply(this); getEnvironment().ensureMaterializedInitialValues(new MatchContext(this), stream); crowd.beginVisit(this, result); RuleApply apply = rule.apply(stream, crowd, true); for (AbstractRuleMatch<? extends AbstractRule> eachMatch : apply.getList()) { if (eachMatch.matched()) { List<AnnotationFS> matchedAnnotations = ((RuleMatch) eachMatch).getMatchedAnnotations(null, null); if (matchedAnnotations == null || matchedAnnotations.isEmpty()) { continue; } AnnotationFS each = matchedAnnotations.get(0); if (each == null) { continue; } RutaMatcher matcher = ((RutaRuleElement) rule.getRuleElements().get(0)).getMatcher(); if (matcher == null) { continue; } Type type = matcher.getType(getParent() == null ? this : getParent(), stream); RutaStream window = stream.getWindowStream(each, type); for (RutaStatement element : getElements()) { if (element != null) { element.apply(window, crowd); } } } } crowd.endVisit(this, result); return result; }
RutaScriptBlock extends RutaBlock { @Override public ScriptApply apply(RutaStream stream, InferenceCrowd crowd) { BlockApply result = new BlockApply(this); getEnvironment().ensureMaterializedInitialValues(new MatchContext(this), stream); crowd.beginVisit(this, result); RuleApply apply = rule.apply(stream, crowd, true); for (AbstractRuleMatch<? extends AbstractRule> eachMatch : apply.getList()) { if (eachMatch.matched()) { List<AnnotationFS> matchedAnnotations = ((RuleMatch) eachMatch).getMatchedAnnotations(null, null); if (matchedAnnotations == null || matchedAnnotations.isEmpty()) { continue; } AnnotationFS each = matchedAnnotations.get(0); if (each == null) { continue; } RutaMatcher matcher = ((RutaRuleElement) rule.getRuleElements().get(0)).getMatcher(); if (matcher == null) { continue; } Type type = matcher.getType(getParent() == null ? this : getParent(), stream); RutaStream window = stream.getWindowStream(each, type); for (RutaStatement element : getElements()) { if (element != null) { element.apply(window, crowd); } } } } crowd.endVisit(this, result); return result; } }
RutaScriptBlock extends RutaBlock { @Override public ScriptApply apply(RutaStream stream, InferenceCrowd crowd) { BlockApply result = new BlockApply(this); getEnvironment().ensureMaterializedInitialValues(new MatchContext(this), stream); crowd.beginVisit(this, result); RuleApply apply = rule.apply(stream, crowd, true); for (AbstractRuleMatch<? extends AbstractRule> eachMatch : apply.getList()) { if (eachMatch.matched()) { List<AnnotationFS> matchedAnnotations = ((RuleMatch) eachMatch).getMatchedAnnotations(null, null); if (matchedAnnotations == null || matchedAnnotations.isEmpty()) { continue; } AnnotationFS each = matchedAnnotations.get(0); if (each == null) { continue; } RutaMatcher matcher = ((RutaRuleElement) rule.getRuleElements().get(0)).getMatcher(); if (matcher == null) { continue; } Type type = matcher.getType(getParent() == null ? this : getParent(), stream); RutaStream window = stream.getWindowStream(each, type); for (RutaStatement element : getElements()) { if (element != null) { element.apply(window, crowd); } } } } crowd.endVisit(this, result); return result; } RutaScriptBlock(String id, RutaRule rule, List<RutaStatement> elements, RutaBlock parent,
          String defaultNamespace); }
RutaScriptBlock extends RutaBlock { @Override public ScriptApply apply(RutaStream stream, InferenceCrowd crowd) { BlockApply result = new BlockApply(this); getEnvironment().ensureMaterializedInitialValues(new MatchContext(this), stream); crowd.beginVisit(this, result); RuleApply apply = rule.apply(stream, crowd, true); for (AbstractRuleMatch<? extends AbstractRule> eachMatch : apply.getList()) { if (eachMatch.matched()) { List<AnnotationFS> matchedAnnotations = ((RuleMatch) eachMatch).getMatchedAnnotations(null, null); if (matchedAnnotations == null || matchedAnnotations.isEmpty()) { continue; } AnnotationFS each = matchedAnnotations.get(0); if (each == null) { continue; } RutaMatcher matcher = ((RutaRuleElement) rule.getRuleElements().get(0)).getMatcher(); if (matcher == null) { continue; } Type type = matcher.getType(getParent() == null ? this : getParent(), stream); RutaStream window = stream.getWindowStream(each, type); for (RutaStatement element : getElements()) { if (element != null) { element.apply(window, crowd); } } } } crowd.endVisit(this, result); return result; } RutaScriptBlock(String id, RutaRule rule, List<RutaStatement> elements, RutaBlock parent,
          String defaultNamespace); @Override ScriptApply apply(RutaStream stream, InferenceCrowd crowd); @Override String toString(); }
RutaScriptBlock extends RutaBlock { @Override public ScriptApply apply(RutaStream stream, InferenceCrowd crowd) { BlockApply result = new BlockApply(this); getEnvironment().ensureMaterializedInitialValues(new MatchContext(this), stream); crowd.beginVisit(this, result); RuleApply apply = rule.apply(stream, crowd, true); for (AbstractRuleMatch<? extends AbstractRule> eachMatch : apply.getList()) { if (eachMatch.matched()) { List<AnnotationFS> matchedAnnotations = ((RuleMatch) eachMatch).getMatchedAnnotations(null, null); if (matchedAnnotations == null || matchedAnnotations.isEmpty()) { continue; } AnnotationFS each = matchedAnnotations.get(0); if (each == null) { continue; } RutaMatcher matcher = ((RutaRuleElement) rule.getRuleElements().get(0)).getMatcher(); if (matcher == null) { continue; } Type type = matcher.getType(getParent() == null ? this : getParent(), stream); RutaStream window = stream.getWindowStream(each, type); for (RutaStatement element : getElements()) { if (element != null) { element.apply(window, crowd); } } } } crowd.endVisit(this, result); return result; } RutaScriptBlock(String id, RutaRule rule, List<RutaStatement> elements, RutaBlock parent,
          String defaultNamespace); @Override ScriptApply apply(RutaStream stream, InferenceCrowd crowd); @Override String toString();  }