/// <summary> /// Parses a word definition at the specified offset in the specified file /// and returns the full set of synonyms (two levels of synsets) /// </summary> /// <param name="offset">The offset in the file at which to begin parsing</param> /// <param name="dbFileName">The full path of the file to open</param> /// <returns>A populated Definition object is successful; otherwise null</returns> public static List <string> GetDoublePartialDefinitionSynonyms(long offset, string dbFileName) { List <string> retVal = new List <string>(); try { string data = FileWordNetTools.ReadRecord(offset, dbFileName); if (!string.IsNullOrEmpty(data)) { int i = 0; string[] tokens = data.Split(DefinitionFile.Tokenizer, StringSplitOptions.RemoveEmptyEntries); long position = Convert.ToInt64(tokens[i]); i++; if (position != offset) { throw new ArithmeticException("The stream position is not aligned with the specified offset!"); } i++; // skip file number char partOfSpeech = tokens[i][0]; i++; int wordCount = Convert.ToInt32(tokens[i], 16); i++; for (int j = 0; j < wordCount * 2; j += 2) //Step by two for lexid { string tempWord = tokens[i + j]; if (!string.IsNullOrEmpty(tempWord)) { // it's a first level synonym-- add it twice! retVal.Add(DefinitionFile.DecodeWord(tempWord)); retVal.Add(DefinitionFile.DecodeWord(tempWord)); } } i += wordCount * 2; int ptrCount = Convert.ToInt32(tokens[i]); i++; for (int j = i; j < (i + (ptrCount * 4)); j += 4) { if (tokens[j + 2][0] == partOfSpeech && tokens[j][0] != '!') { // Look up these too! long pointerOffset = Convert.ToInt64(tokens[j + 1]); List <string> synonyms = GetPartialDefinitionSynonyms(pointerOffset, dbFileName); retVal.AddRange(synonyms); } } } } catch (Exception e) { Console.WriteLine(e.StackTrace); // don't do anything-- just don't add the word! } return(retVal); }