예제 #1
0
        public void LoadSortedUniqueWordList(IEnumerable <string> sortedWordList)
        {
            // load unique and sorted word list
            if (textBuffer != null)
            {
                return;
            }
            if (firstChar == '\0' || lastChar == '\0')
            {
                throw new NotSupportedException();
            }

            //---------------
            Dictionary <char, DevelopingWordGroup> wordGroups = new Dictionary <char, DevelopingWordGroup>();

            textBuffer = new TextBuffer(1024);
            foreach (string line in sortedWordList)
            {
                char[] lineBuffer = line.Trim().ToCharArray();
                int    lineLen    = lineBuffer.Length;
                char   c0;
                if (lineLen > 0 && (c0 = lineBuffer[0]) != '#')
                {
                    int startAt = textBuffer.CurrentPosition;
                    textBuffer.AddWord(lineBuffer);

#if DEBUG
                    if (lineLen > byte.MaxValue)
                    {
                        throw new NotSupportedException();
                    }
#endif

                    WordSpan wordspan = new WordSpan(startAt, (byte)lineLen);
                    //each wordgroup contains text span

                    DevelopingWordGroup found;
                    if (!wordGroups.TryGetValue(c0, out found))
                    {
                        found = new DevelopingWordGroup(new WordSpan(startAt, 1));
                        wordGroups.Add(c0, found);
                    }
                    found.AddWordSpan(wordspan);
                }
                //- next line
            }
            //------------------------------------------------------------------
            textBuffer.Freeze();
            //------------------------------------------------------------------
            //do index
            DoIndex(wordGroups);

            //clear, not used
            wordGroups.Clear();
        }
예제 #2
0
        public void LoadFromTextfile(string filename)
        {
            //once only
            if (textBuffer != null)
            {
                return;
            }
            if (firstChar == '\0' || lastChar == '\0')
            {
                throw new NotSupportedException();
            }

            //---------------
            Dictionary <char, DevelopingWordGroup> wordGroups = new Dictionary <char, DevelopingWordGroup>();

            using (FileStream fs = new FileStream(filename, FileMode.Open))
                using (StreamReader reader = new StreamReader(fs))
                {
                    //init with filesize
                    textBuffer = new TextBuffer((int)fs.Length);
                    string line = reader.ReadLine();
                    while (line != null)
                    {
                        line = line.Trim();
                        char[] lineBuffer = line.ToCharArray();
                        int    lineLen    = lineBuffer.Length;
                        char   c0;
                        if (lineLen > 0 && (c0 = lineBuffer[0]) != '#')
                        {
                            int startAt = textBuffer.CurrentPosition;
                            textBuffer.AddWord(lineBuffer);

#if DEBUG
                            if (lineLen > byte.MaxValue)
                            {
                                throw new NotSupportedException();
                            }
#endif

                            WordSpan wordspan = new WordSpan(startAt, (byte)lineLen);
                            //each wordgroup contains text span

                            DevelopingWordGroup found;
                            if (!wordGroups.TryGetValue(c0, out found))
                            {
                                found = new DevelopingWordGroup(new WordSpan(startAt, 1));
                                wordGroups.Add(c0, found);
                            }
                            found.AddWordSpan(wordspan);
                        }
                        //- next line
                        line = reader.ReadLine();
                    }

                    reader.Close();
                    fs.Close();
                }
            //------------------------------------------------------------------
            textBuffer.Freeze();
            //------------------------------------------------------------------
            //do index
            DoIndex(wordGroups);

            //clear, not used
            wordGroups.Clear();
        }