Quellcode durchsuchen

修正 PoC 先行版的錯誤

0x0001F36D vor 5 Jahren
Ursprung
Commit
4deda75c36

+ 3 - 1
src/Yuuna.Contracts/Patterns/Internal/PatternFactory.cs

@@ -7,7 +7,7 @@ namespace Yuuna.Contracts.Patterns
     using System.Collections.Concurrent;
     using System.Collections.Generic;
     using System.Collections.Immutable;
-
+    using System.Diagnostics;
     using Yuuna.Common.Artisan.Cascade;
     using Yuuna.Contracts.Modules;
     using Yuuna.Contracts.Semantics;
@@ -53,6 +53,8 @@ namespace Yuuna.Contracts.Patterns
                 Invoke = session.Dequeue() as Invoke,
                 Incomplete = session.Dequeue() as Incomplete,
             };
+
+            Debug.WriteLine("#" + string.Join("::", ge.Pattern.SequentialKeys));
             this._list.TryAdd(ge.Pattern, ge);
         }
     }

+ 60 - 26
src/Yuuna/EntryPoint.cs

@@ -26,7 +26,7 @@ namespace Yuuna
             Unknown = default,
             Positive,
             Negative,
-            Question
+            //Question
         }
 
         private struct Word
@@ -46,7 +46,12 @@ namespace Yuuna
 
         public Antonym(string positive, string negative, string question)
         {
-            this._words = new[] { new Word(positive, TypeKinds.Positive), new Word(negative, TypeKinds.Negative), new Word(question, TypeKinds.Question) };
+            this._words = new[] 
+            { 
+                new Word(positive, TypeKinds.Positive), 
+                new Word(negative, TypeKinds.Negative),
+                //new Word(question, TypeKinds.Question)
+            };
             Array.Sort(this._words, new Comparison<Word>((x, y) => y.Priority - x.Priority)); 
         }
 
@@ -64,7 +69,7 @@ namespace Yuuna
             foreach (var w in this._words)
             {
                 if(sentence.Contains(w.Value))
-                {
+                { 
                     condition = w.Condition;
                     return true;
                 }
@@ -83,9 +88,18 @@ namespace Yuuna
 
     public sealed class ConsoleBotInteract : IInteractiveView
     {
+        public string Name { get; }
+
+        public ConsoleBotInteract(string name)
+        {
+            if (string.IsNullOrWhiteSpace(name))
+                throw new ArgumentException( "", nameof(name));
+            this.Name = name;
+        }
+
         public void OnReceive(Response response)
         { 
-            Console.WriteLine("Bot: " + response.Message);
+            Console.WriteLine(this.Name + ": " + response.Message);
         }
 
         public string Accept()
@@ -99,7 +113,7 @@ namespace Yuuna
     internal class EntryPoint
     {
         public static void Main(string[] args)
-        {
+        { 
             var canResponses = new Response[]
             {
                 (Moods.Sad, "我不清楚你想做什麼 OvQ"),
@@ -111,10 +125,10 @@ namespace Yuuna
             {
                 new Antonym("是", "不是"),
                 new Antonym("對", "不對"),
-                new Antonym("是", "否"),
+                new Antonym("是", "否"), 
             };
 
-            IInteractiveView interactor = new ConsoleBotInteract();
+            IInteractiveView interactor = new ConsoleBotInteract("悠");
             ITextSegmenter segmenter = new JiebaTextSegmenter();
             IStrategy plan = new DefaultStrategy();
 
@@ -152,6 +166,7 @@ namespace Yuuna
                 case Status.Condition:
                     {
                         var sb = new StringBuilder();
+                        
                         sb.Append("你是想要"); 
 
                         foreach (var g in alternative.Matches[0].Pattern.ToImmutable())
@@ -166,13 +181,16 @@ namespace Yuuna
 
                         foreach (var antonym in antonyms)
                         {
-                            if(antonym.Judge(text, out var type) && type.Equals(Antonym.TypeKinds.Positive))
+                            if (antonym.Judge(text, out var type))
                             {
-                                var single = alternative.Matches[0];
-                                single.Pattern.Owner.Patterns.TryGet(single.Pattern, out var bag);
-                                var r = bag.Invoke(single);
-                                interactor.OnReceive(r);
-                                goto Leave;
+                                if (type.Equals(Antonym.TypeKinds.Positive))
+                                {
+                                    var single = alternative.Matches[0];
+                                    single.Pattern.Owner.Patterns.TryGet(single.Pattern, out var bag);
+                                    var r = bag.Invoke(single);
+                                    interactor.OnReceive(r);
+                                    goto Leave;
+                                }
                             }
                         }
 
@@ -196,18 +214,26 @@ namespace Yuuna
                         sb.Append("嗎?");
                         interactor.OnReceive(sb.ToString());
 
-                        text = interactor.Accept();
-
+                        text = interactor.Accept(); 
                         foreach (var antonym in antonyms)
                         {
-                            if (antonym.Judge(text, out var type) && type.Equals(Antonym.TypeKinds.Positive))
+                            if (antonym.Judge(text, out var type))
                             {
-                                current.Pattern.Owner.Patterns.TryGet(current.Pattern, out var bag);
-                                var r = bag.Invoke(current);
-                                interactor.OnReceive(r);
-                                goto Leave;
+                                if (type.Equals(Antonym.TypeKinds.Positive))
+                                {
+                                    current.Pattern.Owner.Patterns.TryGet(current.Pattern, out var bag);
+                                    var r = bag.Invoke(current);
+                                    interactor.OnReceive(r);
+                                    goto Leave;
+                                }
+                                else
+                                    break;
                             }
+                            else
+                                goto Unknown;
                         }
+                         
+
 
                         sb.Clear();
 
@@ -228,15 +254,23 @@ namespace Yuuna
 
                         foreach (var antonym in antonyms)
                         {
-                            if (antonym.Judge(text, out var type) && type.Equals(Antonym.TypeKinds.Positive))
-                            { 
-                                current.Pattern.Owner.Patterns.TryGet(current.Pattern, out var bag);
-                                var r = bag.Invoke(current);
-                                interactor.OnReceive(r);
-                                goto Leave;
+                            if (antonym.Judge(text, out var type))
+                            {
+                                if (type.Equals(Antonym.TypeKinds.Positive))
+                                {
+                                    current.Pattern.Owner.Patterns.TryGet(current.Pattern, out var bag);
+                                    var r = bag.Invoke(current);
+                                    interactor.OnReceive(r);
+                                    goto Leave;
+                                }
+                                else
+                                    break;
                             }
+                            else
+                                goto Unknown;
                         }
 
+                        Unknown:
                         interactor.OnReceive(canResponses.RandomTakeOne()); 
 
                         Leave:

+ 1 - 0
src/Yuuna/TextSegmention/JiebaSegmenter.cs

@@ -55,6 +55,7 @@ namespace Yuuna.TextSegmention
 
             foreach (var name in manager.Keys)
             {
+
                 this.InternalLog("name: " + name);
                 foreach (var synonym in manager[name].ToImmutable())
                 {