Here you can find the source of replaceIgnoreList(String text)
Parameter | Description |
---|---|
Input | text |
public static String replaceIgnoreList(String text)
//package com.java2s; //License from project: GNU General Public License import java.util.HashMap; public class Main { /**/*from ww w . j a v a2s .com*/ * These are the salutations or other words that are not denoting end of * sentence word. <br> * This list is appendable. */ public static HashMap<String, String> exceptionToReplaceWith = new HashMap<String, String>() { { //Notice space in key and value, it is necessary for exact match otherwise, Isaac krurev. will also match rev. //If its a new sentence, then also there will be space. The only case missed here is when the text itself starts with a Salutation. //It is covered by inserting space in the first line of text //Note that: mr\\. is a regex hence we need to have \\. to represent a dot. put(" mr\\. ", " mr "); put(" mrs\\. ", " mrs "); put(" dr\\. ", " dr "); put(" prof\\. ", " prof "); put(" rev\\. ", " rev "); } }; /** * List of character that could be ignored and replaced. <br> * Customized, not generic. */ public static String ignoredCharRegex = "'|\"|,|;|:|\\(|\\)|\\[|\\]"; /** * String to replace the ignored characters. */ public static String replacementForIgnoredChar = ""; /** * Replaces the ignored characters. * * @param Input * text * @return Cleaned text */ public static String replaceIgnoreList(String text) { text = " " + text; for (String exception : exceptionToReplaceWith.keySet()) { text = text.replaceAll(exception, exceptionToReplaceWith.get(exception)); } text = text.replaceAll(ignoredCharRegex, replacementForIgnoredChar); return text; } }