Java Code Examples for org.apache.flink.cep.nfa.State#addProceed()
The following examples show how to use
org.apache.flink.cep.nfa.State#addProceed() .
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 | 6 votes |
/** * Create the states for the group pattern as a looping one. * * @param groupPattern the group pattern to create the states for * @param sinkState the state that the group pattern being converted should point to * @return the first state of the states of the group pattern */ private State<T> createLoopingGroupPatternState( final GroupPattern<T, ?> groupPattern, final State<T> sinkState) { final IterativeCondition<T> proceedCondition = getTrueFunction(); Pattern<T, ?> oldCurrentPattern = currentPattern; Pattern<T, ?> oldFollowingPattern = followingPattern; GroupPattern<T, ?> oldGroupPattern = currentGroupPattern; final State<T> dummyState = createState(currentPattern.getName(), State.StateType.Normal); State<T> lastSink = dummyState; currentGroupPattern = groupPattern; currentPattern = groupPattern.getRawPattern(); lastSink = createMiddleStates(lastSink); lastSink = convertPattern(lastSink); lastSink.addProceed(sinkState, proceedCondition); dummyState.addProceed(lastSink, proceedCondition); currentPattern = oldCurrentPattern; followingPattern = oldFollowingPattern; currentGroupPattern = oldGroupPattern; return lastSink; }
Example 2
Source File: NFACompiler.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
/** * Create the states for the group pattern as a looping one. * * @param groupPattern the group pattern to create the states for * @param sinkState the state that the group pattern being converted should point to * @return the first state of the states of the group pattern */ private State<T> createLoopingGroupPatternState( final GroupPattern<T, ?> groupPattern, final State<T> sinkState) { final IterativeCondition<T> proceedCondition = getTrueFunction(); Pattern<T, ?> oldCurrentPattern = currentPattern; Pattern<T, ?> oldFollowingPattern = followingPattern; GroupPattern<T, ?> oldGroupPattern = currentGroupPattern; final State<T> dummyState = createState(currentPattern.getName(), State.StateType.Normal); State<T> lastSink = dummyState; currentGroupPattern = groupPattern; currentPattern = groupPattern.getRawPattern(); lastSink = createMiddleStates(lastSink); lastSink = convertPattern(lastSink); lastSink.addProceed(sinkState, proceedCondition); dummyState.addProceed(lastSink, proceedCondition); currentPattern = oldCurrentPattern; followingPattern = oldFollowingPattern; currentGroupPattern = oldGroupPattern; return lastSink; }
Example 3
Source File: NFACompiler.java From flink with Apache License 2.0 | 6 votes |
/** * Create the states for the group pattern as a looping one. * * @param groupPattern the group pattern to create the states for * @param sinkState the state that the group pattern being converted should point to * @return the first state of the states of the group pattern */ private State<T> createLoopingGroupPatternState( final GroupPattern<T, ?> groupPattern, final State<T> sinkState) { final IterativeCondition<T> proceedCondition = getTrueFunction(); Pattern<T, ?> oldCurrentPattern = currentPattern; Pattern<T, ?> oldFollowingPattern = followingPattern; GroupPattern<T, ?> oldGroupPattern = currentGroupPattern; final State<T> dummyState = createState(currentPattern.getName(), State.StateType.Normal); State<T> lastSink = dummyState; currentGroupPattern = groupPattern; currentPattern = groupPattern.getRawPattern(); lastSink = createMiddleStates(lastSink); lastSink = convertPattern(lastSink); lastSink.addProceed(sinkState, proceedCondition); dummyState.addProceed(lastSink, proceedCondition); currentPattern = oldCurrentPattern; followingPattern = oldFollowingPattern; currentGroupPattern = oldGroupPattern; return lastSink; }
Example 4
Source File: NFACompiler.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
private void addStopStateToLooping(final State<T> loopingState) { if (followingPattern != null && followingPattern.getQuantifier().getConsumingStrategy() == Quantifier.ConsumingStrategy.NOT_FOLLOW) { final IterativeCondition<T> notCondition = getTakeCondition(followingPattern); final State<T> stopState = createStopState(notCondition, followingPattern.getName()); loopingState.addProceed(stopState, notCondition); } }
Example 5
Source File: NFACompiler.java From flink with Apache License 2.0 | 5 votes |
/** * Create all the states for the group pattern. * * @param groupPattern the group pattern to create the states for * @param sinkState the state that the group pattern being converted should point to * @param proceedState the state that the group pattern being converted should proceed to * @param isOptional whether the group pattern being converted is optional * @return the first state of the states of the group pattern */ private State<T> createGroupPatternState( final GroupPattern<T, ?> groupPattern, final State<T> sinkState, final State<T> proceedState, final boolean isOptional) { final IterativeCondition<T> proceedCondition = getTrueFunction(); Pattern<T, ?> oldCurrentPattern = currentPattern; Pattern<T, ?> oldFollowingPattern = followingPattern; GroupPattern<T, ?> oldGroupPattern = currentGroupPattern; State<T> lastSink = sinkState; currentGroupPattern = groupPattern; currentPattern = groupPattern.getRawPattern(); lastSink = createMiddleStates(lastSink); lastSink = convertPattern(lastSink); if (isOptional) { // for the first state of a group pattern, its PROCEED edge should point to // the following state of that group pattern lastSink.addProceed(proceedState, proceedCondition); } currentPattern = oldCurrentPattern; followingPattern = oldFollowingPattern; currentGroupPattern = oldGroupPattern; return lastSink; }
Example 6
Source File: NFACompiler.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
/** * Create all the states for the group pattern. * * @param groupPattern the group pattern to create the states for * @param sinkState the state that the group pattern being converted should point to * @param proceedState the state that the group pattern being converted should proceed to * @param isOptional whether the group pattern being converted is optional * @return the first state of the states of the group pattern */ private State<T> createGroupPatternState( final GroupPattern<T, ?> groupPattern, final State<T> sinkState, final State<T> proceedState, final boolean isOptional) { final IterativeCondition<T> proceedCondition = getTrueFunction(); Pattern<T, ?> oldCurrentPattern = currentPattern; Pattern<T, ?> oldFollowingPattern = followingPattern; GroupPattern<T, ?> oldGroupPattern = currentGroupPattern; State<T> lastSink = sinkState; currentGroupPattern = groupPattern; currentPattern = groupPattern.getRawPattern(); lastSink = createMiddleStates(lastSink); lastSink = convertPattern(lastSink); if (isOptional) { // for the first state of a group pattern, its PROCEED edge should point to // the following state of that group pattern lastSink.addProceed(proceedState, proceedCondition); } currentPattern = oldCurrentPattern; followingPattern = oldFollowingPattern; currentGroupPattern = oldGroupPattern; return lastSink; }
Example 7
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 8
Source File: NFACompiler.java From flink with Apache License 2.0 | 5 votes |
private void addStopStateToLooping(final State<T> loopingState) { if (followingPattern != null && followingPattern.getQuantifier().getConsumingStrategy() == Quantifier.ConsumingStrategy.NOT_FOLLOW) { final IterativeCondition<T> notCondition = getTakeCondition(followingPattern); final State<T> stopState = createStopState(notCondition, followingPattern.getName()); loopingState.addProceed(stopState, notCondition); } }
Example 9
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 10
Source File: NFACompiler.java From flink with Apache License 2.0 | 5 votes |
/** * Create all the states for the group pattern. * * @param groupPattern the group pattern to create the states for * @param sinkState the state that the group pattern being converted should point to * @param proceedState the state that the group pattern being converted should proceed to * @param isOptional whether the group pattern being converted is optional * @return the first state of the states of the group pattern */ private State<T> createGroupPatternState( final GroupPattern<T, ?> groupPattern, final State<T> sinkState, final State<T> proceedState, final boolean isOptional) { final IterativeCondition<T> proceedCondition = getTrueFunction(); Pattern<T, ?> oldCurrentPattern = currentPattern; Pattern<T, ?> oldFollowingPattern = followingPattern; GroupPattern<T, ?> oldGroupPattern = currentGroupPattern; State<T> lastSink = sinkState; currentGroupPattern = groupPattern; currentPattern = groupPattern.getRawPattern(); lastSink = createMiddleStates(lastSink); lastSink = convertPattern(lastSink); if (isOptional) { // for the first state of a group pattern, its PROCEED edge should point to // the following state of that group pattern lastSink.addProceed(proceedState, proceedCondition); } currentPattern = oldCurrentPattern; followingPattern = oldFollowingPattern; currentGroupPattern = oldGroupPattern; 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.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 12
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 13
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 14
Source File: NFACompiler.java From flink with Apache License 2.0 | 4 votes |
private void addStopStates(final State<T> state) { for (Tuple2<IterativeCondition<T>, String> notCondition: getCurrentNotCondition()) { final State<T> stopState = createStopState(notCondition.f0, notCondition.f1); state.addProceed(stopState, notCondition.f0); } }
Example 15
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 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 |
private void addStopStates(final State<T> state) { for (Tuple2<IterativeCondition<T>, String> notCondition: getCurrentNotCondition()) { final State<T> stopState = createStopState(notCondition.f0, notCondition.f1); state.addProceed(stopState, notCondition.f0); } }
Example 18
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 19
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; }
Example 20
Source File: NFACompiler.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
private void addStopStates(final State<T> state) { for (Tuple2<IterativeCondition<T>, String> notCondition: getCurrentNotCondition()) { final State<T> stopState = createStopState(notCondition.f0, notCondition.f1); state.addProceed(stopState, notCondition.f0); } }