Пример #1
0
        /// <summary>
        /// Parses a word definition at the specified offset in the specified file
        ///  and just returns the synonyms
        /// </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> GetPartialDefinitionSynonyms(long offset, string dbFileName)
        {
            List <string> retVal = new List <string>();

            try
            {
                string data = FileWordNetTools.ReadPartialRecord(offset, dbFileName, 128);
                if (!string.IsNullOrEmpty(data))
                {
                    int      i      = 0;
                    string[] tokens = data.Split(DefinitionFile.Tokenizer, 24, 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 += 2;

                    int wordCount = Convert.ToInt32(tokens[i], 16);
                    i++;

                    for (int j = 0; j < wordCount * 2 && j + i < tokens.Length; j += 2) //Step by two for lexid
                    {
                        string tempWord = tokens[i + j];
                        if (!string.IsNullOrEmpty(tempWord))
                        {
                            retVal.Add(DefinitionFile.DecodeWord(tempWord));
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                // don't do anything-- just don't add the word!
            }
            return(retVal);
        }