org.apache.flink.cep.pattern.conditions.RichNotCondition Java Examples
The following examples show how to use
org.apache.flink.cep.pattern.conditions.RichNotCondition.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NFACompiler.java From flink with Apache License 2.0 | 5 votes |
/** * This method extends the given condition with stop(until) condition if necessary. * The until condition needs to be applied only if both of the given conditions are not null. * * @param condition the condition to extend * @param untilCondition the until condition to join with the given condition * @param isTakeCondition whether the {@code condition} is for {@code TAKE} edge * @return condition with AND applied or the original condition */ private IterativeCondition<T> extendWithUntilCondition( IterativeCondition<T> condition, IterativeCondition<T> untilCondition, boolean isTakeCondition) { if (untilCondition != null && condition != null) { return new RichAndCondition<>(new RichNotCondition<>(untilCondition), condition); } else if (untilCondition != null && isTakeCondition) { return new RichNotCondition<>(untilCondition); } return condition; }
Example #2
Source File: NFACompiler.java From flink with Apache License 2.0 | 5 votes |
private void updateWithGreedyCondition( State<T> state, IterativeCondition<T> takeCondition) { for (StateTransition<T> stateTransition : state.getStateTransitions()) { stateTransition.setCondition( new RichAndCondition<>(stateTransition.getCondition(), new RichNotCondition<>(takeCondition))); } }
Example #3
Source File: NFACompiler.java From flink with Apache License 2.0 | 5 votes |
/** * @return The {@link IterativeCondition condition} for the {@code IGNORE} edge * that corresponds to the specified {@link Pattern} and extended with * stop(until) condition if necessary. For more on strategy see {@link Quantifier} */ @SuppressWarnings("unchecked") private IterativeCondition<T> getIgnoreCondition(Pattern<T, ?> pattern) { Quantifier.ConsumingStrategy consumingStrategy = pattern.getQuantifier().getConsumingStrategy(); if (headOfGroup(pattern)) { // for the head pattern of a group pattern, we should consider the inner consume strategy // of the group pattern if the group pattern is not the head of the TIMES/LOOPING quantifier; // otherwise, we should consider the consume strategy of the group pattern if (isCurrentGroupPatternFirstOfLoop()) { consumingStrategy = currentGroupPattern.getQuantifier().getConsumingStrategy(); } else { consumingStrategy = currentGroupPattern.getQuantifier().getInnerConsumingStrategy(); } } IterativeCondition<T> ignoreCondition = null; switch (consumingStrategy) { case STRICT: ignoreCondition = null; break; case SKIP_TILL_NEXT: ignoreCondition = new RichNotCondition<>((IterativeCondition<T>) pattern.getCondition()); break; case SKIP_TILL_ANY: ignoreCondition = BooleanConditions.trueFunction(); break; } if (currentGroupPattern != null && currentGroupPattern.getUntilCondition() != null) { ignoreCondition = extendWithUntilCondition( ignoreCondition, (IterativeCondition<T>) currentGroupPattern.getUntilCondition(), false); } return ignoreCondition; }
Example #4
Source File: NFACompiler.java From flink with Apache License 2.0 | 5 votes |
/** * @return The {@link IterativeCondition condition} for the {@code IGNORE} edge * that corresponds to the specified {@link Pattern} and extended with stop(until) condition * if necessary. It is applicable only for inner states of a complex state like looping or times. */ @SuppressWarnings("unchecked") private IterativeCondition<T> getInnerIgnoreCondition(Pattern<T, ?> pattern) { Quantifier.ConsumingStrategy consumingStrategy = pattern.getQuantifier().getInnerConsumingStrategy(); if (headOfGroup(pattern)) { // for the head pattern of a group pattern, we should consider the // inner consume strategy of the group pattern consumingStrategy = currentGroupPattern.getQuantifier().getInnerConsumingStrategy(); } IterativeCondition<T> innerIgnoreCondition = null; switch (consumingStrategy) { case STRICT: innerIgnoreCondition = null; break; case SKIP_TILL_NEXT: innerIgnoreCondition = new RichNotCondition<>((IterativeCondition<T>) pattern.getCondition()); break; case SKIP_TILL_ANY: innerIgnoreCondition = BooleanConditions.trueFunction(); break; } if (currentGroupPattern != null && currentGroupPattern.getUntilCondition() != null) { innerIgnoreCondition = extendWithUntilCondition( innerIgnoreCondition, (IterativeCondition<T>) currentGroupPattern.getUntilCondition(), false); } return innerIgnoreCondition; }
Example #5
Source File: NFACompiler.java From flink with Apache License 2.0 | 5 votes |
/** * This method extends the given condition with stop(until) condition if necessary. * The until condition needs to be applied only if both of the given conditions are not null. * * @param condition the condition to extend * @param untilCondition the until condition to join with the given condition * @param isTakeCondition whether the {@code condition} is for {@code TAKE} edge * @return condition with AND applied or the original condition */ private IterativeCondition<T> extendWithUntilCondition( IterativeCondition<T> condition, IterativeCondition<T> untilCondition, boolean isTakeCondition) { if (untilCondition != null && condition != null) { return new RichAndCondition<>(new RichNotCondition<>(untilCondition), condition); } else if (untilCondition != null && isTakeCondition) { return new RichNotCondition<>(untilCondition); } return condition; }
Example #6
Source File: NFACompiler.java From flink with Apache License 2.0 | 5 votes |
/** * Creates all the states between Start and Final state. * * @param sinkState the state that last state should point to (always the Final state) * @return the next state after Start in the resulting graph */ private State<T> createMiddleStates(final State<T> sinkState) { State<T> lastSink = sinkState; while (currentPattern.getPrevious() != null) { if (currentPattern.getQuantifier().getConsumingStrategy() == Quantifier.ConsumingStrategy.NOT_FOLLOW) { //skip notFollow patterns, they are converted into edge conditions } else if (currentPattern.getQuantifier().getConsumingStrategy() == Quantifier.ConsumingStrategy.NOT_NEXT) { final State<T> notNext = createState(currentPattern.getName(), State.StateType.Normal); final IterativeCondition<T> notCondition = getTakeCondition(currentPattern); final State<T> stopState = createStopState(notCondition, currentPattern.getName()); if (lastSink.isFinal()) { //so that the proceed to final is not fired notNext.addIgnore(lastSink, new RichNotCondition<>(notCondition)); } else { notNext.addProceed(lastSink, new RichNotCondition<>(notCondition)); } notNext.addProceed(stopState, notCondition); lastSink = notNext; } else { lastSink = convertPattern(lastSink); } // we traverse the pattern graph backwards followingPattern = currentPattern; currentPattern = currentPattern.getPrevious(); final Time currentWindowTime = currentPattern.getWindowTime(); if (currentWindowTime != null && currentWindowTime.toMilliseconds() < windowTime.orElse(Long.MAX_VALUE)) { // the window time is the global minimum of all window times of each state windowTime = Optional.of(currentWindowTime.toMilliseconds()); } } return lastSink; }
Example #7
Source File: NFACompiler.java From flink with Apache License 2.0 | 5 votes |
private void updateWithGreedyCondition( State<T> state, IterativeCondition<T> takeCondition) { for (StateTransition<T> stateTransition : state.getStateTransitions()) { stateTransition.setCondition( new RichAndCondition<>(stateTransition.getCondition(), new RichNotCondition<>(takeCondition))); } }
Example #8
Source File: NFACompiler.java From flink with Apache License 2.0 | 5 votes |
/** * @return The {@link IterativeCondition condition} for the {@code IGNORE} edge * that corresponds to the specified {@link Pattern} and extended with * stop(until) condition if necessary. For more on strategy see {@link Quantifier} */ @SuppressWarnings("unchecked") private IterativeCondition<T> getIgnoreCondition(Pattern<T, ?> pattern) { Quantifier.ConsumingStrategy consumingStrategy = pattern.getQuantifier().getConsumingStrategy(); if (headOfGroup(pattern)) { // for the head pattern of a group pattern, we should consider the inner consume strategy // of the group pattern if the group pattern is not the head of the TIMES/LOOPING quantifier; // otherwise, we should consider the consume strategy of the group pattern if (isCurrentGroupPatternFirstOfLoop()) { consumingStrategy = currentGroupPattern.getQuantifier().getConsumingStrategy(); } else { consumingStrategy = currentGroupPattern.getQuantifier().getInnerConsumingStrategy(); } } IterativeCondition<T> ignoreCondition = null; switch (consumingStrategy) { case STRICT: ignoreCondition = null; break; case SKIP_TILL_NEXT: ignoreCondition = new RichNotCondition<>((IterativeCondition<T>) pattern.getCondition()); break; case SKIP_TILL_ANY: ignoreCondition = BooleanConditions.trueFunction(); break; } if (currentGroupPattern != null && currentGroupPattern.getUntilCondition() != null) { ignoreCondition = extendWithUntilCondition( ignoreCondition, (IterativeCondition<T>) currentGroupPattern.getUntilCondition(), false); } return ignoreCondition; }
Example #9
Source File: NFACompiler.java From flink with Apache License 2.0 | 5 votes |
/** * @return The {@link IterativeCondition condition} for the {@code IGNORE} edge * that corresponds to the specified {@link Pattern} and extended with stop(until) condition * if necessary. It is applicable only for inner states of a complex state like looping or times. */ @SuppressWarnings("unchecked") private IterativeCondition<T> getInnerIgnoreCondition(Pattern<T, ?> pattern) { Quantifier.ConsumingStrategy consumingStrategy = pattern.getQuantifier().getInnerConsumingStrategy(); if (headOfGroup(pattern)) { // for the head pattern of a group pattern, we should consider the // inner consume strategy of the group pattern consumingStrategy = currentGroupPattern.getQuantifier().getInnerConsumingStrategy(); } IterativeCondition<T> innerIgnoreCondition = null; switch (consumingStrategy) { case STRICT: innerIgnoreCondition = null; break; case SKIP_TILL_NEXT: innerIgnoreCondition = new RichNotCondition<>((IterativeCondition<T>) pattern.getCondition()); break; case SKIP_TILL_ANY: innerIgnoreCondition = BooleanConditions.trueFunction(); break; } if (currentGroupPattern != null && currentGroupPattern.getUntilCondition() != null) { innerIgnoreCondition = extendWithUntilCondition( innerIgnoreCondition, (IterativeCondition<T>) currentGroupPattern.getUntilCondition(), false); } return innerIgnoreCondition; }
Example #10
Source File: NFACompiler.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
/** * Creates all the states between Start and Final state. * * @param sinkState the state that last state should point to (always the Final state) * @return the next state after Start in the resulting graph */ private State<T> createMiddleStates(final State<T> sinkState) { State<T> lastSink = sinkState; while (currentPattern.getPrevious() != null) { if (currentPattern.getQuantifier().getConsumingStrategy() == Quantifier.ConsumingStrategy.NOT_FOLLOW) { //skip notFollow patterns, they are converted into edge conditions } else if (currentPattern.getQuantifier().getConsumingStrategy() == Quantifier.ConsumingStrategy.NOT_NEXT) { final State<T> notNext = createState(currentPattern.getName(), State.StateType.Normal); final IterativeCondition<T> notCondition = getTakeCondition(currentPattern); final State<T> stopState = createStopState(notCondition, currentPattern.getName()); if (lastSink.isFinal()) { //so that the proceed to final is not fired notNext.addIgnore(lastSink, new RichNotCondition<>(notCondition)); } else { notNext.addProceed(lastSink, new RichNotCondition<>(notCondition)); } notNext.addProceed(stopState, notCondition); lastSink = notNext; } else { lastSink = convertPattern(lastSink); } // we traverse the pattern graph backwards followingPattern = currentPattern; currentPattern = currentPattern.getPrevious(); final Time currentWindowTime = currentPattern.getWindowTime(); if (currentWindowTime != null && currentWindowTime.toMilliseconds() < windowTime) { // the window time is the global minimum of all window times of each state windowTime = currentWindowTime.toMilliseconds(); } } return lastSink; }
Example #11
Source File: NFACompiler.java From flink with Apache License 2.0 | 5 votes |
/** * Creates all the states between Start and Final state. * * @param sinkState the state that last state should point to (always the Final state) * @return the next state after Start in the resulting graph */ private State<T> createMiddleStates(final State<T> sinkState) { State<T> lastSink = sinkState; while (currentPattern.getPrevious() != null) { if (currentPattern.getQuantifier().getConsumingStrategy() == Quantifier.ConsumingStrategy.NOT_FOLLOW) { //skip notFollow patterns, they are converted into edge conditions } else if (currentPattern.getQuantifier().getConsumingStrategy() == Quantifier.ConsumingStrategy.NOT_NEXT) { final State<T> notNext = createState(currentPattern.getName(), State.StateType.Normal); final IterativeCondition<T> notCondition = getTakeCondition(currentPattern); final State<T> stopState = createStopState(notCondition, currentPattern.getName()); if (lastSink.isFinal()) { //so that the proceed to final is not fired notNext.addIgnore(lastSink, new RichNotCondition<>(notCondition)); } else { notNext.addProceed(lastSink, new RichNotCondition<>(notCondition)); } notNext.addProceed(stopState, notCondition); lastSink = notNext; } else { lastSink = convertPattern(lastSink); } // we traverse the pattern graph backwards followingPattern = currentPattern; currentPattern = currentPattern.getPrevious(); final Time currentWindowTime = currentPattern.getWindowTime(); if (currentWindowTime != null && currentWindowTime.toMilliseconds() < windowTime) { // the window time is the global minimum of all window times of each state windowTime = currentWindowTime.toMilliseconds(); } } return lastSink; }
Example #12
Source File: NFACompiler.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
private void updateWithGreedyCondition( State<T> state, IterativeCondition<T> takeCondition) { for (StateTransition<T> stateTransition : state.getStateTransitions()) { stateTransition.setCondition( new RichAndCondition<>(stateTransition.getCondition(), new RichNotCondition<>(takeCondition))); } }
Example #13
Source File: NFACompiler.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
/** * @return The {@link IterativeCondition condition} for the {@code IGNORE} edge * that corresponds to the specified {@link Pattern} and extended with * stop(until) condition if necessary. For more on strategy see {@link Quantifier} */ @SuppressWarnings("unchecked") private IterativeCondition<T> getIgnoreCondition(Pattern<T, ?> pattern) { Quantifier.ConsumingStrategy consumingStrategy = pattern.getQuantifier().getConsumingStrategy(); if (headOfGroup(pattern)) { // for the head pattern of a group pattern, we should consider the inner consume strategy // of the group pattern if the group pattern is not the head of the TIMES/LOOPING quantifier; // otherwise, we should consider the consume strategy of the group pattern if (isCurrentGroupPatternFirstOfLoop()) { consumingStrategy = currentGroupPattern.getQuantifier().getConsumingStrategy(); } else { consumingStrategy = currentGroupPattern.getQuantifier().getInnerConsumingStrategy(); } } IterativeCondition<T> ignoreCondition = null; switch (consumingStrategy) { case STRICT: ignoreCondition = null; break; case SKIP_TILL_NEXT: ignoreCondition = new RichNotCondition<>((IterativeCondition<T>) pattern.getCondition()); break; case SKIP_TILL_ANY: ignoreCondition = BooleanConditions.trueFunction(); break; } if (currentGroupPattern != null && currentGroupPattern.getUntilCondition() != null) { ignoreCondition = extendWithUntilCondition( ignoreCondition, (IterativeCondition<T>) currentGroupPattern.getUntilCondition(), false); } return ignoreCondition; }
Example #14
Source File: NFACompiler.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
/** * @return The {@link IterativeCondition condition} for the {@code IGNORE} edge * that corresponds to the specified {@link Pattern} and extended with stop(until) condition * if necessary. It is applicable only for inner states of a complex state like looping or times. */ @SuppressWarnings("unchecked") private IterativeCondition<T> getInnerIgnoreCondition(Pattern<T, ?> pattern) { Quantifier.ConsumingStrategy consumingStrategy = pattern.getQuantifier().getInnerConsumingStrategy(); if (headOfGroup(pattern)) { // for the head pattern of a group pattern, we should consider the // inner consume strategy of the group pattern consumingStrategy = currentGroupPattern.getQuantifier().getInnerConsumingStrategy(); } IterativeCondition<T> innerIgnoreCondition = null; switch (consumingStrategy) { case STRICT: innerIgnoreCondition = null; break; case SKIP_TILL_NEXT: innerIgnoreCondition = new RichNotCondition<>((IterativeCondition<T>) pattern.getCondition()); break; case SKIP_TILL_ANY: innerIgnoreCondition = BooleanConditions.trueFunction(); break; } if (currentGroupPattern != null && currentGroupPattern.getUntilCondition() != null) { innerIgnoreCondition = extendWithUntilCondition( innerIgnoreCondition, (IterativeCondition<T>) currentGroupPattern.getUntilCondition(), false); } return innerIgnoreCondition; }
Example #15
Source File: NFACompiler.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
/** * This method extends the given condition with stop(until) condition if necessary. * The until condition needs to be applied only if both of the given conditions are not null. * * @param condition the condition to extend * @param untilCondition the until condition to join with the given condition * @param isTakeCondition whether the {@code condition} is for {@code TAKE} edge * @return condition with AND applied or the original condition */ private IterativeCondition<T> extendWithUntilCondition( IterativeCondition<T> condition, IterativeCondition<T> untilCondition, boolean isTakeCondition) { if (untilCondition != null && condition != null) { return new RichAndCondition<>(new RichNotCondition<>(untilCondition), condition); } else if (untilCondition != null && isTakeCondition) { return new RichNotCondition<>(untilCondition); } return condition; }
Example #16
Source File: NFACompiler.java From flink with Apache License 2.0 | 4 votes |
/** * Creates the given state as a looping one. Looping state is one with TAKE edge to itself and * PROCEED edge to the sinkState. It also consists of a similar state without the PROCEED edge, so that * for each PROCEED transition branches in computation state graph can be created only once. * * @param sinkState the state that the converted state should point to * @return the first state of the created complex state */ @SuppressWarnings("unchecked") private State<T> createLooping(final State<T> sinkState) { if (currentPattern instanceof GroupPattern) { return createLoopingGroupPatternState((GroupPattern) currentPattern, sinkState); } final IterativeCondition<T> untilCondition = (IterativeCondition<T>) currentPattern.getUntilCondition(); final IterativeCondition<T> ignoreCondition = extendWithUntilCondition( getInnerIgnoreCondition(currentPattern), untilCondition, false); final IterativeCondition<T> takeCondition = extendWithUntilCondition( getTakeCondition(currentPattern), untilCondition, true); IterativeCondition<T> proceedCondition = getTrueFunction(); final State<T> loopingState = createState(currentPattern.getName(), State.StateType.Normal); if (currentPattern.getQuantifier().hasProperty(Quantifier.QuantifierProperty.GREEDY)) { if (untilCondition != null) { State<T> sinkStateCopy = copy(sinkState); loopingState.addProceed(sinkStateCopy, new RichAndCondition<>(proceedCondition, untilCondition)); originalStateMap.put(sinkState.getName(), sinkStateCopy); } loopingState.addProceed(sinkState, untilCondition != null ? new RichAndCondition<>(proceedCondition, new RichNotCondition<>(untilCondition)) : proceedCondition); updateWithGreedyCondition(sinkState, getTakeCondition(currentPattern)); } else { loopingState.addProceed(sinkState, proceedCondition); } loopingState.addTake(takeCondition); addStopStateToLooping(loopingState); if (ignoreCondition != null) { final State<T> ignoreState = createState(currentPattern.getName(), State.StateType.Normal); ignoreState.addTake(loopingState, takeCondition); ignoreState.addIgnore(ignoreCondition); loopingState.addIgnore(ignoreState, ignoreCondition); addStopStateToLooping(ignoreState); } return loopingState; }
Example #17
Source File: NFACompiler.java From flink with Apache License 2.0 | 4 votes |
/** * Creates a simple single state. For an OPTIONAL state it also consists * of a similar state without the PROCEED edge, so that for each PROCEED transition branches * in computation state graph can be created only once. * * @param ignoreCondition condition that should be applied to IGNORE transition * @param sinkState state that the state being converted should point to * @param proceedState state that the state being converted should proceed to * @param isOptional whether the state being converted is optional * @return the created state */ @SuppressWarnings("unchecked") private State<T> createSingletonState(final State<T> sinkState, final State<T> proceedState, final IterativeCondition<T> takeCondition, final IterativeCondition<T> ignoreCondition, final boolean isOptional) { if (currentPattern instanceof GroupPattern) { return createGroupPatternState((GroupPattern) currentPattern, sinkState, proceedState, isOptional); } final State<T> singletonState = createState(currentPattern.getName(), State.StateType.Normal); // if event is accepted then all notPatterns previous to the optional states are no longer valid final State<T> sink = copyWithoutTransitiveNots(sinkState); singletonState.addTake(sink, takeCondition); // if no element accepted the previous nots are still valid. final IterativeCondition<T> proceedCondition = getTrueFunction(); // for the first state of a group pattern, its PROCEED edge should point to the following state of // that group pattern and the edge will be added at the end of creating the NFA for that group pattern if (isOptional && !headOfGroup(currentPattern)) { if (currentPattern.getQuantifier().hasProperty(Quantifier.QuantifierProperty.GREEDY)) { final IterativeCondition<T> untilCondition = (IterativeCondition<T>) currentPattern.getUntilCondition(); if (untilCondition != null) { singletonState.addProceed( originalStateMap.get(proceedState.getName()), new RichAndCondition<>(proceedCondition, untilCondition)); } singletonState.addProceed(proceedState, untilCondition != null ? new RichAndCondition<>(proceedCondition, new RichNotCondition<>(untilCondition)) : proceedCondition); } else { singletonState.addProceed(proceedState, proceedCondition); } } if (ignoreCondition != null) { final State<T> ignoreState; if (isOptional) { ignoreState = createState(currentPattern.getName(), State.StateType.Normal); ignoreState.addTake(sink, takeCondition); ignoreState.addIgnore(ignoreCondition); addStopStates(ignoreState); } else { ignoreState = singletonState; } singletonState.addIgnore(ignoreState, ignoreCondition); } return singletonState; }
Example #18
Source File: NFACompiler.java From flink with Apache License 2.0 | 4 votes |
/** * Creates a simple single state. For an OPTIONAL state it also consists * of a similar state without the PROCEED edge, so that for each PROCEED transition branches * in computation state graph can be created only once. * * @param ignoreCondition condition that should be applied to IGNORE transition * @param sinkState state that the state being converted should point to * @param proceedState state that the state being converted should proceed to * @param isOptional whether the state being converted is optional * @return the created state */ @SuppressWarnings("unchecked") private State<T> createSingletonState(final State<T> sinkState, final State<T> proceedState, final IterativeCondition<T> takeCondition, final IterativeCondition<T> ignoreCondition, final boolean isOptional) { if (currentPattern instanceof GroupPattern) { return createGroupPatternState((GroupPattern) currentPattern, sinkState, proceedState, isOptional); } final State<T> singletonState = createState(currentPattern.getName(), State.StateType.Normal); // if event is accepted then all notPatterns previous to the optional states are no longer valid final State<T> sink = copyWithoutTransitiveNots(sinkState); singletonState.addTake(sink, takeCondition); // if no element accepted the previous nots are still valid. final IterativeCondition<T> proceedCondition = getTrueFunction(); // for the first state of a group pattern, its PROCEED edge should point to the following state of // that group pattern and the edge will be added at the end of creating the NFA for that group pattern if (isOptional && !headOfGroup(currentPattern)) { if (currentPattern.getQuantifier().hasProperty(Quantifier.QuantifierProperty.GREEDY)) { final IterativeCondition<T> untilCondition = (IterativeCondition<T>) currentPattern.getUntilCondition(); if (untilCondition != null) { singletonState.addProceed( originalStateMap.get(proceedState.getName()), new RichAndCondition<>(proceedCondition, untilCondition)); } singletonState.addProceed(proceedState, untilCondition != null ? new RichAndCondition<>(proceedCondition, new RichNotCondition<>(untilCondition)) : proceedCondition); } else { singletonState.addProceed(proceedState, proceedCondition); } } if (ignoreCondition != null) { final State<T> ignoreState; if (isOptional) { ignoreState = createState(currentPattern.getName(), State.StateType.Normal); ignoreState.addTake(sink, takeCondition); ignoreState.addIgnore(ignoreCondition); addStopStates(ignoreState); } else { ignoreState = singletonState; } singletonState.addIgnore(ignoreState, ignoreCondition); } return singletonState; }
Example #19
Source File: NFACompiler.java From flink with Apache License 2.0 | 4 votes |
/** * Creates the given state as a looping one. Looping state is one with TAKE edge to itself and * PROCEED edge to the sinkState. It also consists of a similar state without the PROCEED edge, so that * for each PROCEED transition branches in computation state graph can be created only once. * * @param sinkState the state that the converted state should point to * @return the first state of the created complex state */ @SuppressWarnings("unchecked") private State<T> createLooping(final State<T> sinkState) { if (currentPattern instanceof GroupPattern) { return createLoopingGroupPatternState((GroupPattern) currentPattern, sinkState); } final IterativeCondition<T> untilCondition = (IterativeCondition<T>) currentPattern.getUntilCondition(); final IterativeCondition<T> ignoreCondition = extendWithUntilCondition( getInnerIgnoreCondition(currentPattern), untilCondition, false); final IterativeCondition<T> takeCondition = extendWithUntilCondition( getTakeCondition(currentPattern), untilCondition, true); IterativeCondition<T> proceedCondition = getTrueFunction(); final State<T> loopingState = createState(currentPattern.getName(), State.StateType.Normal); if (currentPattern.getQuantifier().hasProperty(Quantifier.QuantifierProperty.GREEDY)) { if (untilCondition != null) { State<T> sinkStateCopy = copy(sinkState); loopingState.addProceed(sinkStateCopy, new RichAndCondition<>(proceedCondition, untilCondition)); originalStateMap.put(sinkState.getName(), sinkStateCopy); } loopingState.addProceed(sinkState, untilCondition != null ? new RichAndCondition<>(proceedCondition, new RichNotCondition<>(untilCondition)) : proceedCondition); updateWithGreedyCondition(sinkState, getTakeCondition(currentPattern)); } else { loopingState.addProceed(sinkState, proceedCondition); } loopingState.addTake(takeCondition); addStopStateToLooping(loopingState); if (ignoreCondition != null) { final State<T> ignoreState = createState(currentPattern.getName(), State.StateType.Normal); ignoreState.addTake(loopingState, takeCondition); ignoreState.addIgnore(ignoreCondition); loopingState.addIgnore(ignoreState, ignoreCondition); addStopStateToLooping(ignoreState); } return loopingState; }
Example #20
Source File: NFACompiler.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
/** * Creates the given state as a looping one. Looping state is one with TAKE edge to itself and * PROCEED edge to the sinkState. It also consists of a similar state without the PROCEED edge, so that * for each PROCEED transition branches in computation state graph can be created only once. * * @param sinkState the state that the converted state should point to * @return the first state of the created complex state */ @SuppressWarnings("unchecked") private State<T> createLooping(final State<T> sinkState) { if (currentPattern instanceof GroupPattern) { return createLoopingGroupPatternState((GroupPattern) currentPattern, sinkState); } final IterativeCondition<T> untilCondition = (IterativeCondition<T>) currentPattern.getUntilCondition(); final IterativeCondition<T> ignoreCondition = extendWithUntilCondition( getInnerIgnoreCondition(currentPattern), untilCondition, false); final IterativeCondition<T> takeCondition = extendWithUntilCondition( getTakeCondition(currentPattern), untilCondition, true); IterativeCondition<T> proceedCondition = getTrueFunction(); final State<T> loopingState = createState(currentPattern.getName(), State.StateType.Normal); if (currentPattern.getQuantifier().hasProperty(Quantifier.QuantifierProperty.GREEDY)) { if (untilCondition != null) { State<T> sinkStateCopy = copy(sinkState); loopingState.addProceed(sinkStateCopy, new RichAndCondition<>(proceedCondition, untilCondition)); originalStateMap.put(sinkState.getName(), sinkStateCopy); } loopingState.addProceed(sinkState, untilCondition != null ? new RichAndCondition<>(proceedCondition, new RichNotCondition<>(untilCondition)) : proceedCondition); updateWithGreedyCondition(sinkState, getTakeCondition(currentPattern)); } else { loopingState.addProceed(sinkState, proceedCondition); } loopingState.addTake(takeCondition); addStopStateToLooping(loopingState); if (ignoreCondition != null) { final State<T> ignoreState = createState(currentPattern.getName(), State.StateType.Normal); ignoreState.addTake(loopingState, takeCondition); ignoreState.addIgnore(ignoreCondition); loopingState.addIgnore(ignoreState, ignoreCondition); addStopStateToLooping(ignoreState); } return loopingState; }
Example #21
Source File: NFACompiler.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
/** * Creates a simple single state. For an OPTIONAL state it also consists * of a similar state without the PROCEED edge, so that for each PROCEED transition branches * in computation state graph can be created only once. * * @param ignoreCondition condition that should be applied to IGNORE transition * @param sinkState state that the state being converted should point to * @param proceedState state that the state being converted should proceed to * @param isOptional whether the state being converted is optional * @return the created state */ @SuppressWarnings("unchecked") private State<T> createSingletonState(final State<T> sinkState, final State<T> proceedState, final IterativeCondition<T> takeCondition, final IterativeCondition<T> ignoreCondition, final boolean isOptional) { if (currentPattern instanceof GroupPattern) { return createGroupPatternState((GroupPattern) currentPattern, sinkState, proceedState, isOptional); } final State<T> singletonState = createState(currentPattern.getName(), State.StateType.Normal); // if event is accepted then all notPatterns previous to the optional states are no longer valid final State<T> sink = copyWithoutTransitiveNots(sinkState); singletonState.addTake(sink, takeCondition); // if no element accepted the previous nots are still valid. final IterativeCondition<T> proceedCondition = getTrueFunction(); // for the first state of a group pattern, its PROCEED edge should point to the following state of // that group pattern and the edge will be added at the end of creating the NFA for that group pattern if (isOptional && !headOfGroup(currentPattern)) { if (currentPattern.getQuantifier().hasProperty(Quantifier.QuantifierProperty.GREEDY)) { final IterativeCondition<T> untilCondition = (IterativeCondition<T>) currentPattern.getUntilCondition(); if (untilCondition != null) { singletonState.addProceed( originalStateMap.get(proceedState.getName()), new RichAndCondition<>(proceedCondition, untilCondition)); } singletonState.addProceed(proceedState, untilCondition != null ? new RichAndCondition<>(proceedCondition, new RichNotCondition<>(untilCondition)) : proceedCondition); } else { singletonState.addProceed(proceedState, proceedCondition); } } if (ignoreCondition != null) { final State<T> ignoreState; if (isOptional) { ignoreState = createState(currentPattern.getName(), State.StateType.Normal); ignoreState.addTake(sink, takeCondition); ignoreState.addIgnore(ignoreCondition); addStopStates(ignoreState); } else { ignoreState = singletonState; } singletonState.addIgnore(ignoreState, ignoreCondition); } return singletonState; }