AddWord() публичный Метод

public AddWord ( char wordBuffer ) : void
wordBuffer char
Результат void
Пример #1
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();
        }
Пример #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();

        }