/** * Fix all words that should be all uppercase and lowercases all words that are currently all * uppercase (but shouldn't be). * * @param line line to fix * @param originalLine original line * @param so {@link SubtitleObject} * @return fixed line */ private static String fixAllUppercase(String line, String originalLine, SubtitleObject so) { String[] split = so.split(RegexEnum.SPACE, line); String current = null; for (int i = 0; i < split.length; ++i) { current = split[i]; if (ALL_UPPERCASE.contains(current)) { if (!current.equals(current.toUpperCase())) { split[i] = split[i].toUpperCase(); } } else if (POTENTIAL_ALL_UPPERCASE.contains(current)) { if (originalLine.indexOf(current.toUpperCase()) == line.indexOf(current)) { split[i] = split[i].toUpperCase(); } } else if (current.length() > 1 && current.equals(current.toUpperCase()) && !StringUtil.containsLettersAndNumbers(current)) { split[i] = split[i].toLowerCase(); } } return String.join(" ", split); }
/** * Fix all proper nouns. * * @param line line to fix * @param so {@link SubtitleObject} * @return fixed line */ private static String fixProperNouns(String line, SubtitleObject so) { String[] split = so.split(RegexEnum.SPACE, line); String current = null; for (int i = 0; i < split.length; ++i) { current = split[i]; if (!StringUtil.isPunctuation(current) && !StringUtil.containsLettersAndNumbers(current)) { if (StringUtil.startsUpperCase(current) && current.length() > 1 && StringUtil.countUppercase(current) == 1) { if (!PROPER_NOUNS.contains(current) && !POTENTIAL_PROPER_NOUNS.contains(current)) { split[i] = current.toLowerCase(); } } else { if (PROPER_NOUNS.contains(current)) { split[i] = StringUtil.capitalize(current); } } } } return String.join(" ", split); }