UOM // Only update observation if half-decayed.

This commit is contained in:
ShikiSuen 2022-07-23 23:48:46 +08:00
parent 1cbcbb4b6f
commit d2ed575d36
1 changed files with 24 additions and 6 deletions

View File

@ -70,19 +70,26 @@ extension vChewing {
saveCallback()
return
}
//
if var theNeta = mutLRUMap[key] {
theNeta.observation.update(candidate: candidate, timestamp: timestamp)
mutLRUList.insert(theNeta, at: 0)
mutLRUMap[key] = theNeta
IME.prtDebugIntel("UOM: Observation finished with existing observation: \(key)")
saveCallback()
_ = suggest(
walkedAnchors: walkedAnchors, cursorIndex: cursorIndex, timestamp: timestamp,
decayCallback: {
theNeta.observation.update(candidate: candidate, timestamp: timestamp)
self.mutLRUList.insert(theNeta, at: 0)
self.mutLRUMap[key] = theNeta
IME.prtDebugIntel("UOM: Observation finished with existing observation: \(key)")
saveCallback()
}
)
}
}
public func suggest(
walkedAnchors: [Megrez.NodeAnchor],
cursorIndex: Int,
timestamp: Double
timestamp: Double,
decayCallback: @escaping () -> Void = {}
) -> [Megrez.Unigram] {
let key = convertKeyFrom(walkedAnchors: walkedAnchors, cursorIndex: cursorIndex)
let currentReadingKey = convertKeyFrom(walkedAnchors: walkedAnchors, cursorIndex: cursorIndex, readingOnly: true)
@ -97,6 +104,7 @@ extension vChewing {
var currentHighScore = 0.0
for overrideNeta in Array(observation.overrides) {
let override: Override = overrideNeta.value
let overrideScore: Double = getScore(
eventCount: override.count,
totalCount: observation.count,
@ -105,6 +113,16 @@ extension vChewing {
lambda: mutDecayExponent
)
if (0...currentHighScore).contains(overrideScore) { continue }
let overrideDetectionScore: Double = getScore(
eventCount: override.count,
totalCount: observation.count,
eventTimestamp: override.timestamp,
timestamp: timestamp,
lambda: mutDecayExponent * 2
)
if (0...currentHighScore).contains(overrideDetectionScore) { decayCallback() }
let newUnigram = Megrez.Unigram(
keyValue: .init(key: currentReadingKey, value: overrideNeta.key), score: overrideScore
)