Skip to content

Commit

Permalink
refactor: 优化排序评分算法
Browse files Browse the repository at this point in the history
  • Loading branch information
lazyloong committed Dec 19, 2023
1 parent 0abeb8d commit bc99b1e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"author": "lazyloong",

"minAppVersion": "1.0.0",
"version": "2.10.2"
"version": "2.10.3"
}
7 changes: 4 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ export class Pinyin extends Array<PinyinChild> {
}
getScore(range: Array<[number, number]>) {
let score = 0;
let coverage = range.reduce((p, i) => p + i[1] - i[0] + 1, 0);
score += 30 * (coverage / this.text.length); // 使用线性函数计算覆盖度
score += 20 * Math.exp(-range[0][0] / this.text.length); // 靠前加分
let coverage = range.reduce((p, c) => p + c[1] - c[0] + 1, 0);
coverage = coverage / this.text.length;
score += coverage < 0.5 ? 150 * coverage : 50 * coverage + 50; // 使用线性函数计算覆盖度
score += 20 / (range[0][0] + 1); // 靠前加分
score += 30 / range.length; // 分割越少分越高
return score;
}
Expand Down

0 comments on commit bc99b1e

Please sign in to comment.