using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; namespace DataBaseProcessing { public class HolidayRecognizer { // 定义常见节假日的关键词 private static readonly string[] holidays = { "元旦", "春节", "清明节", "劳动节", "端午节", "中秋节", "国庆节", "暑假", "春运" }; // 构建正则表达式来匹配节假日 private static string holidayPattern = string.Join("|", holidays); // 判断输入的句子中是否包含节假日 public static bool ContainsHoliday(string input) { // 使用正则表达式来匹配节假日 Regex regex = new Regex(holidayPattern); return regex.IsMatch(input); } // 如果包含节假日,返回匹配的节假日名称 public static string GetHolidayName(string input) { Regex regex = new Regex(holidayPattern); Match match = regex.Match(input); return match.Success ? match.Value : "未找到节假日"; } } }