LatinExtendedCharPatternRecognizer 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; } boolean isComplete = true; StringBuilder sb = new StringBuilder(); int n = stringToRecognize.length(); for (int i = 0; i < n; i++) { char c = stringToRecognize.charAt(i); int pos = CHARS_TO_REPLACE.indexOf(c); if (pos > -1) { sb.append(REPLACEMENT_CHARS.charAt(pos)); } else { sb.append(c); isComplete = false; } } result.setResult(Collections.singleton(sb.toString()), isComplete); return result; }  @Override RecognitionResult recognize(String stringToRecognize, DataTypeEnum type); boolean containsAlphabetic(String patternString); @Override Set<String> getValuePattern(String originalValue); static final String CHARS_TO_REPLACE; static final String REPLACEMENT_CHARS; }
@Test public void testRecognize() { LatinExtendedCharPatternRecognizer recognizer = new LatinExtendedCharPatternRecognizer(); RecognitionResult result = recognizer.recognize(""); Assert.assertFalse(result.isComplete()); Assert.assertEquals(Collections.singleton(""), result.getPatternStringSet()); RecognitionResult result2 = recognizer.recognize(" "); Assert.assertFalse(result2.isComplete()); Assert.assertEquals(Collections.singleton(" "), result2.getPatternStringSet()); RecognitionResult result3 = recognizer.recognize(null); Assert.assertFalse(result3.isComplete()); Assert.assertEquals(Collections.singleton(null), result3.getPatternStringSet()); String chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞß0123456789"; String replChars = "aaaaaaaaaaaaaaaaaaaaaaaaaaAAAAAAAAAAAAAAAAAAAAAAAAAAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA9999999999"; RecognitionResult result4 = recognizer.recognize(chars); Assert.assertTrue(result4.isComplete()); Assert.assertEquals(Collections.singleton(replChars), result4.getPatternStringSet()); String charsWithNoneAscii = "abcィd"; String replCharsWithNoneAscii = "aaaィa"; RecognitionResult result5 = recognizer.recognize(charsWithNoneAscii); Assert.assertFalse(result5.isComplete()); Assert.assertEquals(Collections.singleton(replCharsWithNoneAscii), result5.getPatternStringSet()); String charsWithDash = "abc-d"; String replCharsWithDash = "aaa-a"; RecognitionResult result6 = recognizer.recognize(charsWithDash); Assert.assertFalse(result6.isComplete()); Assert.assertEquals(Collections.singleton(replCharsWithDash), result6.getPatternStringSet()); Map<String, String> str2Pattern = new HashMap<>(); str2Pattern.put("*-!", "*-!"); str2Pattern.put("1-3", "9-9"); str2Pattern.put("2001-9-10 - 2009-09-08", "9999-9-99 - 9999-99-99"); str2Pattern.put("22. fdsud 1975", "99. aaaaa 9999"); testRecognition(str2Pattern); str2Pattern.clear(); str2Pattern.put("2001-8-20", "yyyy-M-d"); str2Pattern.put("22. july 1975", "d. MMMM yyyy"); testDateRecognition(str2Pattern); }