Exemplo n.º 1
0
        public void NextLexeme(char[] segmentBuff, Context context)
        {

            //读取当前位置的char	
            char input = segmentBuff[context.Cursor];

            bool bufferLockFlag = false;
            //处理混合字母
            bufferLockFlag = this.ProcessMixLetter(input, context) || bufferLockFlag;
            //处理英文字母
            bufferLockFlag = this.ProcessEnglishLetter(input, context) || bufferLockFlag;
            //		//处理阿拉伯字母
            //		bufferLockFlag = this.processPureArabic(input, context) || bufferLockFlag;

            //判断是否锁定缓冲区
            if (bufferLockFlag)
            {
                context.LockBuffer(this);
            }
            else
            {
                //对缓冲区解锁
                context.UnlockBuffer(this);
            }
        }
Exemplo n.º 2
0
        public void NextLexeme(char[] segmentBuff, Context context)
        {
            fCaN = false;
            //数词处理部分
            ProcessNumber(segmentBuff, context);

            //量词处理部分		
            if (countStart == -1)
            {//未开始处理量词
                //当前游标的位置紧挨着数词
                if ((fCaN && nStart == -1)
                        || (nEnd != -1 && nEnd == context.Cursor - 1)//遇到CNM的状态
                        )
                {
                    //量词处理
                    ProcessCount(segmentBuff, context);

                }
            }
            else
            {//已开始处理量词
                //量词处理
                ProcessCount(segmentBuff, context);
            }

            //判断是否锁定缓冲区
            if (this.nStart == -1 && this.nEnd == -1 && NaN == this.nStatus
                    && this.countStart == -1 && this.countEnd == -1)
            {
                //对缓冲区解锁
                context.UnlockBuffer(this);
            }
            else
            {
                context.LockBuffer(this);
            }
        }
Exemplo n.º 3
0
        public void NextLexeme(char[] segmentBuff, Context context)
        {

            Hit hit;
            //读取当前位置的char	
            char input = segmentBuff[context.Cursor];

            if (CharacterHelper.IsCJKCharacter(input))
            {//是(CJK)字符,则进行处理
                if (hitList.Count > 0)
                {
                    //处理词段队列
                    Hit[] tmpArray = hitList.ToArray();
                    foreach (Hit tempHit in tmpArray)
                    {
                        hit = Dictionary.MatchWithHit(segmentBuff, context.Cursor, tempHit);

                        if (hit.IsMatch)
                        {//匹配成词
                            //判断是否有不可识别的词段
                            if (hit.Begin > doneIndex + 1)
                            {
                                //输出并处理从doneIndex+1 到 seg.start - 1之间的未知词段
                                ProcessUnknown(segmentBuff, context, doneIndex + 1, hit.Begin - 1);
                            }
                            //输出当前的词
                            Lexeme newLexeme = new Lexeme(context.BuffOffset, hit.Begin, context.Cursor - hit.Begin + 1, Lexeme.TYPE_CJK_NORMAL);
                            context.AddLexeme(newLexeme);
                            //更新goneIndex,标识已处理
                            if (doneIndex < context.Cursor)
                            {
                                doneIndex = context.Cursor;
                            }

                            if (hit.IsPrefix)
                            {//同时也是前缀

                            }
                            else
                            { //后面不再可能有匹配了
                                //移出当前的hit
                                hitList.Remove(hit);
                            }

                        }
                        else if (hit.IsPrefix)
                        {//前缀,未匹配成词

                        }
                        else if (hit.IsUnmatch)
                        {//不匹配
                            //移出当前的hit
                            hitList.Remove(hit);
                        }
                    }
                }

                //处理以input为开始的一个新hit
                hit = Dictionary.MatchInMainDict(segmentBuff, context.Cursor, 1);
                if (hit.IsMatch)
                {//匹配成词
                    //判断是否有不可识别的词段
                    if (context.Cursor > doneIndex + 1)
                    {
                        //输出并处理从doneIndex+1 到 context.Cursor- 1之间的未知
                        ProcessUnknown(segmentBuff, context, doneIndex + 1, context.Cursor - 1);
                    }
                    //输出当前的词
                    Lexeme newLexeme = new Lexeme(context.BuffOffset, context.Cursor, 1, Lexeme.TYPE_CJK_NORMAL);
                    context.AddLexeme(newLexeme);
                    //更新doneIndex,标识已处理
                    if (doneIndex < context.Cursor)
                    {
                        doneIndex = context.Cursor;
                    }

                    if (hit.IsPrefix)
                    {//同时也是前缀
                        //向词段队列增加新的Hit
                        hitList.AddLast(hit);  //Todo:代码不同
                    }

                }
                else if (hit.IsPrefix)
                {//前缀,未匹配成词
                    //向词段队列增加新的Hit
                    hitList.AddLast(hit);

                }
                else if (hit.IsUnmatch)
                {//不匹配,当前的input不是词,也不是词前缀,将其视为分割性的字符
                    if (doneIndex >= context.Cursor)
                    {
                        //当前不匹配的字符已经被处理过了,不需要再processUnknown
                        return;
                    }

                    //输出从doneIndex到当前字符(含当前字符)之间的未知词
                    ProcessUnknown(segmentBuff, context, doneIndex + 1, context.Cursor);
                    //更新doneIndex,标识已处理
                    doneIndex = context.Cursor;
                }

            }
            else
            {//输入的不是中文(CJK)字符
                if (hitList.Count > 0
                        && doneIndex < context.Cursor - 1)
                {
                    foreach (Hit tempHit in hitList)
                    {
                        //判断是否有不可识别的词段
                        if (doneIndex < tempHit.End)
                        {
                            //输出并处理从doneIndex+1 到 seg.end之间的未知词段
                            ProcessUnknown(segmentBuff, context, doneIndex + 1, tempHit.End);
                        }
                    }
                }
                //清空词段队列
                hitList.Clear();
                //更新doneIndex,标识已处理
                if (doneIndex < context.Cursor)
                {
                    doneIndex = context.Cursor;
                }
            }

            //缓冲区结束临界处理
            if (context.Cursor == context.Available - 1)
            { //读取缓冲区结束的最后一个字符			
                if (hitList.Count > 0 //队列中还有未处理词段
                    && doneIndex < context.Cursor)
                {//最后一个字符还未被输出过
                    foreach (Hit tempHit in hitList)
                    {
                        //判断是否有不可识别的词段
                        if (doneIndex < tempHit.End)
                        {
                            //输出并处理从doneIndex+1 到 seg.end之间的未知词段
                            ProcessUnknown(segmentBuff, context, doneIndex + 1, tempHit.End);
                        }
                    }
                }
                //清空词段队列
                hitList.Clear();
            }

            //判断是否锁定缓冲区
            if (hitList.Count == 0)
            {
                context.UnlockBuffer(this);

            }
            else
            {
                context.LockBuffer(this);

            }
        }