private string RetrieveSearchQuery(string cmd, string item) { List <string> text = new List <string>(item.ToLower().Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries)); SearchEngine engine = AssistingSearchEngine(cmd); string[] tokens = engine.Name.ToLower().Split(new string[] { " ", "_", "-", "(", ")", "[", "]", "{", "}" }, StringSplitOptions.RemoveEmptyEntries); // discover what tokens represent a search engine foreach (string token in tokens) { int min = Int32.MaxValue; int min_pos = -1; for (int i = 0; i < text.Count; i++) { if (StringUtility.WordContainsWord(text[i], token)) { int dist = EditDistanceMeasurer.LevenshteinDistance(text[i], token); if (dist < min) { min = dist; min_pos = i; } } } // delete the token if (min_pos != -1) { text.RemoveAt(min_pos); } } // build the query string content = string.Empty; for (int i = 0; i < text.Count; i++) { if (i == text.Count - 1) { content += text[i]; } else { content += text[i] + " "; } } return(content); }
private int CalcNonFittedWordDistance(string word1, string word2) { return(EditDistanceMeasurer.LevenshteinDistance(word2, word1)); }