/// <summary> /// Finds definitions for a specified word /// </summary> /// <param name="word">The word to define</param> /// <returns>A dictionary of wrods and definition pertenant to the specified word</returns> public Dictionary <string, List <WordNetDefinition> > GetDefinition(string word) { Dictionary <string, List <WordNetDefinition> > retVal = new Dictionary <string, List <WordNetDefinition> >(); List <string> fileListIndex = GetIndexForType(WordNetAccess.PartOfSpeech.All); List <string> fileListData = GetDBaseForType(WordNetAccess.PartOfSpeech.All); for (int i = 0; i < fileListIndex.Count; i++) { long offset = FastSearch(word.ToLower(), fileListIndex[i], IndexFile.Tokenizer); if (offset > 0) { Index idx = ParseIndexAt(offset, fileListIndex[i]); foreach (long synSetOffset in idx.SynSetsOffsets) { try { WordNetDefinition def = ParseDefinitionAt(synSetOffset, fileListData[i], word); string wordKey = string.Join(", ", def.Words.ToArray()); if (!retVal.ContainsKey(wordKey)) { retVal.Add(wordKey, new List <WordNetDefinition>()); } retVal[wordKey].Add(def); } catch (Exception ex) { string message = ex.Message; } } } } return(retVal); }
/// <summary> /// Parses an definition structure from the specified file at the specified offset /// </summary> /// <param name="offset">The offset in the file at which the index exists</param> /// <param name="dbFileName">The full path to the database file to open</param> /// <returns>A populated index structure in successful; otherwise an empty index structure</returns> internal WordNetDefinition ParseDefinitionAt(long offset, string dbFileName, string word) { string data = ReadRecord(offset, dbFileName); WordNetDefinition def = DefinitionFile.ParseDefinition(data, word, dbFileName); def.Position = offset; return(def); }
IEnumerator <KeyValuePair <long, WordNetDefinition> > IEnumerable <KeyValuePair <long, WordNetDefinition> > .GetEnumerator() { List <KeyValuePair <long, WordNetDefinition> > all = new List <KeyValuePair <long, WordNetDefinition> >(); foreach (KeyValuePair <long, string[]> words in synonyms) { WordNetDefinition one = new WordNetDefinition(); one.Words = new List <string>(words.Value); all.Add(new KeyValuePair <long, WordNetDefinition>(words.Key, one)); } return((IEnumerator <KeyValuePair <long, WordNetDefinition> >)all); }
public bool TryGetValue(long key, out WordNetDefinition value) { string[] words; if (!synonyms.TryGetValue(key, out words)) { value = null; return(false); } value = new WordNetDefinition(); value.Words = new List <string>(words); return(true); }