private String getRegex(PatternRule rule) { StringBuilder sb = new StringBuilder(); List<PatternToken> tokens = rule.getPatternTokens(); boolean hasCSParts = tokens.stream().anyMatch(PatternToken::isCaseSensitive); boolean allCSParts = tokens.stream().allMatch(PatternToken::isCaseSensitive); for (PatternToken patternToken : rule.getPatternTokens()) { String str = patternToken.getString(); boolean setAllParenthesis = containsBackRef(rule.getMessage()) || containsBackRef(rule.getSuggestionsOutMsg()); if (hasCSParts && !allCSParts && !patternToken.isCaseSensitive()) { sb.append("(?i:"); appendTokenString(sb, str, setAllParenthesis); sb.append(")"); } else { appendTokenString(sb, str, setAllParenthesis); } sb.append(" "); } String escapedRegex = XmlEscapers.xmlContentEscaper().escape(sb.toString().trim()); if (allCSParts) { return "<regexp case_sensitive='yes'>" + escapedRegex + "</regexp>"; } return "<regexp>" + escapedRegex + "</regexp>"; }
private boolean isSimple(PatternToken t) { return !(t.getNegation() || t.getPOSNegation() || t.hasAndGroup() || t.hasExceptionList() || t.hasNextException() || t.hasOrGroup() || t.isInflected() || t.isPOStagRegularExpression() || t.getPOStag() != null || t.isReferenceElement() || t.isSentenceStart() || t.getSkipNext() >= 1); }