Megrez v1.1.3 // Nerf the additional weights to the balanced score.
This commit is contained in:
parent
ba595c475e
commit
0bcaa61656
|
@ -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(
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue