package net.filebot.similarity; import static java.util.regex.Pattern.*; import static net.filebot.util.RegularExpressions.*; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Normalization { public static final Pattern APOSTROPHE = compile("['`´‘’ʻ]+"); public static final Pattern PUNCTUATION_OR_SPACE = compile("[\\p{Punct}\\p{Space}]+", UNICODE_CHARACTER_CLASS); public static final Pattern WORD_SEPARATOR_PUNCTUATION = compile("[:?._]"); public static final Pattern TRAILING_PARENTHESIS = compile("(? Doctor Who return TRAILING_PARENTHESIS.matcher(name).replaceAll("").trim(); } public static String truncateText(String title, int limit) { if (title.length() < limit) { return title; } String[] words = SPACE.split(title); StringBuilder s = new StringBuilder(); for (int i = 0; i < words.length && s.length() + words[i].length() < limit; i++) { if (i > 0) { s.append(' '); } s.append(words[i]); } return s.toString().trim(); } }