InputHandler // Syncing changes from Megrez v2.6.2-v2.6.3 update.

This commit is contained in:
ShikiSuen 2023-03-16 20:00:39 +08:00
parent 652069b1de
commit f76d0b6f96
2 changed files with 17 additions and 18 deletions

View File

@ -166,10 +166,9 @@ public class InputHandler: InputHandlerProtocol {
return !isBound && rawResult
}
/// Megrez 使便
///
/// 使 Node Crossing
var cursorForCandidate: Int {
/// Megrez 使
/// - Remark: Megrez v2.6.2 cursor
var actualNodeCursorPosition: Int {
compositor.cursor
- ((compositor.cursor == compositor.length || !prefs.useRearCursorMode) && compositor.cursor > 0 ? 1 : 0)
}
@ -233,18 +232,18 @@ public class InputHandler: InputHandlerProtocol {
/// - Parameter theCandidate:
func consolidateCursorContext(with theCandidate: Megrez.KeyValuePaired) {
var grid = compositor.hardCopy // Node hardCopy
var frontBoundaryEX = cursorForCandidate + 1
var rearBoundaryEX = cursorForCandidate
var frontBoundaryEX = actualNodeCursorPosition + 1
var rearBoundaryEX = actualNodeCursorPosition
var debugIntelToPrint = ""
if grid.overrideCandidate(theCandidate, at: cursorForCandidate) {
if grid.overrideCandidate(theCandidate, at: actualNodeCursorPosition) {
grid.walk()
let range = grid.walkedNodes.contextRange(ofGivenCursor: cursorForCandidate)
let range = grid.walkedNodes.contextRange(ofGivenCursor: actualNodeCursorPosition)
rearBoundaryEX = range.lowerBound
frontBoundaryEX = range.upperBound
debugIntelToPrint.append("EX: \(rearBoundaryEX)..<\(frontBoundaryEX), ")
}
let range = compositor.walkedNodes.contextRange(ofGivenCursor: cursorForCandidate)
let range = compositor.walkedNodes.contextRange(ofGivenCursor: actualNodeCursorPosition)
var rearBoundary = min(range.lowerBound, rearBoundaryEX)
var frontBoundary = max(range.upperBound, frontBoundaryEX)
@ -311,7 +310,7 @@ public class InputHandler: InputHandlerProtocol {
if preConsolidate { consolidateCursorContext(with: theCandidate) }
//
if !compositor.overrideCandidate(theCandidate, at: cursorForCandidate) { return }
if !compositor.overrideCandidate(theCandidate, at: actualNodeCursorPosition) { return }
let previousWalk = compositor.walkedNodes
//
walk()
@ -319,7 +318,7 @@ public class InputHandler: InputHandlerProtocol {
// 使
var accumulatedCursor = 0
let currentNode = currentWalk.findNode(at: cursorForCandidate, target: &accumulatedCursor)
let currentNode = currentWalk.findNode(at: actualNodeCursorPosition, target: &accumulatedCursor)
guard let currentNode = currentNode else { return }
uom: if currentNode.currentUnigram.score > -12, prefs.fetchSuggestionsFromUserOverrideModel {
@ -332,7 +331,7 @@ public class InputHandler: InputHandlerProtocol {
//
//
currentUOM.performObservation(
walkedBefore: previousWalk, walkedAfter: currentWalk, cursor: cursorForCandidate,
walkedBefore: previousWalk, walkedAfter: currentWalk, cursor: actualNodeCursorPosition,
timestamp: Date().timeIntervalSince1970, saveCallback: { self.currentUOM.saveData() }
)
//
@ -352,8 +351,8 @@ public class InputHandler: InputHandlerProtocol {
/// nodeCrossing
var arrCandidates: [Megrez.KeyValuePaired] = {
switch prefs.useRearCursorMode {
case false: return compositor.fetchCandidates(at: cursorForCandidate, filter: .endAt)
case true: return compositor.fetchCandidates(at: cursorForCandidate, filter: .beginAt)
case false: return compositor.fetchCandidates(filter: .endAt)
case true: return compositor.fetchCandidates(filter: .beginAt)
}
}()
@ -386,7 +385,7 @@ public class InputHandler: InputHandlerProtocol {
if !prefs.fetchSuggestionsFromUserOverrideModel { return arrResult }
///
let suggestion = currentUOM.fetchSuggestion(
currentWalk: compositor.walkedNodes, cursor: cursorForCandidate, timestamp: Date().timeIntervalSince1970
currentWalk: compositor.walkedNodes, cursor: actualNodeCursorPosition, timestamp: Date().timeIntervalSince1970
)
arrResult.append(contentsOf: suggestion.candidates)
if apply {
@ -399,9 +398,9 @@ public class InputHandler: InputHandlerProtocol {
)
vCLog(
"UOM: Suggestion received, overriding the node score of the selected candidate: \(suggestedPair.toNGramKey)")
if !compositor.overrideCandidate(suggestedPair, at: cursorForCandidate, overrideType: overrideBehavior) {
if !compositor.overrideCandidate(suggestedPair, at: actualNodeCursorPosition, overrideType: overrideBehavior) {
compositor.overrideCandidateLiteral(
newestSuggestedCandidate.1.value, at: cursorForCandidate, overrideType: overrideBehavior
newestSuggestedCandidate.1.value, at: actualNodeCursorPosition, overrideType: overrideBehavior
)
}
walk()

View File

@ -789,7 +789,7 @@ extension InputHandler {
return true
}
guard let region = compositor.walkedNodes.cursorRegionMap[cursorForCandidate],
guard let region = compositor.walkedNodes.cursorRegionMap[actualNodeCursorPosition],
compositor.walkedNodes.count > region
else {
delegate.callError("1CE6FFBD")