public static string BuildRegularExpression(string source, WordLanguage wl) { Dictionary <string, List <string> > TargetAlphabet = EnglishLetters; switch (wl) { case WordLanguage.English: TargetAlphabet = EnglishLetters; break; case WordLanguage.Russian: TargetAlphabet = RussianLetters; break; } string result = "("; foreach (var i in source) { result += "(?:"; foreach (var j in TargetAlphabet[i.ToString().ToLower()]) { result = result += j + "|"; } result = result.Remove(result.Length - 1); result += ")"; result += @"{1,}[*|`|.|,|_|\s|-]*"; } result = result.Remove(result.Length - 17); result += ")"; return(result); }
static void AddNewWord(string input, WordLanguage wl) { try { Words.Add(input, Filter.BuildRegularExpression(input, wl)); } catch (ArgumentException e) { Console.Clear(); Console.WriteLine("This word is currently exist\n" + e.Message + "\n"); } }
public int CompareTo(Word obj) { if (obj == null) { throw new NullReferenceException(); } if (Date.CompareTo(obj.Date) == 0 && EnglishExample.CompareTo(obj.EnglishExample) == 0 && EnglishWord.CompareTo(obj.EnglishWord) == 0 && TodaysWord.CompareTo(obj.TodaysWord) == 0 && TodaysExample.CompareTo(obj.TodaysExample) == 0 && WordLanguage.CompareTo(obj.WordLanguage) == 0 && PartOfSpeech.CompareTo(obj.PartOfSpeech) == 0) { return(0); } if (Date.CompareTo(obj.Date) != 0) { return(Date.CompareTo(obj.Date)); } else { if (EnglishExample.CompareTo(obj.EnglishExample) != 0) { return(EnglishExample.CompareTo(obj.EnglishExample)); } else { if (EnglishWord.CompareTo(obj.EnglishWord) != 0) { return(EnglishWord.CompareTo(obj.EnglishWord)); } else { if (WordLanguage.CompareTo(obj.WordLanguage) != 0) { return(WordLanguage.CompareTo(obj.WordLanguage)); } else { if (TodaysWord.CompareTo(obj.TodaysWord) != 0) { return(TodaysWord.CompareTo(obj.TodaysWord)); } else { if (TodaysExample.CompareTo(obj.TodaysExample) != 0) { return(TodaysExample.CompareTo(obj.TodaysExample)); } else { return(PartOfSpeech.CompareTo(obj.PartOfSpeech)); } } } } } } }