DataCompiler // Changed the handling of kana frequencies.

- This can make sure that kana has lowest frequencies than anything.
This commit is contained in:
ShikiSuen 2022-02-28 00:07:44 +08:00
parent a7cb355d4f
commit 0f0fc84090
1 changed files with 12 additions and 5 deletions

View File

@ -343,17 +343,24 @@ func weightAndSort(_ arrStructUncalculated: [Entry], isCHS: Bool) -> [Entry] {
let fscale: Float = 2.7 let fscale: Float = 2.7
var norm: Float = 0.0 var norm: Float = 0.0
for entry in arrStructUncalculated { for entry in arrStructUncalculated {
if entry.valCount >= 0 {
norm += fscale**(Float(entry.valPhrase.count) / 3.0 - 1.0) * Float(entry.valCount) // Credit: MJHsieh. norm += fscale**(Float(entry.valPhrase.count) / 3.0 - 1.0) * Float(entry.valCount) // Credit: MJHsieh.
} }
}
// norm norm // norm norm
// //
// 1 0 0.5 // 1 0 0.5
// MJHsieh MIT License // MJHsieh MIT License
for entry in arrStructUncalculated { for entry in arrStructUncalculated {
let weight: Float = (entry.valCount < 1) ? var weight: Float = 0
log10(fscale**(Float(entry.valPhrase.count) / 3.0 - 1.0) * 0.5 / norm) // Credit: MJHsieh. switch entry.valCount {
: case -1: //
log10(fscale**(Float(entry.valPhrase.count) / 3.0 - 1.0) * Float(entry.valCount) / norm) // Credit: MJHsieh. weight = -13
case 0: //
weight = log10(fscale**(Float(entry.valPhrase.count) / 3.0 - 1.0) * 0.5 / norm) // Credit: MJHsieh.
default:
weight = log10(fscale**(Float(entry.valPhrase.count) / 3.0 - 1.0) * Float(entry.valCount) / norm) // Credit: MJHsieh.
}
let weightRounded: Float = weight.rounded(toPlaces: 3) // let weightRounded: Float = weight.rounded(toPlaces: 3) //
arrStructCalculated += [Entry.init(valPhone: entry.valPhone, valPhrase: entry.valPhrase, valWeight: weightRounded, valCount: entry.valCount)] arrStructCalculated += [Entry.init(valPhone: entry.valPhone, valPhrase: entry.valPhrase, valWeight: weightRounded, valCount: entry.valCount)]
} }