WordPatternRecognizer extends AbstractPatternRecognizer { @Override public RecognitionResult recognize(String stringToRecognize, DataTypeEnum type) { RecognitionResult result = new RecognitionResult(); if (StringUtils.isEmpty(stringToRecognize)) { result.setResult(Collections.singleton(stringToRecognize), false); return result; } char[] ca = stringToRecognize.toCharArray(); StringBuilder patternSeq = new StringBuilder(); int runningPos = 0; int loopStart; int seqLength; while (runningPos < ca.length) { loopStart = runningPos; for (PatternExplorer pe : PatternExplorer.values()) { seqLength = exploreNextPattern(pe, ca, runningPos); if (seqLength > 0) { patternSeq.append(pe.getPattern(seqLength)); runningPos += seqLength; } } if (loopStart == runningPos) { patternSeq.append(ca[loopStart]); runningPos++; } } result.setResult(Collections.singleton(patternSeq.toString()), true); return result; }  static WordPatternRecognizer withCase(); static WordPatternRecognizer noCase(); @Override RecognitionResult recognize(String stringToRecognize, DataTypeEnum type); @Override Set<String> getValuePattern(String originalValue);  }
@Test public void checkIsoAllCodepoints() { List<Integer> issues = new ArrayList<>(); for (int codePoint = 0; codePoint < Character.MAX_CODE_POINT; codePoint++) { String string = String.valueOf(Character.toChars(codePoint)); String wordPattern = withCaseRecognizer.recognize(string).getPatternStringSet().iterator().next(); String regex = WordPatternToRegex.toRegex(wordPattern, true); Pattern pattern = Pattern.compile(regex); String errorMessage = "Code point " + codePoint + " (used for " + string + " with hex code " + Integer.toHexString(codePoint) + ") does not match " + regex + " (associated wordPattern is " + (WordPattern.get(wordPattern) == null ? string : WordPattern.get(wordPattern).name()) + ")"; Assert.assertTrue(errorMessage, pattern.matcher(string).matches()); if (!pattern.matcher(string).matches()) issues.add(codePoint); } display(issues); }