public SearchWords PrepareRealWords(string[] words) { // Load index language: string language = ""; IndexCfg cfg = IndexCfg.Load(cnn); if (cfg != null) { language = cfg.Language.ToLower(); } // Normalize words, see if they are at the index and search synonymous: SearchWords synonimous = new SearchWords(); foreach (string word in words) { string n = Normalize(word); if (!n.Equals("")) { ArrayList currentSet = new ArrayList(3); Word wrd = Word.Load(cnn, n); if (wrd == null) { currentSet = SearchSynonyms(n, language); if (currentSet.Count == 0) { // Word not found: Exit without results. return(null); } } else { currentSet.Add(wrd); currentSet.AddRange(SearchSynonyms(n, language)); } synonimous.WordSets.Add(currentSet); } } if (synonimous.WordSets.Count == 0) { // Any good search word: Exit without results. return(null); } return(synonimous); }
public void DumpToDatabase(DbConnection connection, Document doc) { IDictionaryEnumerator e = table.GetEnumerator(); while (e.MoveNext()) { // Get the DB word: string wordText = (string)e.Key; Word word = Word.Load(connection, wordText); if (word == null) { word = new Word(wordText); word.Insert(connection); } // Store the counter. Counter cnt = (Counter)e.Value; WordInstance inst = new WordInstance(word.Code, doc.Code, cnt.Count, cnt.Positions); inst.Insert(connection); } }
public ArrayList SearchSynonyms(string word, string language) { ArrayList synonyms = new ArrayList(); if (language.Equals("spanish")) { if (word.EndsWith("es")) { // plural? string maybeSynonymous = word.Substring(0, word.Length - 2); Word wrd = Word.Load(cnn, maybeSynonymous); if (wrd != null) { synonyms.Add(wrd); } } if (word.EndsWith("s")) { // plural? string maybeSynonymous = word.Substring(0, word.Length - 1); Word wrd = Word.Load(cnn, maybeSynonymous); if (wrd != null) { synonyms.Add(wrd); } } else { // not plural string maybeSynonymous = word + "es"; Word wrd = Word.Load(cnn, maybeSynonymous); if (wrd != null) { synonyms.Add(wrd); } else { maybeSynonymous = word + "s"; wrd = Word.Load(cnn, maybeSynonymous); if (wrd != null) { synonyms.Add(wrd); } } } } if (language.Equals("english")) { if (word.EndsWith("s")) { // plural? string maybeSynonymous = word.Substring(0, word.Length - 1); Word wrd = Word.Load(cnn, maybeSynonymous); if (wrd != null) { synonyms.Add(wrd); } } else { // not plural string maybeSynonymous = word + "s"; Word wrd = Word.Load(cnn, maybeSynonymous); if (wrd != null) { synonyms.Add(wrd); } } } return(synonyms); }