LMCoreNS // Auto-generate candidates of half-width punctuations.

This commit is contained in:
ShikiSuen 2022-11-26 05:45:49 +08:00
parent 7e57eb74c1
commit cdc8a3a113
1 changed files with 19 additions and 12 deletions

View File

@ -107,7 +107,8 @@ extension vChewingLM {
/// - key:
public func unigramsFor(key: String) -> [Megrez.Unigram] {
var grams: [Megrez.Unigram] = []
if let arrRangeRecords: [Data] = rangeMap[cnvPhonabetToASCII(key)] {
var gramsHW: [Megrez.Unigram] = []
guard let arrRangeRecords: [Data] = rangeMap[cnvPhonabetToASCII(key)] else { return grams }
for netaSet in arrRangeRecords {
let strNetaSet = String(decoding: netaSet, as: UTF8.self)
let neta = Array(strNetaSet.trimmingCharacters(in: .newlines).split(separator: " ").reversed())
@ -120,8 +121,14 @@ extension vChewingLM {
theScore *= -1 //
}
grams.append(Megrez.Unigram(value: theValue, score: theScore))
if !key.contains("_punctuation") { continue }
if let halfValue = theValue.applyingTransform(.fullwidthToHalfwidth, reverse: false) {
if halfValue != theValue {
gramsHW.append(Megrez.Unigram(value: halfValue, score: theScore))
}
}
}
grams.append(contentsOf: gramsHW)
return grams
}