diff --git a/Source/Modules/LanguageParsers/Megrez/1_BlockReadingBuilder.swift b/Source/Modules/LanguageParsers/Megrez/1_BlockReadingBuilder.swift index 2bf8cb76..eb562795 100644 --- a/Source/Modules/LanguageParsers/Megrez/1_BlockReadingBuilder.swift +++ b/Source/Modules/LanguageParsers/Megrez/1_BlockReadingBuilder.swift @@ -193,8 +193,7 @@ extension Megrez { // 利用幅位長度來決定權重。 // 這樣一來,例:「再見」比「在」與「見」的權重更高。 if balanced { - let weightedScore: Double = (Double(n.spanningLength) - 1) * 2 - n.accumulatedScore += weightedScore + n.accumulatedScore += n.additionalWeights } var path: [NodeAnchor] = reverseWalk( diff --git a/Source/Modules/LanguageParsers/Megrez/2_Grid.swift b/Source/Modules/LanguageParsers/Megrez/2_Grid.swift index da532564..61410e8f 100644 --- a/Source/Modules/LanguageParsers/Megrez/2_Grid.swift +++ b/Source/Modules/LanguageParsers/Megrez/2_Grid.swift @@ -204,33 +204,33 @@ extension Megrez { extension Megrez.Grid { public var dumpDOT: String { - var sst = "digraph {\ngraph [ rankdir=LR ];\nBOS;\n" + var strOutput = "digraph {\ngraph [ rankdir=LR ];\nBOS;\n" for (p, span) in mutSpans.enumerated() { for ni in 0...(span.maximumLength) { guard let np: Megrez.Node = span.node(length: ni) else { continue } if p == 0 { - sst += "BOS -> \(np.currentKeyValue.value);\n" + strOutput += "BOS -> \(np.currentKeyValue.value);\n" } - sst += "\(np.currentKeyValue.value);\n" + strOutput += "\(np.currentKeyValue.value);\n" if (p + ni) < mutSpans.count { - let dstSpan = mutSpans[p + ni] - for q in 0...(dstSpan.maximumLength) { - if let dn = dstSpan.node(length: q) { - sst += np.currentKeyValue.value + " -> " + dn.currentKeyValue.value + ";\n" + let destinatedSpan = mutSpans[p + ni] + for q in 0...(destinatedSpan.maximumLength) { + if let dn = destinatedSpan.node(length: q) { + strOutput += np.currentKeyValue.value + " -> " + dn.currentKeyValue.value + ";\n" } } } if (p + ni) == mutSpans.count { - sst += np.currentKeyValue.value + " -> EOS;\n" + strOutput += np.currentKeyValue.value + " -> EOS;\n" } } } - sst += "EOS;\n}\n" - return sst + strOutput += "EOS;\n}\n" + return strOutput } } diff --git a/Source/Modules/LanguageParsers/Megrez/3_NodeAnchor.swift b/Source/Modules/LanguageParsers/Megrez/3_NodeAnchor.swift index b450b6a2..11b47258 100644 --- a/Source/Modules/LanguageParsers/Megrez/3_NodeAnchor.swift +++ b/Source/Modules/LanguageParsers/Megrez/3_NodeAnchor.swift @@ -52,11 +52,19 @@ extension Megrez { return stream } + /// 獲取加權量。 + public var additionalWeights: Double { + (Double(spanningLength) - 1) * 0.75 + } + /// 獲取平衡權重。 public var balancedScore: Double { - let weightedScore: Double = (Double(spanningLength) - 1) * 2 - let nodeScore: Double = node?.score ?? 0 - return weightedScore + nodeScore + (node?.score ?? 0) + additionalWeights + } + + /// 獲取平衡累計權重。 + public var balancedAccumulatedScore: Double { + accumulatedScore + additionalWeights } } }