|
|
@@ -12,6 +12,7 @@ namespace Yuuna.Contracts.Plugins
|
|
|
using Yuuna.Contracts.Patterns;
|
|
|
using Yuuna.Contracts.Semantics;
|
|
|
using Yuuna.Contracts.TextSegmention;
|
|
|
+ using Yuuna.Contracts.Utilities;
|
|
|
|
|
|
public sealed class Fake : PluginBase
|
|
|
{
|
|
|
@@ -24,7 +25,7 @@ namespace Yuuna.Contracts.Plugins
|
|
|
|
|
|
p.Build(g["open"], g["door"]).OnInvoke(score =>
|
|
|
{
|
|
|
- var DOOR = new { IS_OPENED = new[] { true, false, true, false }.Random() };
|
|
|
+ var DOOR = new { IS_OPENED = new[] { true, false, true, false }.RandomTakeOne() };
|
|
|
// 開門
|
|
|
if (!DOOR.IS_OPENED)
|
|
|
return (Moods.Happy, "已經開好門囉 <3");
|
|
|
@@ -34,7 +35,7 @@ namespace Yuuna.Contracts.Plugins
|
|
|
|
|
|
p.Build(g["open"], g["light"]).OnInvoke(score =>
|
|
|
{
|
|
|
- var LIGHT = new { IS_OPENED = new[] { true, false,true,false }.Random() };
|
|
|
+ var LIGHT = new { IS_OPENED = new[] { true, false,true,false }.RandomTakeOne() };
|
|
|
// 開門
|
|
|
if (!LIGHT.IS_OPENED)
|
|
|
return (Moods.Happy, "已經開好燈囉 <3");
|
|
|
@@ -54,25 +55,6 @@ namespace Yuuna.Contracts.Plugins
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static class RandomHelper
|
|
|
- {
|
|
|
- public static T Random<T>(this IEnumerable<T> collection)
|
|
|
- {
|
|
|
- if (collection == null)
|
|
|
- throw new ArgumentNullException(nameof(collection));
|
|
|
- var list = collection.ToArray();
|
|
|
- if (list.Length == 0)
|
|
|
- return default(T);
|
|
|
- else if (list.Length == 1)
|
|
|
- return list[0];
|
|
|
- else
|
|
|
- {
|
|
|
- var rnd = new System.Random(Guid.NewGuid().GetHashCode());
|
|
|
- var index = rnd.Next(0, list.Length);
|
|
|
- return list[index];
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
public class PluginHub
|
|
|
{
|
|
|
@@ -87,9 +69,7 @@ namespace Yuuna.Contracts.Plugins
|
|
|
{
|
|
|
// Send("打開門");
|
|
|
// Send("開燈");
|
|
|
- Send("打開燈");
|
|
|
-
|
|
|
-
|
|
|
+ // Send("打開燈");
|
|
|
}
|
|
|
|
|
|
public static void Send(string text)
|
|
|
@@ -128,8 +108,8 @@ namespace Yuuna.Contracts.Plugins
|
|
|
{
|
|
|
case 1:
|
|
|
{
|
|
|
- sb.Append("你" + new[] { "是想", "想要" }.Random() + " ");
|
|
|
- sb.Append(choices.Select(x => x.Contrast.ToImmutable().Aggregate(string.Empty, (s, g) => s += g.ToImmutable().Random().ToImmutable().Random())));
|
|
|
+ sb.Append("你" + new[] { "是想", "想要" }.RandomTakeOne() + " ");
|
|
|
+ sb.Append(choices.Select(x => x.Contrast.ToImmutable().Aggregate(string.Empty, (s, g) => s += g.ToImmutable().RandomTakeOne().ToImmutable().RandomTakeOne())));
|
|
|
sb.Append(" 嗎?");
|
|
|
}
|
|
|
break;
|
|
|
@@ -137,8 +117,8 @@ namespace Yuuna.Contracts.Plugins
|
|
|
|
|
|
case 2:
|
|
|
{
|
|
|
- sb.Append("你" + new[] { "是想", "想要" }.Random() + " ");
|
|
|
- sb.AppendJoin(" 還是 ", choices.Select(x => x.Contrast.ToImmutable().Aggregate(string.Empty, (s, g) => s += g.ToImmutable().Random().ToImmutable().Random())));
|
|
|
+ sb.Append("你" + new[] { "是想", "想要" }.RandomTakeOne() + " ");
|
|
|
+ sb.AppendJoin(" 還是 ", choices.Select(x => x.Contrast.ToImmutable().Aggregate(string.Empty, (s, g) => s += g.ToImmutable().RandomTakeOne().ToImmutable().RandomTakeOne())));
|
|
|
sb.Append(" ?");
|
|
|
}
|
|
|
break;
|
|
|
@@ -152,16 +132,6 @@ namespace Yuuna.Contracts.Plugins
|
|
|
|
|
|
Console.WriteLine(sb);
|
|
|
|
|
|
- //foreach (var topmost in list.Where(x=>x.IsCompacted))
|
|
|
- //{
|
|
|
- // Console.WriteLine(topmost.IsCompacted);
|
|
|
- // Console.WriteLine("coverage: " + topmost.Coverage * 100.0 +" %");
|
|
|
- // Console.WriteLine("missing: "+topmost.Missing.Count);
|
|
|
-
|
|
|
- // Console.WriteLine(string.Join(",", topmost.Contrast.SequentialKeys));
|
|
|
- // Console.WriteLine();
|
|
|
- //}
|
|
|
- //Console.ReadKey();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -177,10 +147,19 @@ namespace Yuuna.Contracts.Plugins
|
|
|
this._groupManager = new GroupManager();
|
|
|
}
|
|
|
|
|
|
+ protected virtual void PreInitialize(ITextSegmenter segmenter)
|
|
|
+ {
|
|
|
+ }
|
|
|
+
|
|
|
internal void Initialize(ITextSegmenter textSegmenter)
|
|
|
{
|
|
|
+ this.PreInitialize(textSegmenter);
|
|
|
this.BuildPatterns(this._groupManager, this._grammarSet);
|
|
|
textSegmenter.Load(this._groupManager);
|
|
|
+ this.OnInitialize();
|
|
|
+ }
|
|
|
+ protected virtual void OnInitialize()
|
|
|
+ {
|
|
|
}
|
|
|
|
|
|
protected abstract void BuildPatterns(IGroupManager groupManager, IPatternBuilder grammarBuilder);
|