Example #1
0
    /// <summary>
    /// 检索
    /// </summary>
    /// <param name="paragragh"></param>
    /// <returns></returns>
    public static List <LocAndValue <String> > Search(AnnouceDocument doc, SearchRule rule)
    {
        var rtn = new List <LocAndValue <String> >();

        if (rule.BaseWord.Description.Count == 0)
        {
            //关键字,没有任何描述
            doc.CustomerList = LocateCustomerWord(doc.root, rule.BaseWord.Word, "关键字");
            doc.nermap.Anlayze(doc);
        }
        foreach (var paragragh in doc.nermap.ParagraghlocateDict.Values)
        {
            for (int baseIdx = 0; baseIdx < paragragh.NerList.Count; baseIdx++)
            {
                var evaluate = paragragh.NerList[baseIdx];
                if (!IsMatch(rule.BaseWord, evaluate))
                {
                    continue;
                }

                if (rule.SearchForward)
                {
                    //向前
                    for (int ScanIdx = baseIdx + 1; ScanIdx < paragragh.NerList.Count; ScanIdx++)
                    {
                        evaluate = paragragh.NerList[ScanIdx];
                        if (IsMatch(rule.Target, evaluate))
                        {
                            if (rule.Validator == null)
                            {
                                rtn.Add(evaluate);
                                break;
                            }
                            else
                            {
                                if (rule.Validator(evaluate))
                                {
                                    rtn.Add(evaluate);
                                    break;
                                }
                            }
                        }
                    }
                }
                else
                {
                    //向后
                    for (int ScanIdx = baseIdx - 1; ScanIdx > -1; ScanIdx--)
                    {
                        evaluate = paragragh.NerList[ScanIdx];
                        if (IsMatch(rule.Target, evaluate))
                        {
                            if (rule.Validator == null)
                            {
                                rtn.Add(evaluate);
                                break;
                            }
                            else
                            {
                                if (rule.Validator(evaluate))
                                {
                                    rtn.Add(evaluate);
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
        return(rtn);
    }