Example #1
0
        /// <summary>
        /// 主分词函数
        /// 从头到尾扫描字符串一遍,
        /// 并进行相应的处理
        /// </summary>
        ///
        private void work()
        {
            while (true)
            {
                if (_currentPos < _context.Length - 1)
                {
                    _token = next();
                }
                else
                {
                    if (_serachTime == 0)
                    {
                        break;
                    }
                    else
                    {
                        endFlex();
                        continue;
                    }
                }
                if (_isParagraphStarted)
                {
                    if (isParagraphEnd())
                    {
                        continue;
                    }

                    if (_isSentenceStarted)
                    {
                        if (_isSubsentenceStarted)
                        {
                            /****************************
                             * 无效字符 \r\n \b \f
                             * **********************/
                            if (MarkHelper.IsInvalidChar(_token))
                            {
                                continue;
                            }

                            /***********************
                             * 子句结束符 ,
                             * ************************/
                            if (isSubsentenceEnd())
                            {
                                continue;
                            }

                            /***************************
                             * 句子结束符 。 ; …… !?
                             * ************************/
                            if (isSentenceEnd())
                            {
                                continue;
                            }

                            /************************
                             * 分割特殊字符
                             * **********************************/
                            if (_serachTime == 0)
                            {
                                if (workSpecialChars())
                                {
                                    continue;
                                }
                            }
                            searchInTheTree();
                        }
                        else
                        {
                            subSentenceStart();
                        }
                    }
                    else
                    {
                        sentenceStart();
                    }
                }
                else
                {
                    if (CharHelper.IsBlank(_token))
                    {
                        continue;
                    }
                    paragraphStart();
                }
            }
        }