|
@@ -8,136 +8,53 @@ namespace Yuuna
|
|
|
using Yuuna.Recognition.Speech;
|
|
|
using System.Threading.Tasks;
|
|
|
using System.Reflection;
|
|
|
- using Yuuna.Contracts.Interaction;
|
|
|
- using Yuuna.TextSegmention;
|
|
|
- using System.Diagnostics;
|
|
|
- using Microsoft.AspNetCore;
|
|
|
- using Microsoft.AspNetCore.Hosting;
|
|
|
- using Microsoft.Extensions.DependencyInjection;
|
|
|
- using Microsoft.AspNetCore.Builder;
|
|
|
+ using System.Diagnostics;
|
|
|
using Microsoft.AspNetCore.Routing;
|
|
|
- using Microsoft.Extensions.Hosting;
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
+ using Yuuna.Contracts.Optimization;
|
|
|
+ using Yuuna.Interaction.AspNetCore;
|
|
|
+ using RestSharp;
|
|
|
+ using Yuuna.TextSegmention;
|
|
|
+ using Yuuna.Contracts.Interaction;
|
|
|
|
|
|
- namespace Controllers
|
|
|
- {
|
|
|
- public class Yuuna
|
|
|
+ internal class EntryPoint
|
|
|
+ {
|
|
|
+ public static async Task Main(string[] args)
|
|
|
{
|
|
|
- public class Input
|
|
|
- {
|
|
|
- public string Text { get; set; }
|
|
|
- }
|
|
|
-
|
|
|
- public class Output
|
|
|
- {
|
|
|
- public Output(bool success, string message, Mood mood, string text)
|
|
|
- {
|
|
|
- this.Success = success;
|
|
|
- this.Message = message;
|
|
|
- this.Mood = mood.Name;
|
|
|
- this.Text = text;
|
|
|
- }
|
|
|
- public bool Success { get; }
|
|
|
- public string Message { get; }
|
|
|
- public string Mood { get; }
|
|
|
- public string Text { get; }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- [ApiController]
|
|
|
- [Route("/")]
|
|
|
- //[Route("[controller]")]
|
|
|
- public class YuunaController : ControllerBase
|
|
|
- {
|
|
|
-
|
|
|
- public YuunaController( Actor actor)
|
|
|
- {
|
|
|
- this._actor = actor;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- private readonly Actor _actor;
|
|
|
-
|
|
|
- [HttpGet, HttpPost]
|
|
|
- public Yuuna.Output Post([FromBody]Yuuna.Input text)
|
|
|
+ //await WebHost.RunAsync();
|
|
|
+ var actor = new Actor(new JiebaTextSegmenter(), new Response[]
|
|
|
{
|
|
|
- return new Yuuna.Output(this._actor.Accept(text.Text, out var r), r.Message, r.Mood, text.Text);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- public class Startup
|
|
|
- {
|
|
|
- public Startup()
|
|
|
- {
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- // This method gets called by the runtime. Use this method to add services to the container.
|
|
|
- public void ConfigureServices(IServiceCollection services)
|
|
|
- {
|
|
|
- services.AddSingleton(new Actor(new JiebaTextSegmenter(), new Response[]
|
|
|
- {
|
|
|
(Moods.Sad, "我不清楚你想做什麼 OvQ"),
|
|
|
(Moods.Sad, "我不懂你想幹嘛 QAQ"),
|
|
|
(Moods.Sad, "我不知道你想幹嘛 OHQ"),
|
|
|
- }));
|
|
|
- services.AddControllers();
|
|
|
- }
|
|
|
+ }, new Strategy(), ModuleManager.Instance.Modules);
|
|
|
|
|
|
- // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
|
|
- public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
|
|
- {
|
|
|
- if (env.IsDevelopment())
|
|
|
+ while (true)
|
|
|
{
|
|
|
- app.UseDeveloperExceptionPage();
|
|
|
- }
|
|
|
-
|
|
|
- //app.UseHttpsRedirection();
|
|
|
-
|
|
|
- app.UseRouting();
|
|
|
-
|
|
|
- app.UseEndpoints(endpoints =>
|
|
|
- {
|
|
|
- endpoints.MapControllers();
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
- internal class EntryPoint
|
|
|
- {
|
|
|
- public static void Main(string[] args)
|
|
|
- {
|
|
|
- Host.CreateDefaultBuilder(args)
|
|
|
- .ConfigureWebHostDefaults(webBuilder =>
|
|
|
+ Console.Write("Me: ");
|
|
|
+ if (actor.Accept(Console.ReadLine(), out var response))
|
|
|
{
|
|
|
- webBuilder.UseUrls("http://0.0.0.0:5000");
|
|
|
- webBuilder.UseStartup<Startup>();
|
|
|
- })
|
|
|
- .Build()
|
|
|
- .Run();
|
|
|
+ Console.WriteLine("Bot: " + response.Message);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Console.CursorTop--;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- //var actor = new Actor(new JiebaTextSegmenter(), new Response[]
|
|
|
+ //while (true)
|
|
|
//{
|
|
|
- // (Moods.Sad, "我不清楚你想做什麼 OvQ"),
|
|
|
- // (Moods.Sad, "我不懂你想幹嘛 QAQ"),
|
|
|
- // (Moods.Sad, "我不知道你想幹嘛 OHQ"),
|
|
|
- //});
|
|
|
+ // var client = new RestClient("http://api.yuuna-project.com:5000/");
|
|
|
+ // client.Timeout = -1;
|
|
|
+ // var request = new RestRequest(Method.POST);
|
|
|
+ // request.AddHeader("Content-Type", "application/json");
|
|
|
+ // request.AddParameter("application/json", "{\n \"text\": \""+Console.ReadLine()+"\"\n}", ParameterType.RequestBody);
|
|
|
+ // var response = client.Execute(request);
|
|
|
+ // Console.WriteLine("Bot: " + response.Content);
|
|
|
+ //}
|
|
|
|
|
|
- //while (true)
|
|
|
- //{
|
|
|
- // Console.Write("Me: ");
|
|
|
- // if (actor.Accept(Console.ReadLine(), out var response))
|
|
|
- // {
|
|
|
- // Console.WriteLine("Bot: " + response.Message);
|
|
|
- // }
|
|
|
- // else
|
|
|
- // {
|
|
|
- // Console.CursorTop --;
|
|
|
- // }
|
|
|
- //}
|
|
|
-
|
|
|
-
|
|
|
//var canResponses = new Response[]
|
|
|
//{
|
|
|
// (Moods.Sad, "我不清楚你想做什麼 OvQ"),
|
|
@@ -190,7 +107,7 @@ namespace Yuuna
|
|
|
// case AlternativeStatus.Condition:
|
|
|
// {
|
|
|
// var sb = new StringBuilder();
|
|
|
-
|
|
|
+
|
|
|
// sb.Append("你是想要");
|
|
|
|
|
|
// foreach (var g in alternative.Matches[0].Pattern.ToImmutable())
|
|
@@ -203,6 +120,8 @@ namespace Yuuna
|
|
|
|
|
|
// text = interactor.Accept();
|
|
|
|
|
|
+
|
|
|
+
|
|
|
// foreach (var antonym in antonyms)
|
|
|
// {
|
|
|
// if (antonym.Judge(text, out var type))
|
|
@@ -290,7 +209,7 @@ namespace Yuuna
|
|
|
// break;
|
|
|
// }
|
|
|
// }
|
|
|
-
|
|
|
+
|
|
|
// interactor.OnReceive(canResponses.RandomTakeOne());
|
|
|
|
|
|
// Leave:
|
|
@@ -311,6 +230,7 @@ namespace Yuuna
|
|
|
//}
|
|
|
//goto LOOP;
|
|
|
|
|
|
+
|
|
|
//try
|
|
|
//{Send("開燈");
|
|
|
// var stt = SpeechRecognizer.Create("secret.json");
|
|
@@ -344,117 +264,5 @@ namespace Yuuna
|
|
|
// Console.ReadKey();
|
|
|
//}
|
|
|
}
|
|
|
-
|
|
|
- public static void Send(string text)
|
|
|
- {
|
|
|
-
|
|
|
-
|
|
|
- //Console.WriteLine("我: " + text);
|
|
|
- //var cutted = segmenter.Cut(text);
|
|
|
- //Console.WriteLine($"來自分詞器 {segmenter.Name} 的分詞結果: [ {string.Join(", ", cutted)} ]");
|
|
|
-
|
|
|
- //var alternative = plan.FindBest(allPlugins.Select(x=>x.PatternSet).ToArray(), cutted);
|
|
|
- //switch (alternative.Status)
|
|
|
- //{
|
|
|
- // // 罐頭回應
|
|
|
- // case Status.Invalid:
|
|
|
- // view.OnResponsed(s_canResponses.RandomTakeOne());
|
|
|
- // break;
|
|
|
-
|
|
|
- // case Status.Optimal:
|
|
|
- // {
|
|
|
- // var single = alternative.Matches[0];
|
|
|
- // single.Pattern.Owner.Patterns.TryGet(single.Pattern, out var bag);
|
|
|
- // var r = bag.Invoke(single);
|
|
|
- // view.OnResponsed(r);
|
|
|
- // }
|
|
|
- // break;
|
|
|
-
|
|
|
- // case Status.Condition:
|
|
|
- // {
|
|
|
- // Console.WriteLine("proposition");
|
|
|
- // Console.Write("你是想要");
|
|
|
- // foreach (var matched in alternative.Matches[0].SequentialMatches)
|
|
|
- // {
|
|
|
- // Console.Write(matched.ToImmutable().RandomTakeOne());
|
|
|
- // }
|
|
|
- // foreach (var missing in alternative.Matches[0].Missing)
|
|
|
- // {
|
|
|
- // foreach (var unmatch in missing.ToImmutable())
|
|
|
- // {
|
|
|
- // Console.Write(unmatch.ToImmutable().RandomTakeOne());
|
|
|
- // }
|
|
|
- // }
|
|
|
- // Console.WriteLine("嗎?");
|
|
|
- // Console.ReadLine()
|
|
|
- // }
|
|
|
- // break;
|
|
|
-
|
|
|
- // case Status.Proposition:
|
|
|
- // Console.WriteLine("proposition");
|
|
|
- // break;
|
|
|
-
|
|
|
- // case Status.Paradox:
|
|
|
- // Console.WriteLine("paradox");
|
|
|
- // break;
|
|
|
-
|
|
|
- // case Status.NoModuleInstalled:
|
|
|
- // Console.WriteLine("noModuleInstalled");
|
|
|
- // Console.WriteLine("無效的模組");
|
|
|
- // break;
|
|
|
-
|
|
|
- // default:
|
|
|
- // throw new InvalidOperationException();
|
|
|
- //}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- //var list = new List<IScore>();
|
|
|
- //foreach (var p in allPlugins)
|
|
|
- // list.AddRange(p.Evaluate(cutted));
|
|
|
- //list.Sort(ScoreComparer.Default);
|
|
|
-
|
|
|
- //var sb = new StringBuilder("Bot: ");
|
|
|
- //var best = list.LastOrDefault();
|
|
|
- //if (best is null)
|
|
|
- // sb.Append("我不懂你的意思");
|
|
|
- //else if (best.IsCompacted)
|
|
|
- //{
|
|
|
- // var resp = best.Owner.SelectBest(best).Invoke(best);
|
|
|
- // Console.WriteLine(resp.Mood.ToString());
|
|
|
- // sb.Append(resp.Message);
|
|
|
- //}
|
|
|
- //else
|
|
|
- //{
|
|
|
- // var choices = list.Where(s => s.Missing.Count <= 1).ToImmutableArray();
|
|
|
- // switch (choices.Length)
|
|
|
- // {
|
|
|
- // case 1:
|
|
|
- // {
|
|
|
- // Console.WriteLine("#1");
|
|
|
- // sb.Append("你" + new[] { "是想", "想要" }.RandomTakeOne() + " ");
|
|
|
- // sb.Append(choices.Select(x => x.Pattern.ToImmutable().Aggregate(string.Empty, (s, g) => s += g.ToImmutable().RandomTakeOne().ToImmutable().RandomTakeOne())));
|
|
|
- // sb.Append(" 嗎?");
|
|
|
- // }
|
|
|
- // break;
|
|
|
-
|
|
|
- // case 2:
|
|
|
- // {
|
|
|
- // Console.WriteLine("#2");
|
|
|
- // sb.Append("你" + new[] { "是想", "想要" }.RandomTakeOne() + " ");
|
|
|
- // sb.AppendJoin(" 還是 ", choices.Select(x => x.Pattern.ToImmutable().Aggregate(string.Empty, (s, g) => s += g.ToImmutable().RandomTakeOne().ToImmutable().RandomTakeOne())));
|
|
|
- // sb.Append(" ?");
|
|
|
- // }
|
|
|
- // break;
|
|
|
-
|
|
|
- // default:
|
|
|
- // Console.WriteLine("#n");
|
|
|
- // sb.Append("我不太清楚你想做什麼");
|
|
|
- // break;
|
|
|
- // }
|
|
|
- //}
|
|
|
-
|
|
|
- //Console.WriteLine(sb);
|
|
|
- }
|
|
|
}
|
|
|
}
|