Exemple #1
0
        /// <summary>
        /// 判断文本是否包含关键字
        /// </summary>
        /// <param name="text">文本</param>
        /// <returns></returns>
        public override bool ContainsAny(string text)
        {
            bool r = false;

            search(text, (keyword, ch, end) => {
                r = !isInEnglishOrInNumber(keyword, ch, end, text);
                return(r);
            });
            if (r)
            {
                return(true);
            }
            var searchText = WordsHelper.ToSenseIllegalWords(text);

            search(searchText, (keyword, ch, end) => {
                r = !isInEnglishOrInNumber(keyword, ch, end, searchText);
                return(r);
            });
            if (r)
            {
                return(true);
            }
            searchText = WordsHelper.RemoveNontext(searchText);
            search(searchText, (keyword, ch, end) => {
                r = !isInEnglishOrInNumber(keyword, ch, end, searchText);
                return(r);
            });
            return(r);
        }
Exemple #2
0
        /// <summary>
        /// 设置关键字
        /// </summary>
        /// <param name="keywords">关键字列表</param>
        public override void SetKeywords(ICollection <string> keywords)
        {
            HashSet <string> kws = new HashSet <string>();

            foreach (var item in keywords)
            {
                kws.Add(WordsHelper.ToSenseIllegalWords(item));
            }
            base.SetKeywords(kws);
        }
Exemple #3
0
        /// <summary>
        /// 从文本中查找到第一个关键字
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        public override IllegalWordsSearchResult FindFirst(string text)
        {
            IllegalWordsSearchResult result = null;

            search(text, (keyword, ch, end) => {
                var start = end + 1 - keyword.Length;
                result    = GetIllegalResult(keyword, ch, start, end, text, text);
                return(result != null);
            });
            if (result != null)
            {
                return(result);
            }
            var searchText = WordsHelper.ToSenseIllegalWords(text);

            search(searchText, (keyword, ch, end) => {
                var start = end + 1 - keyword.Length;
                result    = GetIllegalResult(keyword, ch, start, end, text, searchText);
                return(result != null);
            });
            if (result != null)
            {
                return(result);
            }
            searchText = WordsHelper.RemoveNontext(searchText);
            search(searchText, (keyword, ch, end) => {
                var start = end;
                for (int i = 0; i < keyword.Length; i++)
                {
                    var n = searchText[start--];
                    while (n == 1)
                    {
                        n = searchText[start--];
                    }
                }
                start++;
                result = GetIllegalResult(keyword, ch, start, end, text, searchText);
                return(result != null);
            });
            if (result != null)
            {
                return(result);
            }
            return(IllegalWordsSearchResult.Empty);
        }
Exemple #4
0
        /// <summary>
        /// 在文本中查找所有的关键字
        /// </summary>
        /// <param name="text">文本</param>
        /// <returns></returns>
        public override List <IllegalWordsSearchResult> FindAll(string text)
        {
            List <IllegalWordsSearchResult> newlist = new List <IllegalWordsSearchResult>();
            string searchText = WordsHelper.ToSenseIllegalWords(text);

            searchAll(searchText, (keyword, ch, end) => {
                var start = end + 1 - keyword.Length;
                var r     = GetIllegalResult(keyword, ch, start, end, text, searchText);
                if (r != null)
                {
                    newlist.Add(r);
                }
            });
            searchText = removeChecks(searchText, newlist);
            //list.AddRange(newlist);
            //newlist.Clear();
            searchText = WordsHelper.RemoveNontext(searchText);
            searchAll(searchText, (keyword, ch, end) => {
                var start = end;
                for (int i = 0; i < keyword.Length; i++)
                {
                    var n = searchText[start--];
                    while (n == 1)
                    {
                        n = searchText[start--];
                    }
                }
                start++;
                var r = GetIllegalResult(keyword, ch, start, end, text, searchText);
                if (r != null)
                {
                    newlist.Add(r);
                }
            });
            return(newlist);
        }