LMAssembly // Add temporary data support for LMCoreEX.

This commit is contained in:
ShikiSuen 2022-11-30 23:18:55 +08:00
parent 73b8d04425
commit eb7076e318
2 changed files with 13 additions and 0 deletions

View File

@ -227,6 +227,13 @@ extension vChewingLM {
lmAssociates.valuesFor(pair: pair) lmAssociates.valuesFor(pair: pair)
} }
public func insertTemporaryData(key: String, unigram: Megrez.Unigram, isFiltering: Bool) {
_ =
isFiltering
? lmFiltered.temporaryMap[key, default: []].append(unigram)
: lmUserPhrases.temporaryMap[key, default: []].append(unigram)
}
/// ///
/// - Parameter key: /// - Parameter key:
/// - Returns: /// - Returns:

View File

@ -19,6 +19,8 @@ extension vChewingLM {
@frozen public struct LMCoreEX { @frozen public struct LMCoreEX {
/// 便 strData /// 便 strData
var rangeMap: [String: [Range<String.Index>]] = [:] var rangeMap: [String: [Range<String.Index>]] = [:]
///
var temporaryMap: [String: [Megrez.Unigram]] = [:]
/// ///
var strData: String = "" var strData: String = ""
/// ///
@ -78,6 +80,7 @@ extension vChewingLM {
} }
} }
} }
temporaryMap.removeAll()
} catch { } catch {
vCLog("\(error)") vCLog("\(error)")
vCLog("↑ Exception happened when reading data at: \(path).") vCLog("↑ Exception happened when reading data at: \(path).")
@ -129,6 +132,9 @@ extension vChewingLM {
grams.append(Megrez.Unigram(value: theValue, score: theScore)) grams.append(Megrez.Unigram(value: theValue, score: theScore))
} }
} }
if let arrOtherRecords: [Megrez.Unigram] = temporaryMap[key] {
grams.append(contentsOf: arrOtherRecords)
}
return grams return grams
} }