final AnalyzedTokenReadings[] tokens = sentence.getTokensWithoutWhitespace();
RuleMatch prevRuleMatch = null;
final Queue<AnalyzedTokenReadings> prevTokens = new ArrayBlockingQueue<>(MAX_TERMS);
for (int i = 0; i < tokens.length + MAX_TERMS-1; i++) {
final AnalyzedTokenReadings token;
// we need to extend the token list so we find matches at the end of the original list:
if (i >= tokens.length) {
token = new AnalyzedTokenReadings(new AnalyzedToken("", "", null), prevTokens.peek().getStartPos());
} else {
token = tokens[i];
}
if (i == 0) {
addToQueue(token, prevTokens);
continue;
}
if (token.isImmunized()) {
continue;
}
final AnalyzedTokenReadings firstMatchToken = prevTokens.peek();
final List<String> stringsToCheck = new ArrayList<>();
final List<String> origStringsToCheck = new ArrayList<>(); // original upper/lowercase spelling
final Map<String, AnalyzedTokenReadings> stringToToken =
getStringToTokenMap(prevTokens, stringsToCheck, origStringsToCheck);
// iterate backwards over all potentially incorrect strings to make
// sure we match longer strings first:
for (int k = stringsToCheck.size()-1; k >= 0; k--) {
final String stringToCheck = stringsToCheck.get(k);
final String origStringToCheck = origStringsToCheck.get(k);
if (incorrectCompounds.contains(stringToCheck)) {
final AnalyzedTokenReadings atr = stringToToken.get(stringToCheck);
String msg = null;
final List<String> replacement = new ArrayList<>();
if (!noDashSuggestion.contains(stringToCheck)) {
replacement.add(origStringToCheck.replace(' ', '-'));
msg = withHyphenMessage;
}
if (isNotAllUppercase(origStringToCheck) && !onlyDashSuggestion.contains(stringToCheck)) {
replacement.add(mergeCompound(origStringToCheck));
msg = withoutHyphenMessage;
}
final String[] parts = stringToCheck.split(" ");
if (parts.length > 0 && parts[0].length() == 1) {
replacement.clear();
replacement.add(origStringToCheck.replace(' ', '-'));
msg = withHyphenMessage;
} else if (replacement.isEmpty() || replacement.size() == 2) { // isEmpty shouldn't happen
msg = withOrWithoutHyphenMessage;
}
final RuleMatch ruleMatch = new RuleMatch(this, firstMatchToken.getStartPos(),
atr.getStartPos() + atr.getToken().length(), msg, shortDesc);
// avoid duplicate matches:
if (prevRuleMatch != null && prevRuleMatch.getFromPos() == ruleMatch.getFromPos()) {
prevRuleMatch = ruleMatch;
break;
}