Java Code Examples for org.apache.flink.cep.nfa.State#addStateTransition()
The following examples show how to use
org.apache.flink.cep.nfa.State#addStateTransition() .
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-CEPplus with Apache License 2.0 | 5 votes |
private State<T> copy(final State<T> state) { final State<T> copyOfState = createState( NFAStateNameHandler.getOriginalNameFromInternal(state.getName()), state.getStateType()); for (StateTransition<T> tStateTransition : state.getStateTransitions()) { copyOfState.addStateTransition( tStateTransition.getAction(), tStateTransition.getTargetState().equals(tStateTransition.getSourceState()) ? copyOfState : tStateTransition.getTargetState(), tStateTransition.getCondition()); } return copyOfState; }
Example 2
Source File: NFACompiler.java From flink with Apache License 2.0 | 5 votes |
private State<T> copy(final State<T> state) { final State<T> copyOfState = createState( NFAStateNameHandler.getOriginalNameFromInternal(state.getName()), state.getStateType()); for (StateTransition<T> tStateTransition : state.getStateTransitions()) { copyOfState.addStateTransition( tStateTransition.getAction(), tStateTransition.getTargetState().equals(tStateTransition.getSourceState()) ? copyOfState : tStateTransition.getTargetState(), tStateTransition.getCondition()); } return copyOfState; }
Example 3
Source File: NFACompiler.java From flink with Apache License 2.0 | 5 votes |
private State<T> copy(final State<T> state) { final State<T> copyOfState = createState( NFAStateNameHandler.getOriginalNameFromInternal(state.getName()), state.getStateType()); for (StateTransition<T> tStateTransition : state.getStateTransitions()) { copyOfState.addStateTransition( tStateTransition.getAction(), tStateTransition.getTargetState().equals(tStateTransition.getSourceState()) ? copyOfState : tStateTransition.getTargetState(), tStateTransition.getCondition()); } return copyOfState; }
Example 4
Source File: NFACompiler.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
/** * This method creates an alternative state that is target for TAKE transition from an optional State. * Accepting an event in optional State discards all not Patterns that were present before it. * * <p>E.g for a Pattern begin("a").notFollowedBy("b").followedByAny("c").optional().followedByAny("d") * a sequence like : {a c b d} is a valid match, but {a b d} is not. * * <p><b>NOTICE:</b> This method creates copy only if it necessary. * * @param sinkState a state to create copy without transitive nots * @return the copy of the state itself if no modifications were needed */ private State<T> copyWithoutTransitiveNots(final State<T> sinkState) { final List<Tuple2<IterativeCondition<T>, String>> currentNotCondition = getCurrentNotCondition(); if (currentNotCondition.isEmpty() || !currentPattern.getQuantifier().hasProperty(Quantifier.QuantifierProperty.OPTIONAL)) { //we do not create an alternative path if we are NOT in an OPTIONAL state or there is no NOTs prior to //the optional state return sinkState; } final State<T> copyOfSink = createState(sinkState.getName(), sinkState.getStateType()); for (StateTransition<T> tStateTransition : sinkState.getStateTransitions()) { if (tStateTransition.getAction() == StateTransitionAction.PROCEED) { State<T> targetState = tStateTransition.getTargetState(); boolean remove = false; if (targetState.isStop()) { for (Tuple2<IterativeCondition<T>, String> notCondition : currentNotCondition) { if (targetState.getName().equals(notCondition.f1)) { remove = true; } } } else { targetState = copyWithoutTransitiveNots(tStateTransition.getTargetState()); } if (!remove) { copyOfSink.addStateTransition(tStateTransition.getAction(), targetState, tStateTransition.getCondition()); } } else { copyOfSink.addStateTransition( tStateTransition.getAction(), tStateTransition.getTargetState().equals(tStateTransition.getSourceState()) ? copyOfSink : tStateTransition.getTargetState(), tStateTransition.getCondition() ); } } return copyOfSink; }
Example 5
Source File: NFACompiler.java From flink with Apache License 2.0 | 4 votes |
/** * This method creates an alternative state that is target for TAKE transition from an optional State. * Accepting an event in optional State discards all not Patterns that were present before it. * * <p>E.g for a Pattern begin("a").notFollowedBy("b").followedByAny("c").optional().followedByAny("d") * a sequence like : {a c b d} is a valid match, but {a b d} is not. * * <p><b>NOTICE:</b> This method creates copy only if it necessary. * * @param sinkState a state to create copy without transitive nots * @return the copy of the state itself if no modifications were needed */ private State<T> copyWithoutTransitiveNots(final State<T> sinkState) { final List<Tuple2<IterativeCondition<T>, String>> currentNotCondition = getCurrentNotCondition(); if (currentNotCondition.isEmpty() || !currentPattern.getQuantifier().hasProperty(Quantifier.QuantifierProperty.OPTIONAL)) { //we do not create an alternative path if we are NOT in an OPTIONAL state or there is no NOTs prior to //the optional state return sinkState; } final State<T> copyOfSink = createState(sinkState.getName(), sinkState.getStateType()); for (StateTransition<T> tStateTransition : sinkState.getStateTransitions()) { if (tStateTransition.getAction() == StateTransitionAction.PROCEED) { State<T> targetState = tStateTransition.getTargetState(); boolean remove = false; if (targetState.isStop()) { for (Tuple2<IterativeCondition<T>, String> notCondition : currentNotCondition) { if (targetState.getName().equals(notCondition.f1)) { remove = true; } } } else { targetState = copyWithoutTransitiveNots(tStateTransition.getTargetState()); } if (!remove) { copyOfSink.addStateTransition(tStateTransition.getAction(), targetState, tStateTransition.getCondition()); } } else { copyOfSink.addStateTransition( tStateTransition.getAction(), tStateTransition.getTargetState().equals(tStateTransition.getSourceState()) ? copyOfSink : tStateTransition.getTargetState(), tStateTransition.getCondition() ); } } return copyOfSink; }
Example 6
Source File: NFACompiler.java From flink with Apache License 2.0 | 4 votes |
/** * This method creates an alternative state that is target for TAKE transition from an optional State. * Accepting an event in optional State discards all not Patterns that were present before it. * * <p>E.g for a Pattern begin("a").notFollowedBy("b").followedByAny("c").optional().followedByAny("d") * a sequence like : {a c b d} is a valid match, but {a b d} is not. * * <p><b>NOTICE:</b> This method creates copy only if it necessary. * * @param sinkState a state to create copy without transitive nots * @return the copy of the state itself if no modifications were needed */ private State<T> copyWithoutTransitiveNots(final State<T> sinkState) { final List<Tuple2<IterativeCondition<T>, String>> currentNotCondition = getCurrentNotCondition(); if (currentNotCondition.isEmpty() || !currentPattern.getQuantifier().hasProperty(Quantifier.QuantifierProperty.OPTIONAL)) { //we do not create an alternative path if we are NOT in an OPTIONAL state or there is no NOTs prior to //the optional state return sinkState; } final State<T> copyOfSink = createState(sinkState.getName(), sinkState.getStateType()); for (StateTransition<T> tStateTransition : sinkState.getStateTransitions()) { if (tStateTransition.getAction() == StateTransitionAction.PROCEED) { State<T> targetState = tStateTransition.getTargetState(); boolean remove = false; if (targetState.isStop()) { for (Tuple2<IterativeCondition<T>, String> notCondition : currentNotCondition) { if (targetState.getName().equals(notCondition.f1)) { remove = true; } } } else { targetState = copyWithoutTransitiveNots(tStateTransition.getTargetState()); } if (!remove) { copyOfSink.addStateTransition(tStateTransition.getAction(), targetState, tStateTransition.getCondition()); } } else { copyOfSink.addStateTransition( tStateTransition.getAction(), tStateTransition.getTargetState().equals(tStateTransition.getSourceState()) ? copyOfSink : tStateTransition.getTargetState(), tStateTransition.getCondition() ); } } return copyOfSink; }