소스 검색

Fuck yeah, Let's celebrate this shit can be a human.

0x0001F36D 5 년 전
부모
커밋
35cd06021b

+ 1 - 1
src/Yuuna.Contracts.Test/Yuuna.Contracts.Test.csproj

@@ -21,7 +21,7 @@
   </ItemGroup>
 
   <Target Name="PostBuild" AfterTargets="PostBuildEvent">
-    <Exec Command=":: copy $(TargetPath) $(SolutionDir)..\Yuuna\bin\Debug\netcoreapp3.0\modules\Test" />
+    <Exec Command="mkdir $(SolutionDir)..\Yuuna\bin\Debug\netcoreapp3.0\modules\Test&#xD;&#xA;copy $(TargetPath) $(SolutionDir)..\Yuuna\bin\Debug\netcoreapp3.0\modules\Test" />
   </Target>
 
 </Project>

+ 56 - 0
src/Yuuna.Contracts/Optimization/Alternative.cs

@@ -0,0 +1,56 @@
+// Author: Orlys
+// Github: https://github.com/Orlys
+
+namespace Yuuna.Contracts.Optimization
+{
+    using System.Collections.Immutable;
+    using System.Linq;
+
+    public class Alternative
+    {
+        public AlternativeStatus Status { get; }
+        public IImmutableList<Match> Matches { get; }
+
+        public Alternative(IImmutableList<Match> matches)
+        {
+            var count = matches?.Count ?? 0;
+            if (count.Equals(1))
+            {
+                var single = matches[0].Missing.Count;
+                if (single.Equals(0))
+                {
+                    this.Status = AlternativeStatus.Optimal;  // 最佳解
+
+                }
+                else if (single.Equals(1))
+                {
+                    this.Status = AlternativeStatus.Condition;// 近似解(缺一組條件,詢問使用者) 
+                }
+            }
+            else if (count.Equals(2))
+            {
+                if (matches.All(x => x.Missing.Count == 0))
+                {
+                    this.Status = AlternativeStatus.Paradox;// 內部錯誤(多個意圖重複)
+                }
+                else if (matches.All(x => x.Missing.Count == 1))
+                {
+                    this.Status = AlternativeStatus.Proposition;// 兩個近似解,詢問使用者(二選一 + 離開情境)
+                }
+            } 
+            //else if (count.Equals(0))
+            //{
+            //    // 無有效模組
+            //    this.Status = AlternativeStatus.NoModuleInstalled;
+            //}
+            else
+            {
+                // 不採用
+                this.Status = AlternativeStatus.Invalid;
+            }
+
+            this.Matches = matches;
+        }
+         
+    }
+}

+ 34 - 0
src/Yuuna.Contracts/Optimization/AlternativeStatus.cs

@@ -0,0 +1,34 @@
+// Author: Orlys
+// Github: https://github.com/Orlys
+
+namespace Yuuna.Contracts.Optimization
+{
+    public enum AlternativeStatus
+    {
+        /// <summary>
+        /// 無有效解。
+        /// </summary>
+        Invalid,
+        /// <summary>
+        /// 最佳解。表示與模式(Pattern)完全符合。
+        /// </summary>
+        Optimal,
+        /// <summary>
+        /// 條件式。表示缺少一個群組(Group)。
+        /// </summary>
+        Condition,
+        /// <summary>
+        /// 命題。表示具有兩個條件式(<see cref="Condition"/>)。
+        /// </summary>
+        Proposition,
+        /// <summary>
+        /// 悖論。表示具有兩個(含)以上的最佳解(<see cref="Optimal"/>),這實際上屬於模組設計上的問題。
+        /// </summary>
+        Paradox,
+
+        ///// <summary>
+        ///// 沒有已安裝的模組。
+        ///// </summary>
+        //NoModuleInstalled = -1,
+    }
+}

+ 8 - 111
src/Yuuna.Contracts/Optimization/DefaultStrategy.cs

@@ -12,84 +12,7 @@ namespace Yuuna.Contracts.Optimization
     using Yuuna.Contracts.Patterns;
     using Yuuna.Contracts.Modules;
     using Yuuna.Contracts.Semantics;
-    using System.Linq;
-
-    public enum Status
-    {
-        /// <summary>
-        /// 無有效解。
-        /// </summary>
-        Invalid,
-        /// <summary>
-        /// 最佳解。表示與模式(Pattern)完全符合。
-        /// </summary>
-        Optimal,
-        /// <summary>
-        /// 條件式。表示缺少一個群組(Group)。
-        /// </summary>
-        Condition,
-        /// <summary>
-        /// 命題。表示具有兩個條件式(<see cref="Condition"/>)。
-        /// </summary>
-        Proposition,
-        /// <summary>
-        /// 悖論。表示具有兩個(含)以上的最佳解(<see cref="Optimal"/>),這實際上屬於模組設計上的問題。
-        /// </summary>
-        Paradox,
-
-        /// <summary>
-        /// 沒有已安裝的模組。
-        /// </summary>
-        NoModuleInstalled = -1,
-    }
-
-    public class Alternative
-    {
-        public Status Status { get; }
-        public IImmutableList<Match> Matches { get; }
-
-        public Alternative(IImmutableList<Match> matches)
-        {
-            var count = matches?.Count ?? 0;
-            if (count.Equals(1))
-            {
-                var single = matches[0].Missing.Count;
-                if (single.Equals(0))
-                {
-                    this.Status = Status.Optimal;  // 最佳解
-
-                }
-                else if (single.Equals(1))
-                {
-                    this.Status = Status.Condition;// 近似解(缺一組條件,詢問使用者) 
-                }
-            }
-            else if (count.Equals(2))
-            {
-                if (matches.All(x => x.Missing.Count == 0))
-                {
-                    this.Status = Status.Paradox;// 內部錯誤(多個意圖重複)
-                }
-                else if (matches.All(x => x.Missing.Count == 1))
-                {
-                    this.Status = Status.Proposition;// 兩個近似解,詢問使用者(二選一 + 離開情境)
-                }
-            } 
-            else if (count.Equals(0))
-            {
-                // 無有效模組
-                this.Status = Status.NoModuleInstalled;
-            }
-            else
-            {
-                // 不採用
-                this.Status = Status.Invalid;
-            }
-
-            this.Matches = matches;
-        }
-         
-    }
+    using System.Diagnostics;
 
     public class DefaultStrategy : IStrategy
     {
@@ -138,12 +61,16 @@ namespace Yuuna.Contracts.Optimization
                 }
             }
 
+            sta.Remove(0); //過濾掉完全沒相符的資料以免影響結果
+
 
             var weight = double.MinValue;
             var bestSelect = default(List<Match>);
             foreach (var s in sta)
             {
-                var y = -( Math.Tanh(Math.Pow(Math.E, (s.Value.Count) / (double)-(matches.Count * s.Key))));
+                var y =  Math.Tanh(Math.Pow(Math.E, (s.Value.Count) / (double)-(matches.Count *  s.Key)));
+
+                Debug.WriteLine((s.Key, y));
                 if (y > weight)
                 {
                     weight = y;
@@ -151,38 +78,8 @@ namespace Yuuna.Contracts.Optimization
                 }
             }
 
-
-            return new Alternative(bestSelect?.ToImmutableArray());
-
-
-
-            //var tuple = new List<Tuple<Match, double>>();
-            //foreach (var s in sta)
-            //{
-            //    var x = (s.Value) / (double)-(matches.Count * s.Key.SequentialMatches.Count);
-            //    var y = Math.Tanh(Math.Pow(Math.E, x));
-            //    tuple.Add(Tuple.Create(s.Key, y));
-            //}
-            //var bestSelect = tuple.OrderByDescending(x => x.Item2).FirstOrDefault();
-            //return bestSelect?.Item1;
-
-
-            //var hold = double.MinValue;
-            //var bestSelect = default(Match);
-            //foreach (var s in sta)
-            //{
-            //    var y = Math.Tanh(Math.Pow(Math.E, (s.Value) / (double)-(matches.Count * s.Key.Pattern.Count))); 
-            //    if (y > hold)
-            //    {
-            //        hold = y;
-            //        bestSelect = s.Key;
-            //    }
-            //}
-
-            //if (bestSelect.SequentialMatches.Count == 0)
-            //    return null;
-
-            //return bestSelect;
+            var a = new Alternative(bestSelect?.ToImmutableArray()); 
+            return a;
         }
 
         /// <summary>

+ 17 - 14
src/Yuuna/EntryPoint.cs

@@ -77,6 +77,8 @@ namespace Yuuna
             condition = default;
             return false;
         }
+
+        public override string ToString() => (this._words[0].Value + " / " + this._words[1].Value).ToString();
     }
 
 
@@ -114,8 +116,6 @@ namespace Yuuna
     {
         public static void Main(string[] args)
         { 
-             
-
             var canResponses = new Response[]
             {
                 (Moods.Sad, "我不清楚你想做什麼 OvQ"),
@@ -152,11 +152,11 @@ namespace Yuuna
             switch (alternative.Status)
             {
                 // 罐頭回應
-                case Status.Invalid:
+                case AlternativeStatus.Invalid:
                     interactor.OnReceive(canResponses.RandomTakeOne());
                     break;
 
-                case Status.Optimal:
+                case AlternativeStatus.Optimal:
                     {
                         var single = alternative.Matches[0];
                         single.Pattern.Owner.Patterns.TryGet(single.Pattern, out var bag);
@@ -165,7 +165,7 @@ namespace Yuuna
                         break;
                     }
 
-                case Status.Condition:
+                case AlternativeStatus.Condition:
                     {
                         var sb = new StringBuilder();
                         
@@ -181,8 +181,13 @@ namespace Yuuna
 
                         text = interactor.Accept();
 
+                        //我: 開
+                        //悠: 你是想要開房門嗎?
+                        //我: 對
+                        //悠: 我不知道你想幹嘛 OHQ
                         foreach (var antonym in antonyms)
                         {
+                            Console.WriteLine("$" + antonym);
                             if (antonym.Judge(text, out var type))
                             {
                                 if (type.Equals(Antonym.TypeKinds.Positive))
@@ -193,6 +198,8 @@ namespace Yuuna
                                     interactor.OnReceive(r);
                                     goto Leave;
                                 }
+                                else
+                                    break;
                             }
                         }
 
@@ -201,12 +208,8 @@ namespace Yuuna
                         break;
                     }
 
-                case Status.Proposition:
+                case AlternativeStatus.Proposition:
                     {
-                        //我: 開
-                        //悠: 你是想要開房門嗎?
-                        //我: 對
-                        //悠: 我不知道你想幹嘛 OHQ
 
                         var sb = new StringBuilder(); 
                         var current = alternative.Matches[0];
@@ -277,12 +280,12 @@ namespace Yuuna
                         break;
                     }
 
-                case Status.Paradox:
+                case AlternativeStatus.Paradox:
                     break;
 
-                case Status.NoModuleInstalled:
-                    interactor.OnReceive((Moods.Sad, "無效的模組"));
-                    break;
+                //case AlternativeStatus.NoModuleInstalled:
+                //    interactor.OnReceive((Moods.Sad, "無效的模組"));
+                //    break;
 
                 default:
                     throw new InvalidOperationException();

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

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