示例#1
0
        private void loadDictionary(WordList dictionary, ArrayList alWaitingList)
        {
            System.IO.StreamReader fsr1 = new System.IO.StreamReader(new System.IO.FileStream(".\\twl2defs.txt", System.IO.FileMode.Open));
            while (!fsr1.EndOfStream)
            {
                String str1       = fsr1.ReadLine();
                int    pos        = str1.IndexOf(' ');
                String strWord    = str1.Substring(0, pos).ToUpper().Trim();
                String strMeaning = str1.Substring(pos).Trim();


                // If the meaning is pointing to an existing entry
                // then do not add this word. Instead add the word as an usage to the existing word
                int posOfIndexer = strMeaning.IndexOf('<');
                if (posOfIndexer == 0)
                {
                    String strParent = strMeaning.Substring(posOfIndexer + 1, strMeaning.IndexOf('=') - 1);
                    Word   w         = dictionary.getWord(strParent);
                    if (w != null)
                    {
                        String[] strNewusages = new String[] { strWord };
                        w.addUsages(strNewusages);
                    }
                    else
                    {
                        // Put the word in a waiting list
                        WaitingList wl = new WaitingList();
                        wl.strParent = strParent;
                        wl.strUsage  = strWord;
                        alWaitingList.Add(wl);
                    }
                }
                else
                {
                    Word w = new Word(strWord);
                    w.setMeaning(strMeaning);
                    dictionary.addWord(w);
                }
            }
            fsr1.Close();
        }
示例#2
0
        public void Process()
        {
            WordList wordList;

            wordList = new WordList();
            System.IO.StreamReader fsr = new System.IO.StreamReader(new System.IO.FileStream(".\\dict.txt", System.IO.FileMode.Open));
            while (!fsr.EndOfStream)
            {
                String str = fsr.ReadLine();

                Word w = new Word(str);
                wordList.addWord(w);
            }
            fsr.Close();

            wordList.printList();
            // Old Word list indexed
            // Now open the new wordlist and for each word, check if it is already there in the old word list
            fsr = new System.IO.StreamReader(new System.IO.FileStream(".\\ospd4.txt", System.IO.FileMode.Open));
            WordList newWordList = new WordList();

            // Parse the twl2def worldlist

            WordList  dictionary    = new WordList();
            ArrayList alWaitingList = new ArrayList();

            loadDictionary(dictionary, alWaitingList);


            // Process the waiting list
            for (int i = 0; i < alWaitingList.Count; i++)
            {
                WaitingList wl = (WaitingList)alWaitingList[i];
                Word        w  = dictionary.getWord(wl.strParent);
                if (w != null)
                {
                    String[] strNewusages = new String[] { wl.strUsage };
                    w.addUsages(strNewusages);
                }
            }

            while (!fsr.EndOfStream)
            {
                String str = fsr.ReadLine();

                // First check for it in the existing wordlist section
                if (wordList.getWord(str) == null)
                {
                    Console.Write(str);

                    // If not present, open the dictionary and get the meaning
                    Word newWord = dictionary.getWord(str);
                    if (newWord != null)
                    {
                        if (newWordList.getWord(str) == null)
                        {
                            newWordList.addWord(newWord);
                        }
                        Console.WriteLine(" - " + newWord.getMeaning());
                    }
                    else
                    {
                        //for (int m = 0; m < newWord.getUsages().Length; m++)
                        //{
                        //    strLine = strLine + newWord.getUsages()[m] + " ";
                        //}
                        //strLine = strLine + "\\ ";
                        //strLine = strLine + newWord.getWord() + " ";
                        //strLine = strLine + "NO MEANING";
                        //Console.WriteLine(" - NO MEANING");
                    }
                }
            }
            fsr.Close();
            newWordList.printList();
        }