コード例 #1
0
ファイル: LearnTool.cs プロジェクト: echofool/Ansj.Net
 /// <summary>
 /// </summary>
 /// <param name="smartForest"></param>
 /// <param name="hm"></param>
 /// <param name="nature"></param>
 private void ValueResult(SmartForest<NewWord> smartForest, HashMap<string, double> hm, Nature nature)
 {
     // TODO Auto-generated method stub
     if (smartForest == null || smartForest.Branches == null)
     {
         return;
     }
     for (var i = 0; i < smartForest.Branches.Length; i++)
     {
         var param = smartForest.Branches[i].Param;
         if (smartForest.Branches[i].Status == 3)
         {
             if (param.IsActive && (nature == null || param.Nature.Equals(nature)))
             {
                 hm.Add(param.Name, param.Score);
             }
         }
         else if (smartForest.Branches[i].Status == 2)
         {
             if (param.IsActive && (nature == null || param.Nature.Equals(nature)))
             {
                 hm.Add(param.Name, param.Score);
             }
             ValueResult(smartForest.Branches[i], hm, nature);
         }
         else
         {
             ValueResult(smartForest.Branches[i], hm, nature);
         }
     }
 }
コード例 #2
0
 public NewWordRecognition(Term[] terms, LearnTool learn)
 {
     _terms = terms;
     _forest = learn.GetForest();
     _branch = learn.GetForest();
 }
コード例 #3
0
        public void Recognition()
        {
            if (_branch == null)
            {
                return;
            }
            var length = _terms.Length - 1;

            for (var i = 0; i < length; i++)
            {
                if (_terms[i] == null)
                {
                    continue;
                }
                _from = _terms[i].From;
                _terms[i].Score = 0;
                _terms[i].SelfScore = 0;

                if (_branch != null)
                {
                    _branch = _branch.GetBranch(_terms[i].Name);

                    if (_branch == null || _branch.Status == 3)
                    {
                        Reset();
                        continue;
                    }

                    _offe = i;

                    // 循环查找添加
                    var term = _terms[i];
                    _stringBuilder.Append(term.Name);
                    if (_branch.Status == 2)
                    {
                        term.SelfScore = _branch.Param.Score;
                    }
                    var flag = true;
                    while (flag)
                    {
                        term = term.To;
                        _branch = _branch.GetBranch(term.Name);
                        // 如果没有找到跳出
                        if (_branch == null)
                        {
                            break;
                        }

                        switch (_branch.Status)
                        {
                            case 1:
                                _stringBuilder.Append(term.Name);
                                continue;
                            case 2:
                                _stringBuilder.Append(term.Name);
                                _score = _branch.Param.Score;
                                _tempNature = _branch.Param.Nature;
                                _to = term.To;
                                MakeNewTerm();
                                continue;
                            case 3:
                                _stringBuilder.Append(term.Name);
                                _score = _branch.Param.Score;
                                _tempNature = _branch.Param.Nature;
                                _to = term.To;
                                MakeNewTerm();
                                flag = false;
                                break;
                            default:
                                Trace.WriteLine("怎么能出现0呢?");
                                break;
                        }
                    }
                }
                Reset();
            }
        }
コード例 #4
0
 /// <summary>
 ///     重置
 /// </summary>
 private void Reset()
 {
     _offe = -1;
     _tempNature = null;
     _branch = _forest;
     _score = 0;
     _stringBuilder = new StringBuilder();
 }