public static List <string> FindRhymes(string word, int matchingNumber, int length, int syllables, Activities.SearchActivity activity) { if (sQLiteDb.rhymes == null) { sQLiteDb.LoadData(activity); } sQLiteDb.foundWordsList = new List <string>(); var correctWord = String.Concat(word.Where(c => Char.IsLetter(c))); var toFind = correctWord.Substring(correctWord.Length - matchingNumber); // searchingCount = 0; //foundRhymesList = sQLiteDb.rhymes.Keys.OfType<string>().Where(w => w.Length >= matchingNumber && w.Substring(w.Length - matchingNumber).ToLower() == toFind && w.Length <= length && CountSyllables(w) == syllables).OrderBy(word => word).ToList(); //searching for matching rhymes var start = DateTime.Now; Parallel.ForEach(sQLiteDb.rhymes, rhymesEnum => { sQLiteDb.foundWordsList.AddRange(rhymesEnum.Where(rhyme => rhyme.Length >= matchingNumber && rhyme.Substring(rhyme.Length - matchingNumber).ToLower() == toFind && rhyme.Length <= length && CountSyllables(rhyme) == syllables)); //if (foundRhymesList.Count > searchingCount) //{ // try // { // activity.ShowPartOfList(foundRhymesList); // searchingCount = foundRhymesList.Count; // } // catch // { // } //} }); var finish = DateTime.Now; if (sQLiteDb.foundWordsList.Any()) { activity.SetTime(Math.Round(finish.Subtract(start).TotalSeconds, 2)); } return(sQLiteDb.foundWordsList.AsParallel().Distinct().OrderBy(f => f).ToList()); }
public static List <string> FindSynonyms(string word, Activities.SearchActivity activity) { if (sQLiteDb.synonyms == null) { sQLiteDb.LoadData(activity); //load if not loaded } var synonymsHashtable = new Hashtable(); sQLiteDb.foundWordsList = new List <string>(); var start = DateTime.Now; foreach (var s in sQLiteDb.synonyms.Keys.OfType <string>()) { var tempS = ";" + s.ToLower() + ";"; //adding first and last char in line (to check for full words) if (tempS.Contains(";" + word.ToLower() + ";")) { var elementsList = s.Split(';'); foreach (var item in elementsList) { if (sQLiteDb.NotContainsVulgarity(item.ToLower())) //checking if contains vulgarity { try { synonymsHashtable.Add(item, item); } catch { } } } elementsList = null; } } if (synonymsHashtable.Count == 0) //if not found find to similar words { string tmp; int min = word.Length / 2; for (int i = word.Length; i >= min; i--) { try { tmp = word.Remove(i).ToLower(); } catch { tmp = word.ToLower(); } foreach (var s in sQLiteDb.synonyms.Keys.OfType <string>()) { var tempS = ";" + s.ToLower() + ";"; //adding first and last char in line (to check for full words) if (tempS.Contains(";" + tmp.ToLower() + ";")) { var elementsList = s.Split(';'); foreach (var item in elementsList) { if (sQLiteDb.NotContainsVulgarity(item.ToLower())) //checking if contains vulgarity { try { synonymsHashtable.Add(item, item); } catch { } } } elementsList = null; } } if (synonymsHashtable.Count > 0) { break; } //if (sQLiteDb.synonyms.Keys.OfType<string>().Where(s => s.Contains(";" + tmp.ToLower())).Any()) //if contains a word reduced by i letters //{ // foreach (var s in sQLiteDb.synonyms.Keys.OfType<string>()) // { // var tempS = ";" + s.ToLower(); // if (tempS.Contains(";" + tmp.ToLower())) // { // var elementsList = s.Split(';'); // foreach (var item in elementsList) // { // if (sQLiteDb.NotContainsVulgarity(item.ToLower())) // { // try // { // synonymsHashtable.Add(item, item); // } // catch // { // } // } // } // elementsList = null; // } // } // break; //} } } sQLiteDb.foundWordsList = synonymsHashtable.Keys.OfType <string>().OrderBy(synonym => synonym).ToList(); var finish = DateTime.Now; if (sQLiteDb.foundWordsList.Any()) { activity.SetTime(Math.Round(finish.Subtract(start).TotalSeconds, 2)); } return(sQLiteDb.foundWordsList); }