Java List Replace replaceIgnoreList(String text)

Here you can find the source of replaceIgnoreList(String text)

Description

Replaces the ignored characters.

License

Open Source License

Parameter

Parameter Description
Input text

Return

Cleaned text

Declaration

public static String replaceIgnoreList(String text) 

Method Source Code

//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;
    }
}

Related

  1. replaceAllInList(T a, T b, List list)
  2. replaceAndAdd(List par3List, String translateToLocal)
  3. replaceAtSymbol(String s, List params)
  4. replaceColons(List unstructuredSentences)
  5. replaceFields(Map mapFields, String changeStr, List listString)
  6. replaceInLines(List lines, String from, String to, int fromIndex, int toIndex)
  7. replaceInList(T a, T b, List list)
  8. replaceList(String v, String[] patterns, String[] values)
  9. replaceNpcId(final List npcListSqlLines, final int lineIndex, final int newNpcId, final boolean markAsGuess)