Java Code Examples for org.apache.flink.cep.pattern.Pattern#getPrevious()

The following examples show how to use org.apache.flink.cep.pattern.Pattern#getPrevious() . 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 6 votes vote down vote up
/**
 * Check pattern after match skip strategy.
 */
private void checkPatternSkipStrategy() {
	if (afterMatchSkipStrategy.getPatternName().isPresent()) {
		String patternName = afterMatchSkipStrategy.getPatternName().get();
		Pattern<T, ?> pattern = currentPattern;
		while (pattern.getPrevious() != null && !pattern.getName().equals(patternName)) {
			pattern = pattern.getPrevious();
		}

		// pattern name match check.
		if (!pattern.getName().equals(patternName)) {
			throw new MalformedPatternException("The pattern name specified in AfterMatchSkipStrategy " +
				"can not be found in the given Pattern");
		}
	}
}
 
Example 2
Source File: NFACompiler.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Retrieves list of conditions resulting in Stop state and names of the corresponding NOT patterns.
 *
 * <p>A current not condition can be produced in two cases:
 * <ol>
 *     <li>the previous pattern is a {@link Quantifier.ConsumingStrategy#NOT_FOLLOW}</li>
 *     <li>exists a backward path of {@link Quantifier.QuantifierProperty#OPTIONAL} patterns to
 *       {@link Quantifier.ConsumingStrategy#NOT_FOLLOW}</li>
 * </ol>
 *
 * <p><b>WARNING:</b> for more info on the second case see: {@link NFAFactoryCompiler#copyWithoutTransitiveNots(State)}
 *
 * @return list of not conditions with corresponding names
 */
private List<Tuple2<IterativeCondition<T>, String>> getCurrentNotCondition() {
	List<Tuple2<IterativeCondition<T>, String>> notConditions = new ArrayList<>();

	Pattern<T, ? extends T> previousPattern = currentPattern;
	while (previousPattern.getPrevious() != null && (
		previousPattern.getPrevious().getQuantifier().hasProperty(Quantifier.QuantifierProperty.OPTIONAL) ||
		previousPattern.getPrevious().getQuantifier().getConsumingStrategy() == Quantifier.ConsumingStrategy.NOT_FOLLOW)) {

		previousPattern = previousPattern.getPrevious();

		if (previousPattern.getQuantifier().getConsumingStrategy() == Quantifier.ConsumingStrategy.NOT_FOLLOW) {
			final IterativeCondition<T> notCondition = getTakeCondition(previousPattern);
			notConditions.add(Tuple2.of(notCondition, previousPattern.getName()));
		}
	}
	return notConditions;
}
 
Example 3
Source File: NFACompiler.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Check pattern after match skip strategy.
 */
private void checkPatternSkipStrategy() {
	if (afterMatchSkipStrategy.getPatternName().isPresent()) {
		String patternName = afterMatchSkipStrategy.getPatternName().get();
		Pattern<T, ?> pattern = currentPattern;
		while (pattern.getPrevious() != null && !pattern.getName().equals(patternName)) {
			pattern = pattern.getPrevious();
		}

		// pattern name match check.
		if (!pattern.getName().equals(patternName)) {
			throw new MalformedPatternException("The pattern name specified in AfterMatchSkipStrategy " +
				"can not be found in the given Pattern");
		}
	}
}
 
Example 4
Source File: NFACompiler.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Retrieves list of conditions resulting in Stop state and names of the corresponding NOT patterns.
 *
 * <p>A current not condition can be produced in two cases:
 * <ol>
 *     <li>the previous pattern is a {@link Quantifier.ConsumingStrategy#NOT_FOLLOW}</li>
 *     <li>exists a backward path of {@link Quantifier.QuantifierProperty#OPTIONAL} patterns to
 *       {@link Quantifier.ConsumingStrategy#NOT_FOLLOW}</li>
 * </ol>
 *
 * <p><b>WARNING:</b> for more info on the second case see: {@link NFAFactoryCompiler#copyWithoutTransitiveNots(State)}
 *
 * @return list of not conditions with corresponding names
 */
private List<Tuple2<IterativeCondition<T>, String>> getCurrentNotCondition() {
	List<Tuple2<IterativeCondition<T>, String>> notConditions = new ArrayList<>();

	Pattern<T, ? extends T> previousPattern = currentPattern;
	while (previousPattern.getPrevious() != null && (
		previousPattern.getPrevious().getQuantifier().hasProperty(Quantifier.QuantifierProperty.OPTIONAL) ||
		previousPattern.getPrevious().getQuantifier().getConsumingStrategy() == Quantifier.ConsumingStrategy.NOT_FOLLOW)) {

		previousPattern = previousPattern.getPrevious();

		if (previousPattern.getQuantifier().getConsumingStrategy() == Quantifier.ConsumingStrategy.NOT_FOLLOW) {
			final IterativeCondition<T> notCondition = getTakeCondition(previousPattern);
			notConditions.add(Tuple2.of(notCondition, previousPattern.getName()));
		}
	}
	return notConditions;
}
 
Example 5
Source File: NFACompiler.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Check pattern after match skip strategy.
 */
private void checkPatternSkipStrategy() {
	if (afterMatchSkipStrategy.getPatternName().isPresent()) {
		String patternName = afterMatchSkipStrategy.getPatternName().get();
		Pattern<T, ?> pattern = currentPattern;
		while (pattern.getPrevious() != null && !pattern.getName().equals(patternName)) {
			pattern = pattern.getPrevious();
		}

		// pattern name match check.
		if (!pattern.getName().equals(patternName)) {
			throw new MalformedPatternException("The pattern name specified in AfterMatchSkipStrategy " +
				"can not be found in the given Pattern");
		}
	}
}
 
Example 6
Source File: NFACompiler.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Retrieves list of conditions resulting in Stop state and names of the corresponding NOT patterns.
 *
 * <p>A current not condition can be produced in two cases:
 * <ol>
 *     <li>the previous pattern is a {@link Quantifier.ConsumingStrategy#NOT_FOLLOW}</li>
 *     <li>exists a backward path of {@link Quantifier.QuantifierProperty#OPTIONAL} patterns to
 *       {@link Quantifier.ConsumingStrategy#NOT_FOLLOW}</li>
 * </ol>
 *
 * <p><b>WARNING:</b> for more info on the second case see: {@link NFAFactoryCompiler#copyWithoutTransitiveNots(State)}
 *
 * @return list of not conditions with corresponding names
 */
private List<Tuple2<IterativeCondition<T>, String>> getCurrentNotCondition() {
	List<Tuple2<IterativeCondition<T>, String>> notConditions = new ArrayList<>();

	Pattern<T, ? extends T> previousPattern = currentPattern;
	while (previousPattern.getPrevious() != null && (
		previousPattern.getPrevious().getQuantifier().hasProperty(Quantifier.QuantifierProperty.OPTIONAL) ||
		previousPattern.getPrevious().getQuantifier().getConsumingStrategy() == Quantifier.ConsumingStrategy.NOT_FOLLOW)) {

		previousPattern = previousPattern.getPrevious();

		if (previousPattern.getQuantifier().getConsumingStrategy() == Quantifier.ConsumingStrategy.NOT_FOLLOW) {
			final IterativeCondition<T> notCondition = getTakeCondition(previousPattern);
			notConditions.add(Tuple2.of(notCondition, previousPattern.getName()));
		}
	}
	return notConditions;
}
 
Example 7
Source File: NFACompiler.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Check if there are duplicate pattern names. If yes, it
 * throws a {@link MalformedPatternException}.
 */
private void checkPatternNameUniqueness() {
	// make sure there is no pattern with name "$endState$"
	stateNameHandler.checkNameUniqueness(ENDING_STATE_NAME);
	Pattern patternToCheck = currentPattern;
	while (patternToCheck != null) {
		checkPatternNameUniqueness(patternToCheck);
		patternToCheck = patternToCheck.getPrevious();
	}
	stateNameHandler.clear();
}
 
Example 8
Source File: NFACompiler.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Check if the given pattern's name is already used or not. If yes, it
 * throws a {@link MalformedPatternException}.
 *
 * @param pattern The pattern to be checked
 */
private void checkPatternNameUniqueness(final Pattern pattern) {
	if (pattern instanceof GroupPattern) {
		Pattern patternToCheck = ((GroupPattern) pattern).getRawPattern();
		while (patternToCheck != null) {
			checkPatternNameUniqueness(patternToCheck);
			patternToCheck = patternToCheck.getPrevious();
		}
	} else {
		stateNameHandler.checkNameUniqueness(pattern.getName());
	}
}
 
Example 9
Source File: NFACompiler.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Check if there are duplicate pattern names. If yes, it
 * throws a {@link MalformedPatternException}.
 */
private void checkPatternNameUniqueness() {
	// make sure there is no pattern with name "$endState$"
	stateNameHandler.checkNameUniqueness(ENDING_STATE_NAME);
	Pattern patternToCheck = currentPattern;
	while (patternToCheck != null) {
		checkPatternNameUniqueness(patternToCheck);
		patternToCheck = patternToCheck.getPrevious();
	}
	stateNameHandler.clear();
}
 
Example 10
Source File: NFACompiler.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Check if the given pattern's name is already used or not. If yes, it
 * throws a {@link MalformedPatternException}.
 *
 * @param pattern The pattern to be checked
 */
private void checkPatternNameUniqueness(final Pattern pattern) {
	if (pattern instanceof GroupPattern) {
		Pattern patternToCheck = ((GroupPattern) pattern).getRawPattern();
		while (patternToCheck != null) {
			checkPatternNameUniqueness(patternToCheck);
			patternToCheck = patternToCheck.getPrevious();
		}
	} else {
		stateNameHandler.checkNameUniqueness(pattern.getName());
	}
}
 
Example 11
Source File: NFACompiler.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Check if there are duplicate pattern names. If yes, it
 * throws a {@link MalformedPatternException}.
 */
private void checkPatternNameUniqueness() {
	// make sure there is no pattern with name "$endState$"
	stateNameHandler.checkNameUniqueness(ENDING_STATE_NAME);
	Pattern patternToCheck = currentPattern;
	while (patternToCheck != null) {
		checkPatternNameUniqueness(patternToCheck);
		patternToCheck = patternToCheck.getPrevious();
	}
	stateNameHandler.clear();
}
 
Example 12
Source File: NFACompiler.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Check if the given pattern's name is already used or not. If yes, it
 * throws a {@link MalformedPatternException}.
 *
 * @param pattern The pattern to be checked
 */
private void checkPatternNameUniqueness(final Pattern pattern) {
	if (pattern instanceof GroupPattern) {
		Pattern patternToCheck = ((GroupPattern) pattern).getRawPattern();
		while (patternToCheck != null) {
			checkPatternNameUniqueness(patternToCheck);
			patternToCheck = patternToCheck.getPrevious();
		}
	} else {
		stateNameHandler.checkNameUniqueness(pattern.getName());
	}
}
 
Example 13
Source File: NFACompiler.java    From Flink-CEPplus with Apache License 2.0 2 votes vote down vote up
/**
 * Checks if the given pattern is the head pattern of the current group pattern.
 *
 * @param pattern the pattern to be checked
 * @return {@code true} iff the given pattern is in a group pattern and it is the head pattern of the
 * group pattern, {@code false} otherwise
 */
private boolean headOfGroup(Pattern<T, ?> pattern) {
	return currentGroupPattern != null && pattern.getPrevious() == null;
}
 
Example 14
Source File: NFACompiler.java    From flink with Apache License 2.0 2 votes vote down vote up
/**
 * Checks if the given pattern is the head pattern of the current group pattern.
 *
 * @param pattern the pattern to be checked
 * @return {@code true} iff the given pattern is in a group pattern and it is the head pattern of the
 * group pattern, {@code false} otherwise
 */
private boolean headOfGroup(Pattern<T, ?> pattern) {
	return currentGroupPattern != null && pattern.getPrevious() == null;
}
 
Example 15
Source File: NFACompiler.java    From flink with Apache License 2.0 2 votes vote down vote up
/**
 * Checks if the given pattern is the head pattern of the current group pattern.
 *
 * @param pattern the pattern to be checked
 * @return {@code true} iff the given pattern is in a group pattern and it is the head pattern of the
 * group pattern, {@code false} otherwise
 */
private boolean headOfGroup(Pattern<T, ?> pattern) {
	return currentGroupPattern != null && pattern.getPrevious() == null;
}