public static LoadMap ( string dangAmbigsFile ) : string>.Dictionary |
||
dangAmbigsFile | string | |
return | string>.Dictionary |
public static string PostProcess(string text, string langCode, string dangAmbigsPath, bool dangAmbigsOn) { // postprocessor StringBuilder strB = new StringBuilder(PostProcess(text, langCode)); if (!dangAmbigsOn) { return(strB.ToString()); } // replace text based on entries read from a DangAmbigs.txt file Dictionary <string, string> replaceRules = TextUtilities.LoadMap(Path.Combine(dangAmbigsPath, langCode + ".DangAmbigs.txt")); if (replaceRules.Count == 0 && langCode.Length > 3) { replaceRules = TextUtilities.LoadMap(Path.Combine(dangAmbigsPath, langCode.Substring(0, 3) + ".DangAmbigs.txt")); // fall back on base } Dictionary <string, string> .KeyCollection.Enumerator enumer = replaceRules.Keys.GetEnumerator(); while (enumer.MoveNext()) { string key = enumer.Current; string value = replaceRules[key]; strB = strB.Replace(key, value); } return(strB.ToString()); }
public static string PostProcess(string text, string langCode, string dangAmbigsPath, bool dangAmbigsOn, bool replaceHyphens) { if (text.Trim().Length == 0) { return(text); } if (replaceHyphens) { text = Net.SourceForge.Vietpad.Utilities.TextUtilities.ReplaceHyphensWithSoftHyphens(text); } // correct using external x.DangAmbigs.txt file first, if enabled if (dangAmbigsOn) { StringBuilder strB = new StringBuilder(text); // replace text based on entries read from an x.DangAmbigs.txt file List <Dictionary <string, string> > replaceRules = TextUtilities.LoadMap(Path.Combine(dangAmbigsPath, langCode + ".DangAmbigs.txt")); if (replaceRules.Count == 0 && langCode.Length > 3) { replaceRules = TextUtilities.LoadMap(Path.Combine(dangAmbigsPath, langCode.Substring(0, 3) + ".DangAmbigs.txt")); // fall back on base } if (replaceRules.Count == 0) { throw new NotSupportedException(langCode); } Dictionary <string, string> replaceRulesPlain = replaceRules[PLAIN]; Dictionary <string, string> .KeyCollection.Enumerator enumer = replaceRulesPlain.Keys.GetEnumerator(); while (enumer.MoveNext()) { string key = enumer.Current; string value = replaceRulesPlain[key]; strB = strB.Replace(key, value); } text = strB.ToString(); Dictionary <string, string> replaceRulesRegex = replaceRules[REGEX]; enumer = replaceRulesRegex.Keys.GetEnumerator(); while (enumer.MoveNext()) { string key = enumer.Current; string value = replaceRulesRegex[key]; text = Regex.Replace(text, key, value); } } // postprocessor text = PostProcess(text, langCode); // correct letter cases return(TextUtilities.CorrectLetterCases(text)); }
public static string PostProcess(string text, string langCode, string dangAmbigsPath, bool dangAmbigsOn) { if (text.Trim().Length == 0) { return(text); } // correct using external x.DangAmbigs.txt file first, if enabled if (dangAmbigsOn) { StringBuilder strB = new StringBuilder(text); // replace text based on entries read from an x.DangAmbigs.txt file Dictionary <string, string> replaceRules = TextUtilities.LoadMap(Path.Combine(dangAmbigsPath, langCode + ".DangAmbigs.txt")); if (replaceRules.Count == 0 && langCode.Length > 3) { replaceRules = TextUtilities.LoadMap(Path.Combine(dangAmbigsPath, langCode.Substring(0, 3) + ".DangAmbigs.txt")); // fall back on base } if (replaceRules.Count == 0) { throw new NotSupportedException(langCode); } Dictionary <string, string> .KeyCollection.Enumerator enumer = replaceRules.Keys.GetEnumerator(); while (enumer.MoveNext()) { string key = enumer.Current; string value = replaceRules[key]; strB = strB.Replace(key, value); } text = strB.ToString(); } // postprocessor text = PostProcess(text, langCode); // correct common errors caused by OCR text = TextUtilities.CorrectOCRErrors(text); // correct letter cases return(TextUtilities.CorrectLetterCases(text)); }