TextUtilities { public static String wordShape(String word) { StringBuilder shape = new StringBuilder(); for (char c : word.toCharArray()) { if (Character.isLetter(c)) { if (Character.isUpperCase(c)) { shape.append("X"); } else { shape.append("x"); } } else if (Character.isDigit(c)) { shape.append("d"); } else { shape.append(c); } } StringBuilder finalShape = new StringBuilder().append(shape.charAt(0)); String suffix = ""; if (word.length() > 2) { suffix = shape.substring(shape.length() - 2); } else if (word.length() > 1) { suffix = shape.substring(shape.length() - 1); } StringBuilder middle = new StringBuilder(); if (shape.length() > 3) { char ch = shape.charAt(1); for (int i = 1; i < shape.length() - 2; i++) { middle.append(ch); while (ch == shape.charAt(i) && i < shape.length() - 2) { i++; } ch = shape.charAt(i); } if (ch != middle.charAt(middle.length() - 1)) { middle.append(ch); } } return finalShape.append(middle).append(suffix).toString(); }  static String shadowNumbers(String string); @Deprecated static List<LayoutToken> dehyphenize(List<LayoutToken> tokens); static String dehyphenize(String text); static String getLastToken(String section); static String getFirstToken(String section); @Deprecated static String dehyphenizeHard(String text); static int getLevenshteinDistance(String s, String t); final static void appendN(StringBuffer buffer, char c, int nb); final static String removeAccents(String input); final static String cleanField(String input0, boolean applyStopwordsFilter); final static List<String> segment(String input, String segments); static String HTMLEncode(String string); static String HTMLEncode(String string, boolean fullHTML); static String normalizeRegex(String string); static String convertStreamToString(InputStream is); static int countDigit(String text); static String clean(String token); static String formatTwoDecimals(double d); static String formatFourDecimals(double d); static boolean isAllUpperCase(String text); static boolean isAllLowerCase(String text); static List<String> generateEmailVariants(String firstName, String lastName); static String capitalizeFully(String input, String delimiters); static String wordShape(String word); static String wordShapeTrimmed(String word); static String punctuationProfile(String line); static int getNbTokens(String line, int currentLinePos, List<String> tokenization); static String trimEncodedCharaters(String string); static boolean filterLine(String line); static StringBuilder replaceAll(StringBuilder sb, String regex, String replacement); static String prefix(String s, int count); static String suffix(String s, int count); static String JSONEncode(String json); static String strrep(char c, int times); static int getOccCount(String term, String string); static boolean test_digit(String tok); static boolean isAllUpperCaseOrDigitOrDot(String text); static final String punctuations; static final String fullPunctuations; static final String restrictedPunctuations; static String delimiters; static final String OR; static final String NEW_LINE; static final String SPACE; static final String COMMA; static final String QUOTE; static final String END_BRACKET; static final String START_BRACKET; static final String SHARP; static final String COLON; static final String DOUBLE_QUOTE; static final String ESC_DOUBLE_QUOTE; static final String LESS_THAN; static final String ESC_LESS_THAN; static final String GREATER_THAN; static final String ESC_GREATER_THAN; static final String AND; static final String ESC_AND; static final String SLASH; static final Pattern ORCIDPattern; static final Pattern DOIPattern; static final Pattern arXivPattern; static final Pattern pmidPattern; static final Pattern pmcidPattern; static final Pattern urlPattern; static final Pattern emailPattern; final static List<String> stopwords; }
@Test public void testWordShape() { testWordShape("This", "Xxxx", "Xx"); testWordShape("Equals", "Xxxx", "Xx"); testWordShape("O'Conor", "X'Xxxx", "X'Xx"); testWordShape("McDonalds", "XxXxxx", "XxXx"); testWordShape("any-where", "xx-xxx", "x-x"); testWordShape("1.First", "d.Xxxx", "d.Xx"); testWordShape("ThisIsCamelCase", "XxXxXxXxxx", "XxXxXxXx"); testWordShape("This:happens", "Xx:xxx", "Xx:x"); testWordShape("ABC", "XXX", "X"); testWordShape("AC", "XX", "X"); testWordShape("A", "X", "X"); testWordShape("Ab", "Xx", "Xx"); testWordShape("AbA", "XxX", "XxX"); testWordShape("uü", "xx", "x"); testWordShape("Üwe", "Xxx", "Xx"); testWordShape(" ", " ", " "); testWordShape("Tes9t99", "Xxdxdd", "Xxdxd"); testWordShape("T", "X", "X"); }