Example #1
0
        /// <summary>
        /// 反向分词函数,读取字母,数字序列
        /// </summary>
        /// <param name="ls">反向分词结果的词链表</param>
        /// <param name="temp">要进行反向分词的字符串序列</param>
        /// <param name="i">当前扫描位置</param>
        private void reflexNumberAlpha(List <_WordInnfo> ls, ref string temp, ref int i)
        {
            var temps = temp[i].ToString();
            var w     = new _WordInnfo();

            for (int j = i + 1; j < temp.Length; j++, i++)
            {
                if (Regex_Helper.Is_Number(temp[j].ToString()) || Regex_Helper.Is_Alpha(temp[j].ToString()))
                {
                    temps += temp[j];
                }
                else
                {
                    i++;
                    break;
                }
            }
            w.Name = temps;
            Lexicer.SetAlphaNumberType(w);
            ls.Add(w);
            if (i != temp.Length - 1)
            {
                i--;
            }
        }
            /// <summary>
            /// 将mathexpression 切分为 字母 数字 和符号的 序列
            /// </summary>
            /// <param name="str"></param>
            /// <returns></returns>
            public static List <string> FlexMathExpression(string str)
            {
                var ls   = new List <string>();
                var flag = -1;
                var temp = string.Empty;

                foreach (var item in str)
                {
                    if (Regex_Helper.Is_Alpha(item.ToString()))
                    {
                        if (flag == -1)
                        {
                            if (temp == string.Empty)
                            {
                                temp += item;
                                flag  = 0;
                            }
                        }
                        else if (flag == 1)
                        {
                            temp += item;
                        }
                        else
                        {
                            ls.Add(temp);
                            temp = item.ToString();
                            flag = 1;
                        }
                    }
                    else if (Regex_Helper.Is_Number(item.ToString()))
                    {
                        if (flag == -1)
                        {
                            flag  = 0;
                            temp += item;
                        }
                        else if (flag == 0)
                        {
                            temp += item;
                        }
                        else
                        {
                            ls.Add(temp);
                            temp += item;
                            flag  = 0;
                        }
                    }
                    else
                    {
                        ls.Add(temp);
                        ls.Add(item.ToString());
                        flag = -1;
                        temp = string.Empty;
                    }
                }

                ls.Add(temp);
                return(ls);
            }