Skip to content

Commit

Permalink
增加统计符号频率
Browse files Browse the repository at this point in the history
  • Loading branch information
macroxue committed Jan 27, 2024
1 parent 1f24a9e commit 7fd3c1a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
8 changes: 8 additions & 0 deletions eval.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,19 @@ <h1>双拼方案评测、优化和生成
<textarea readonly rows='6' cols='14' id='yun-stats'>
</textarea>
</td>
<td class='stats' id='alphabet-stats-cell'>
<p/><b>符号: </b>
<input id='alphabet-stats-filter' onchange='show_pinyin_stats("alphabet")'/>
<br/>
<textarea readonly rows='6' cols='14' id='alphabet-stats'>
</textarea>
</td>
</tr>
</table>
<div class='stats-saved' id='pinyin-stats-saved'></div>
<div class='stats-saved' id='sheng-stats-saved'></div>
<div class='stats-saved' id='yun-stats-saved'></div>
<div class='stats-saved' id='alphabet-stats-saved'></div>
</div>

<div class='keyboard'>
Expand Down
23 changes: 22 additions & 1 deletion evaluator.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ var punctuations = {
',':',', '。':'.', ';':';', ',':',', '.':'.', ';':';', '/':'/'
};

var letters = 'abcdefghijklmnopqrstuvwxyz';
var letters = 'abcdefghijklmnopqrstuvwxyz 0123456789';

function split_pinyin(pinyin) {
if (pinyin == 'ng') {
Expand Down Expand Up @@ -127,17 +127,29 @@ function update_yun_sheng_freq(yun, sheng) {
}
}

var alphabeta_freq = {}

function update_alphabeta_freq(char) {
if (alphabeta_freq[char] == null) {
alphabeta_freq[char] = 1;
} else {
++alphabeta_freq[char];
}
}

function stat_pinyin() {
var input = document.getElementById('input-text').value;
var pinyin_freq = {};
var sheng_freq = {};
var yun_freq = {};
var pinyin_splits = {};
var total = 0;
var alphabeta_total = 0;

var last_yun = '';
sheng_yun_freq = {};
yun_sheng_freq = {};
alphabeta_freq = {};

for (var i = 0; i < input.length; ++i) {
var c = input[i].trim();
Expand All @@ -146,10 +158,17 @@ function stat_pinyin() {
}
var punctuation = punctuations[c];
if (punctuation != null) {
++alphabeta_total;
update_alphabeta_freq(punctuation);
update_yun_sheng_freq(last_yun, punctuation);
last_yun = punctuation;
continue;
}
if (letters.includes(c.toLowerCase())) {
++alphabeta_total;
update_alphabeta_freq(c.toLowerCase());
continue;
}
var pinyin = char_pinyin[c];
if (pinyin == null) {
continue;
Expand Down Expand Up @@ -187,9 +206,11 @@ function stat_pinyin() {
save_pinyin_stats('pinyin', pinyin_freq, total);
save_pinyin_stats('sheng', sheng_freq, total);
save_pinyin_stats('yun', yun_freq, total);
save_pinyin_stats('alphabet', alphabeta_freq, alphabeta_total);
show_pinyin_stats('pinyin');
show_pinyin_stats('sheng');
show_pinyin_stats('yun');
show_pinyin_stats('alphabet');
}

function save_pinyin_stats(type, freq, total) {
Expand Down

0 comments on commit 7fd3c1a

Please sign in to comment.