ChouBox/Utile/HuanMeng.DotNetCore/TextCensor/CheckTextVerification.cs
2025-04-23 19:20:23 +08:00

158 lines
5.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HuanMeng.DotNetCore.TextCensor
{
/// <summary>
/// 验证字符串是否违规
/// </summary>
//[Obsolete]
//public static class CheckTextVerification
//{
// static HashSet<string> ShieldStr = new HashSet<string>();
// static List<string> ShieldListStr = new List<string>();
// static string[] ShieldString = new string[0];
// static CheckTextVerification()
// {
// var ckPath = Path.GetFullPath("I:\\test\\PrayForBlessings\\PrayForBlessings\\ciku/");
// var filePath = Directory.EnumerateFiles(ckPath);
// foreach (var item in filePath)
// {
// CheckTextVerification.AddShieldString(item);
// }
// //
// }
// /// <summary>
// ///
// /// </summary>
// /// <param name="path"></param>
// /// <exception cref="Exception"></exception>
// public static void AddShieldString(string path)
// {
// if (!File.Exists(path))
// {
// throw new Exception("文件不存在");
// }
// HashSet<string> strings = new HashSet<string>();
// using (StreamReader reader = new StreamReader(path, UnicodeEncoding.UTF8))
// {
// while (reader.Peek() > 0)
// {
// var tempStr = (reader.ReadLine() ?? "");
// //string result = Regex.Replace(tempStr, pattern, "");
// if (!string.IsNullOrEmpty(tempStr))
// {
// var tempStringToLower = tempStr.ToLower().Split(new char[] { '、', ',' });
// string[] filteredArrayToLower = tempStringToLower.Where(s => !string.IsNullOrEmpty(s)).ToArray();
// strings.UnionWith(filteredArrayToLower);
// }
// }
// ShieldStr.UnionWith(strings);
// ShieldListStr.AddRange(ShieldStr);
// ShieldString = ShieldStr.ToArray();
// Console.WriteLine(string.Format($"[{Path.GetFileName(path)}]加载完毕,总共加载屏蔽字行数:{ShieldStr.Count}"));
// }
// }
// /// <summary>
// ///
// /// </summary>
// /// <param name="sourceTxt"></param>
// /// <returns></returns>
// public static bool VerifyTxt(string sourceTxt)
// {
// if (!string.IsNullOrEmpty(sourceTxt))
// {
// //先去掉空格,特殊字符
// string cleanedText = CleanedTextString(sourceTxt);
// foreach (var item in ShieldStr)
// {
// if (cleanedText.Contains(item))
// {
// return false;
// }
// }
// }
// return true;
// }
// /// <summary>
// ///
// /// </summary>
// /// <param name="sourceTxt"></param>
// /// <returns></returns>
// public static bool VerifyTxtList(string sourceTxt)
// {
// if (!string.IsNullOrEmpty(sourceTxt))
// {
// //先去掉空格,特殊字符
// string cleanedText = CleanedTextString(sourceTxt);
// foreach (var item in ShieldListStr)
// {
// if (cleanedText.Contains(item))
// {
// return false;//2.56
// }
// }
// }
// return true;
// }
// private static string replaceString = " ,.。,@*12345690_-";
// /// <summary>
// ///
// /// </summary>
// /// <param name="sourceTxt"></param>
// /// <returns></returns>
// private static string CleanedTextString(string sourceTxt)
// {
// string cleanedText = sourceTxt.ToLower()
// .Replace(" ", "")
// .Replace(",", "")
// .Replace(".", "")
// .Replace("。", "")
// .Replace("", "")
// .Replace("@", "")
// .Replace("-", "")
// .Replace("*", "")
// .Replace("1", "")
// .Replace("2", "")
// .Replace("3", "")
// .Replace("4", "")
// .Replace("5", "")
// .Replace("6", "")
// .Replace("9", "")
// .Replace("0", "")
// .Replace("_", "");
// return cleanedText;
// }
// public static bool VerifyTxtString(string sourceTxt)
// {
// if (!string.IsNullOrEmpty(sourceTxt))
// {
// //先去掉空格,特殊字符
// string cleanedText = CleanedTextString(sourceTxt);
// foreach (var item in ShieldString)
// {
// if (cleanedText.Contains(item))
// {
// return false;//2.56
// }
// }
// }
// return true;
// }
//}
}