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 93f969d617
commit f9b8ac419d
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
var norm: Float = 0.0
for entry in arrStructUncalculated {
norm += fscale**(Float(entry.valPhrase.count) / 3.0 - 1.0) * Float(entry.valCount) // Credit: MJHsieh.
if entry.valCount >= 0 {
norm += fscale**(Float(entry.valPhrase.count) / 3.0 - 1.0) * Float(entry.valCount) // Credit: MJHsieh.
}
}
// norm norm
//
// 1 0 0.5
// MJHsieh MIT License
for entry in arrStructUncalculated {
let weight: Float = (entry.valCount < 1) ?
log10(fscale**(Float(entry.valPhrase.count) / 3.0 - 1.0) * 0.5 / norm) // Credit: MJHsieh.
:
log10(fscale**(Float(entry.valPhrase.count) / 3.0 - 1.0) * Float(entry.valCount) / norm) // Credit: MJHsieh.
var weight: Float = 0
switch entry.valCount {
case -1: //
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) //
arrStructCalculated += [Entry.init(valPhone: entry.valPhone, valPhrase: entry.valPhrase, valWeight: weightRounded, valCount: entry.valCount)]
}