Beispiel #1
0
        public static PhraseStorage SplitFormula(this string formula)
        {
            PhraseStorage  ps = new PhraseStorage();
            PhraseAnalyzer pa = new PhraseAnalyzer(formula + "#=", ref ps);

            if (pa.Succeed == false)
            {
                throw new Exception(string.Format("公式“{0}”错误", formula));;
            }
            SemanticAnalyzer sa = new SemanticAnalyzer(ref ps);

            if (sa.Check() == false)
            {
                throw new Exception(string.Format("公式“{0}”有误,{1}", formula, sa.ErrorTip));;
            }

            return(ps);
        }
Beispiel #2
0
        /// <summary>
        /// 保存词
        /// </summary>
        /// <param name="startpos">开始位置</param>
        /// <param name="endpos">结束位置</param>
        private void SavePhrase(int startpos, int endpos)
        {
            string temp = null;

            //处理'@'
            if (startpos == endpos && _chArray[startpos] == '@')
            {
                _ps.AddPhraseResult("-", PhraseTypeEnum.less);
                return;
            }
            //处理其他词元
            if (endpos >= 0 && startpos >= 0 && endpos >= startpos)
            {
                //trim(),以防止在startpos到endpos头尾出现空格
                temp = _sentence.Substring(startpos, endpos - startpos + 1).Trim().ToLower();
                _ps.AddPhraseResult(temp, PhraseAnalyzer.StrToType(temp));
            }
        }