diff --git a/Megrez.Tests/Megrez.Tests.csproj b/Megrez.Tests/Megrez.Tests.csproj index 9dc12cf..0cb65eb 100644 --- a/Megrez.Tests/Megrez.Tests.csproj +++ b/Megrez.Tests/Megrez.Tests.csproj @@ -4,7 +4,7 @@ net6.0 enable false - 1.2.6 + 1.2.7 diff --git a/Megrez.Tests/MegrezTests.cs b/Megrez.Tests/MegrezTests.cs index edfb188..e00d74e 100644 --- a/Megrez.Tests/MegrezTests.cs +++ b/Megrez.Tests/MegrezTests.cs @@ -118,9 +118,9 @@ public void TestInput() { theCompositor.DeleteReadingAtTheRearOfCursor(); theCompositor.DeleteReadingAtTheRearOfCursor(); theCompositor.DeleteReadingAtTheRearOfCursor(); - string expectedDumpDot = + string expectedDumpDOT = "digraph {\ngraph [ rankdir=LR ];\nBOS;\nBOS -> 高;\n高;\n高 -> 科;\n高 -> 科技;\nBOS -> 高科技;\n高科技;\n高科技 -> 工;\n高科技 -> 公司;\n科;\n科 -> 際;\n科 -> 濟公;\n科技;\n科技 -> 工;\n科技 -> 公司;\n際;\n際 -> 工;\n際 -> 公司;\n濟公;\n濟公 -> 斯;\n工;\n工 -> 斯;\n公司;\n公司 -> 的;\n斯;\n斯 -> 的;\n的;\n的 -> 年;\n的 -> 年終;\n年;\n年 -> 中;\n年終;\n年終 -> 獎;\n年終 -> 獎金;\n中;\n中 -> 獎;\n中 -> 獎金;\n獎;\n獎 -> 金;\n獎金;\n獎金 -> EOS;\n金;\n金 -> EOS;\nEOS;\n}\n"; - Assert.AreEqual(expectedDumpDot, theCompositor.Grid.DumpDot()); + Assert.AreEqual(expectedDumpDOT, theCompositor.Grid.DumpDOT()); } [Test] diff --git a/Megrez.sln b/Megrez.sln index 01fe007..c53f7c1 100644 --- a/Megrez.sln +++ b/Megrez.sln @@ -52,6 +52,6 @@ Global $0.DotNetNamingPolicy = $4 $4.DirectoryNamespaceAssociation = PrefixedHierarchical $0.StandardHeader = $5 - version = 1.2.6 + version = 1.2.7 EndGlobalSection EndGlobal diff --git a/Megrez/1_Compositor.cs b/Megrez/1_Compositor.cs index 6d99b3b..dd4c49b 100644 --- a/Megrez/1_Compositor.cs +++ b/Megrez/1_Compositor.cs @@ -157,7 +157,7 @@ public bool RemoveHeadReadings(int count) { /// 用以統計累計長詞的內部參數,請勿主動使用。 /// 用以統計累計長詞的內部參數,請勿主動使用。 /// 均有節點的節錨陣列。 - public List Walk(int location, double accumulatedScore = 0.0, string joinedPhrase = "", + public List Walk(int location = 0, double accumulatedScore = 0.0, string joinedPhrase = "", List? longPhrases = default(List)) { int newLocation = Grid.Width - Math.Abs(location); List result = ReverseWalk(newLocation, accumulatedScore, joinedPhrase, longPhrases); diff --git a/Megrez/2_Grid.cs b/Megrez/2_Grid.cs index c2adbc1..16df169 100644 --- a/Megrez/2_Grid.cs +++ b/Megrez/2_Grid.cs @@ -227,7 +227,7 @@ public void FixNodeSelectedCandidate(int location, string value, double overridi /// 生成用以交給 GraphViz 診斷的資料。 /// /// GraphViz 檔案內容,純文字。 - public string DumpDot() { + public string DumpDOT() { string strOutput = "digraph {\ngraph [ rankdir=LR ];\nBOS;\n"; for (int p = 0; p < _spans.Count; p++) { Span span = _spans[p]; diff --git a/Megrez/3_NodeAnchor.cs b/Megrez/3_NodeAnchor.cs index d5c78d7..a8881c7 100644 --- a/Megrez/3_NodeAnchor.cs +++ b/Megrez/3_NodeAnchor.cs @@ -60,6 +60,10 @@ public NodeAnchor(Node node, int location, int spanningLength) { /// 獲取用來比較的權重。 /// public double ScoreForSort => Node?.Score ?? 0.0; + /// + /// 將當前節錨的內容輸出為字串。 + /// + /// 當前節錨的內容輸出成的字串。 public override string ToString() { string stream = ""; stream += "{@(" + Location + "," + SpanningLength + "),"; diff --git a/Megrez/4_Node.cs b/Megrez/4_Node.cs index 1a3fe95..2888745 100644 --- a/Megrez/4_Node.cs +++ b/Megrez/4_Node.cs @@ -57,6 +57,10 @@ public class Node { /// 用來登記要施加給「『被標記為選中狀態』的候選字詞」的複寫權重的數值。 /// public const double ConSelectedCandidateScore = 99.0; + /// + /// 將當前節點的內容輸出為字串。 + /// + /// 當前節點的內容輸出成的字串。 public override string ToString() => $"(node,key:{Key},fixed:{(IsCandidateFixed ? "true" : "false")},selected:{_selectedUnigramIndex},{_unigrams})"; /// @@ -169,6 +173,11 @@ public double ScoreFor(string candidate) { } return result; } + /// + /// 判定兩個節點是否相等。 + /// + /// 用來比較的節點。 + /// 若相等,則返回 true。 public override bool Equals(object obj) { return obj is Node node && EqualityComparer>.Default.Equals(_unigrams, node._unigrams) && EqualityComparer>.Default.Equals(Candidates, node.Candidates) && @@ -179,6 +188,10 @@ public override bool Equals(object obj) { IsCandidateFixed == node.IsCandidateFixed && _selectedUnigramIndex == node._selectedUnigramIndex; } + /// + /// 將當前節點的內容輸出為雜湊資料。 + /// + /// 當前節錨的內容輸出成的雜湊資料。 public override int GetHashCode() { unchecked { return (int)BitConverter.ToInt64(Convert.FromBase64String(ToString()), 0); } } diff --git a/Megrez/6_Bigram.cs b/Megrez/6_Bigram.cs index 1272dc0..d240393 100644 --- a/Megrez/6_Bigram.cs +++ b/Megrez/6_Bigram.cs @@ -55,42 +55,88 @@ public Bigram(KeyValuePaired keyValuePreceded, KeyValuePaired keyValue, double s /// 權重。 /// public double Score { get; set; } - + /// + /// 判定兩個雙元圖是否相等。 + /// + /// 用來比較的雙元圖。 + /// 若相等,則返回 true。 public override bool Equals(object obj) => obj is Bigram bigram && EqualityComparer.Default.Equals(KeyValuePreceded, bigram.KeyValuePreceded) && EqualityComparer.Default.Equals(KeyValue, bigram.KeyValue) && Math.Abs(Score - bigram.Score) < 0.0000001f; + /// + /// 將當前物件的內容輸出為雜湊資料。 + /// + /// 當前物件的內容輸出成的雜湊資料。 public override int GetHashCode() => HashCode.Combine(KeyValuePreceded, KeyValue, Score); + /// + /// 將當前物件的內容輸出為字串。 + /// + /// 當前物件的內容輸出成的字串。 public override string ToString() => $"({KeyValuePreceded}|{KeyValue},{Score})"; - + /// + /// 判定兩個物件是否相等。 + /// + /// + /// + /// public static bool operator ==(Bigram lhs, Bigram rhs) { return lhs.KeyValuePreceded == rhs.KeyValuePreceded && lhs.KeyValue == rhs.KeyValue && Math.Abs(lhs.Score - rhs.Score) < 0.0000001f; } - + /// + /// 判定兩個物件是否相異。 + /// + /// + /// + /// public static bool operator !=(Bigram lhs, Bigram rhs) { return lhs.KeyValuePreceded != rhs.KeyValuePreceded || lhs.KeyValue != rhs.KeyValue || Math.Abs(lhs.Score - rhs.Score) > 0.0000001f; } + /// + /// + /// + /// + /// + /// public static bool operator<(Bigram lhs, Bigram rhs) { return lhs.KeyValuePreceded < rhs.KeyValuePreceded || lhs.KeyValue < rhs.KeyValue || lhs.KeyValue == rhs.KeyValue && lhs.Score < rhs.Score; } + /// + /// + /// + /// + /// + /// public static bool operator>(Bigram lhs, Bigram rhs) { return lhs.KeyValuePreceded > rhs.KeyValuePreceded || lhs.KeyValue > rhs.KeyValue || lhs.KeyValue == rhs.KeyValue && lhs.Score > rhs.Score; } + /// + /// + /// + /// + /// + /// public static bool operator <=(Bigram lhs, Bigram rhs) { return lhs.KeyValuePreceded <= rhs.KeyValuePreceded || lhs.KeyValue <= rhs.KeyValue || lhs.KeyValue == rhs.KeyValue && lhs.Score <= rhs.Score; } + /// + /// + /// + /// + /// + /// public static bool operator >=(Bigram lhs, Bigram rhs) { return lhs.KeyValuePreceded >= rhs.KeyValuePreceded || lhs.KeyValue >= rhs.KeyValue || lhs.KeyValue == rhs.KeyValue && lhs.Score >= rhs.Score; diff --git a/Megrez/6_Unigram.cs b/Megrez/6_Unigram.cs index 373b275..6db6e0c 100644 --- a/Megrez/6_Unigram.cs +++ b/Megrez/6_Unigram.cs @@ -50,34 +50,81 @@ public Unigram(KeyValuePaired keyValue, double score) { /// public double Score { get; set; } + /// + /// 判定兩個物件是否相等。 + /// + /// 用來比較的物件。 + /// 若相等,則返回 true。 public override bool Equals(object obj) { return obj is Unigram unigram && EqualityComparer.Default.Equals(KeyValue, unigram.KeyValue) && Math.Abs(Score - unigram.Score) < 0.0000001f; } + /// + /// 將當前物件的內容輸出為雜湊資料。 + /// + /// 當前物件的內容輸出成的雜湊資料。 public override int GetHashCode() { return HashCode.Combine(KeyValue, Score); } + /// + /// 將當前物件的內容輸出為字串。 + /// + /// 當前物件的內容輸出成的字串。 public override string ToString() => $"({KeyValue},{Score})"; - + /// + /// 判定兩個物件是否相等。 + /// + /// + /// + /// public static bool operator ==(Unigram lhs, Unigram rhs) { return lhs.KeyValue == rhs.KeyValue && Math.Abs(lhs.Score - rhs.Score) < 0.0000001f; } - + /// + /// 判定兩個物件是否相異。 + /// + /// + /// + /// public static bool operator !=(Unigram lhs, Unigram rhs) => lhs.KeyValue != rhs.KeyValue || Math.Abs(lhs.Score - rhs.Score) > 0.0000001f; + /// + /// + /// + /// + /// + /// public static bool operator<(Unigram lhs, Unigram rhs) { return lhs.KeyValue < rhs.KeyValue || lhs.KeyValue == rhs.KeyValue && lhs.Score < rhs.Score; } + /// + /// + /// + /// + /// + /// public static bool operator>(Unigram lhs, Unigram rhs) { return lhs.KeyValue > rhs.KeyValue || lhs.KeyValue == rhs.KeyValue && lhs.Score > rhs.Score; } + /// + /// + /// + /// + /// + /// public static bool operator <=(Unigram lhs, Unigram rhs) { return lhs.KeyValue <= rhs.KeyValue || lhs.KeyValue == rhs.KeyValue && lhs.Score <= rhs.Score; } + /// + /// + /// + /// + /// + /// public static bool operator >=(Unigram lhs, Unigram rhs) { return lhs.KeyValue >= rhs.KeyValue || lhs.KeyValue == rhs.KeyValue && lhs.Score >= rhs.Score; } diff --git a/Megrez/7_KeyValuePaired.cs b/Megrez/7_KeyValuePaired.cs index 9a5328f..b86a130 100644 --- a/Megrez/7_KeyValuePaired.cs +++ b/Megrez/7_KeyValuePaired.cs @@ -54,39 +54,90 @@ public KeyValuePaired(string key = "", string value = "") { /// 只要鍵或者值任一為空,則傳回值為「否」。 public bool IsValid() => !string.IsNullOrEmpty(Key) && !string.IsNullOrEmpty(Value); + /// + /// 判定兩個物件是否相等。 + /// + /// 用來比較的物件。 + /// 若相等,則返回 true。 public override bool Equals(object obj) { return obj is KeyValuePaired pair && Key == pair.Key && Value == pair.Value; } + /// + /// 將當前物件的內容輸出為雜湊資料。 + /// + /// 當前物件的內容輸出成的雜湊資料。 public override int GetHashCode() => HashCode.Combine(Key, Value); + /// + /// 將當前物件的內容輸出為字串。 + /// + /// 當前物件的內容輸出成的字串。 public override string ToString() => $"({Key},{Value})"; + /// + /// 生成統一索引鍵,以作其它用途。如果該鍵值配對有任一為空,則生成空的統一索引鍵。 + /// + /// 生成的統一索引鍵。 public string ToNGramKey() => IsValid() ? $"({Key},{Value})" : "()"; - + /// + /// 判定兩個物件是否相等。 + /// + /// + /// + /// public static bool operator ==(KeyValuePaired lhs, KeyValuePaired rhs) { return lhs.Key.Length == rhs.Key.Length && lhs.Value == rhs.Value; } - + /// + /// 判定兩個物件是否相異。 + /// + /// + /// + /// public static bool operator !=(KeyValuePaired lhs, KeyValuePaired rhs) { return lhs.Key.Length != rhs.Key.Length || lhs.Value != rhs.Value; } + /// + /// + /// + /// + /// + /// public static bool operator<(KeyValuePaired lhs, KeyValuePaired rhs) { return lhs.Key.Length < rhs.Key.Length || lhs.Key.Length == rhs.Key.Length && String.Compare(lhs.Value, rhs.Value, StringComparison.Ordinal) < 0; } + /// + /// + /// + /// + /// + /// public static bool operator>(KeyValuePaired lhs, KeyValuePaired rhs) { return lhs.Key.Length > rhs.Key.Length || lhs.Key.Length == rhs.Key.Length && String.Compare(lhs.Value, rhs.Value, StringComparison.Ordinal) > 0; } + /// + /// + /// + /// + /// + /// public static bool operator <=(KeyValuePaired lhs, KeyValuePaired rhs) { return lhs.Key.Length <= rhs.Key.Length || lhs.Key.Length == rhs.Key.Length && String.Compare(lhs.Value, rhs.Value, StringComparison.Ordinal) <= 0; } + /// + /// + /// + /// + /// + /// public static bool operator >=(KeyValuePaired lhs, KeyValuePaired rhs) { return lhs.Key.Length >= rhs.Key.Length || lhs.Key.Length == rhs.Key.Length && String.Compare(lhs.Value, rhs.Value, StringComparison.Ordinal) >= 0; diff --git a/Megrez/Megrez.csproj b/Megrez/Megrez.csproj index 416a9f0..ce6f43e 100644 --- a/Megrez/Megrez.csproj +++ b/Megrez/Megrez.csproj @@ -3,16 +3,16 @@ net6.0 enable - 1.2.6 + 1.2.7 vChewing.Megrez Shiki Suen Atelier Inmu (c) 2022 and onwards The vChewing Project (MIT-NTL License). https://github.com/ShikiSuen/MegrezNT zh-TW - 1.2.6 - 1.2.6 - 1.2.6 + 1.2.7 + 1.2.7 + 1.2.7 Megrez True README.md