123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- 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<string>("Azure:Storage:ConnectionString"));
- builder.Services.AddAzureRedis(builder.Configuration.GetValue<string>("Azure:Redis:ConnectionString"));
- builder.Services.AddAzureCosmos(builder.Configuration.GetValue<string>("Azure:Cosmos:ConnectionString"));
- builder.Services.AddAzureServiceBus(builder.Configuration.GetValue<string>("Azure:ServiceBus:ConnectionString"));
- builder.Services.AddAzureSignalR(builder.Configuration.GetValue<string>("Azure:SignalR:ConnectionString"));
- builder.Services.AddSnowflakeId(Convert.ToInt64(builder.Configuration.GetValue<string>("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<string> standardAnswers = new List<string> { "apple", "banana", "cherry" };
- // 学生作答集合
- List<string> studentAnswers = new List<string> { "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<string> a = new List<string>() { "a", "d" };
- List<string> b = new List<string>() { "b", "a", "c" };
- var v = (a.All(item => b.Contains(item)));
- string c = "[\r\n 1\r\n]";
- List<int> d = c.ToObject<List<int>>();
- 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 ;
- }
- }
- }
|