Skip to content

Commit

Permalink
Fix a malfunctioned pokayoke in overrideCandidateAgainst(). (#80)
Browse files Browse the repository at this point in the history
* Fix a malfunctioned pokayoke in overrideCandidateAgainst().

* Simplify fetchCandidates().

* Term fix.
  • Loading branch information
ShikiSuen authored Aug 8, 2022
1 parent 52b1d9a commit ed124da
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions Sources/Megrez/3_Candidate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,12 @@ extension Megrez.Compositor {
case .all:
// 得加上這道篩選,所以會出現很多無效結果。
if !theNode.keyArray.contains(keyAtCursor) { continue }
result.append(.init(key: theNode.key, value: gram.value))
case .beginAt:
if theNode.keyArray[0] != keyAtCursor { continue }
result.append(.init(key: theNode.key, value: gram.value))
case .endAt:
if theNode.keyArray.reversed()[0] != keyAtCursor { continue }
result.append(.init(key: theNode.key, value: gram.value))
}
result.append(.init(key: theNode.key, value: gram.value))
}
}
return result
Expand Down Expand Up @@ -132,13 +130,13 @@ extension Megrez.Compositor {
internal func overrideCandidateAgainst(key: String?, at location: Int, value: String, type: Node.OverrideType)
-> Bool
{
let location = max(min(location, keys.count - 1), 0) // 防呆
let location = max(min(location, keys.count), 0) // 防呆
var arrOverlappedNodes: [NodeAnchor] = fetchOverlappingNodes(at: min(keys.count - 1, location))
var overridden: NodeAnchor?
for nis in arrOverlappedNodes {
if let key = key, nis.node.key != key { continue }
if nis.node.selectOverrideUnigram(value: value, type: type) {
overridden = nis
for anchor in arrOverlappedNodes {
if let key = key, anchor.node.key != key { continue }
if anchor.node.selectOverrideUnigram(value: value, type: type) {
overridden = anchor
break
}
}
Expand All @@ -150,9 +148,9 @@ extension Megrez.Compositor {
/// 且 A 與 BC 都是被覆寫的結果,然後使用者現在在與 A 相同的幅位座標位置
/// 選了「DEF」,那麼 BC 的覆寫狀態就有必要重設(但 A 不用重設)。
arrOverlappedNodes = fetchOverlappingNodes(at: i)
for nis in arrOverlappedNodes {
if nis.node == overridden.node { continue }
nis.node.reset()
for anchor in arrOverlappedNodes {
if anchor.node == overridden.node { continue }
anchor.node.reset()
}
}
return true
Expand Down

0 comments on commit ed124da

Please sign in to comment.