UOM // Remove decayCallback().

This commit is contained in:
ShikiSuen 2022-08-12 15:29:27 +08:00
parent ab685149e7
commit 15308a1148
1 changed files with 8 additions and 20 deletions

View File

@ -278,26 +278,19 @@ extension vChewing.LMUserOverride {
saveCallback() saveCallback()
return return
} }
// TODO: // decayCallback
if var theNeta = mutLRUMap[key] { if var theNeta = mutLRUMap[key] {
_ = getSuggestion( theNeta.observation.update(
key: key, timestamp: timestamp, headReading: "", candidate: candidate, timestamp: timestamp, forceHighScoreOverride: forceHighScoreOverride
decayCallback: {
theNeta.observation.update(
candidate: candidate, timestamp: timestamp, forceHighScoreOverride: forceHighScoreOverride
)
self.mutLRUList.insert(theNeta, at: 0)
self.mutLRUMap[key] = theNeta
IME.prtDebugIntel("UOM: Observation finished with existing observation: \(key)")
saveCallback()
}
) )
mutLRUList.insert(theNeta, at: 0)
mutLRUMap[key] = theNeta
IME.prtDebugIntel("UOM: Observation finished with existing observation: \(key)")
saveCallback()
} }
} }
private func getSuggestion( private func getSuggestion(key: String, timestamp: Double, headReading: String) -> Suggestion {
key: String, timestamp: Double, headReading: String, decayCallback: @escaping () -> Void = {}
) -> Suggestion {
guard !key.isEmpty, let kvPair = mutLRUMap[key] else { return .init() } guard !key.isEmpty, let kvPair = mutLRUMap[key] else { return .init() }
let observation: Observation = kvPair.observation let observation: Observation = kvPair.observation
var candidates: [(String, Megrez.Unigram)] = .init() var candidates: [(String, Megrez.Unigram)] = .init()
@ -309,11 +302,6 @@ extension vChewing.LMUserOverride {
eventTimestamp: theObservation.timestamp, timestamp: timestamp, lambda: mutDecayExponent eventTimestamp: theObservation.timestamp, timestamp: timestamp, lambda: mutDecayExponent
) )
if (0...currentHighScore).contains(overrideScore) { continue } if (0...currentHighScore).contains(overrideScore) { continue }
let overrideDetectionScore: Double = getScore(
eventCount: theObservation.count, totalCount: observation.count,
eventTimestamp: theObservation.timestamp, timestamp: timestamp, lambda: mutDecayExponent * 2
)
if (0...currentHighScore).contains(overrideDetectionScore) { decayCallback() }
candidates.append((headReading, .init(value: i, score: overrideScore))) candidates.append((headReading, .init(value: i, score: overrideScore)))
forceHighScoreOverride = theObservation.forceHighScoreOverride forceHighScoreOverride = theObservation.forceHighScoreOverride