using MathNet.Numerics; using System.Configuration; using System.Diagnostics; using System.Text.RegularExpressions; using TEAMModelOS.SDK.DI; using TEAMModelOS.SDK.Extension; namespace HTEX.Test { public class Program { public static void Main(string[] args) { Test(); var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddControllers(); builder.Services.AddAzureStorage(builder.Configuration.GetValue("Azure:Storage:ConnectionString")); builder.Services.AddAzureRedis(builder.Configuration.GetValue("Azure:Redis:ConnectionString")); builder.Services.AddAzureCosmos(builder.Configuration.GetValue("Azure:Cosmos:ConnectionString")); builder.Services.AddAzureServiceBus(builder.Configuration.GetValue("Azure:ServiceBus:ConnectionString")); builder.Services.AddAzureSignalR(builder.Configuration.GetValue("Azure:SignalR:ConnectionString")); builder.Services.AddSnowflakeId(Convert.ToInt64(builder.Configuration.GetValue("Option:LocationNum")), 1); builder.Services.AddHttpClient(); var app = builder.Build(); // Configure the HTTP request pipeline. app.UseHttpsRedirection(); app.UseAuthorization(); app.MapControllers(); app.Run(); } public static string Test() { string originalString = "这 是 一 个 测 试。\n \r\t "; string stringWithoutSpaces = Regex.Replace(originalString, @"\s+", ""); // 标准答案集合 List standardAnswers = new List { "apple", "banana", "cherry" }; // 学生作答集合 List studentAnswers = new List { "bana1na", "orange", "grape", "111" }; // 使用LINQ查询来判断是否有匹配的答案 bool hasMatchingAnswer = standardAnswers.Intersect(studentAnswers).Any(); // 输出结果 Console.WriteLine("学生答案中是否有符合标准答案的? " + (hasMatchingAnswer ? "是" : "否")); string sentence1 = "学生答案中是否有符合标准答案的"; string sentence2 = "学生答案中是否有标合标准答案的"; double areSimilar = AreSentencesSimilar(sentence1, sentence2); Console.WriteLine($"Are the sentences similar? {areSimilar}"); List a = new List() { "a", "d" }; List b = new List() { "b", "a", "c" }; var v = (a.All(item => b.Contains(item))); string c = "[\r\n 1\r\n]"; List d = c.ToObject>(); return "Hello World!"; } public static void calculate_text_similarity() { string pythonExe = @"C:\Path\To\Python\python.exe"; // 修改为你的Python解释器路径 string scriptPath = @"C:\Path\To\Your\Script\calculate_similarity.py"; // 修改为你的脚本路径 string text1 = "今天天气真好"; string text2 = "今天天气不错"; ProcessStartInfo start = new ProcessStartInfo(); start.FileName = pythonExe; start.Arguments = $"\"{scriptPath}\" \"{text1}\" \"{text2}\""; start.UseShellExecute = false; start.RedirectStandardOutput = true; using (Process process = Process.Start(start)) { using (StreamReader reader = process.StandardOutput) { string result = reader.ReadToEnd(); Console.Write(result); } } } public static double CalculateSimilarity(string s1, string s2) { int n = s1.Length; int m = s2.Length; int[,] d = new int[n + 1, m + 1]; for (int i = 0; i <= n; i++) { d[i, 0] = i; } for (int j = 0; j <= m; j++) { d[0, j] = j; } for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { int cost = (s1[i - 1] == s2[j - 1]) ? 0 : 1; d[i, j] = Math.Min(Math.Min(d[i - 1, j] + 1, d[i, j - 1] + 1), d[i - 1, j - 1] + cost); } } return (1.0 - ((double)d[n, m] / Math.Max(s1.Length, s2.Length))) * 100; } public static double AreSentencesSimilar(string sentence1, string sentence2) { // double threshold = 70; // 设置一个阈值,超过这个百分比则认为是相同的句子 double similarity = CalculateSimilarity(sentence1, sentence2); return similarity ; } } }