2018-06-26 18:19:25 +08:00
|
|
|
|
## 抓取网页,生成输入法联想词库。
|
2018-06-27 15:47:30 +08:00
|
|
|
|
|
|
|
|
|
### 生成数据
|
|
|
|
|
|
|
|
|
|
在当前目录下运行:
|
|
|
|
|
|
2020-02-06 08:47:28 +08:00
|
|
|
|
* 准备
|
|
|
|
|
|
2018-06-27 15:47:30 +08:00
|
|
|
|
```
|
|
|
|
|
npm install
|
2020-02-06 08:47:28 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
* 抓取网页,生成words.json
|
|
|
|
|
|
|
|
|
|
> 可以修改maxURLS改变最大网页数量。
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
node gen_words_json.js
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* 生成二进制的words.bin文件
|
|
|
|
|
|
|
|
|
|
> 可以根据自己的需要进行编辑words.json。
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
node to_words_bin.js
|
2018-06-27 15:47:30 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 更新数据
|
|
|
|
|
|
2020-02-06 08:47:28 +08:00
|
|
|
|
在awtk根目录下运行:
|
2018-06-27 15:47:30 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
./bin/resgen tools/word_gen/words.bin src/input_methods/suggest_words.inc
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 注意:
|
|
|
|
|
node\_modules/segment/lib/module/DictTokenizer.js#getChunks 可能导致OOM。
|
|
|
|
|
|
|
|
|
|
如果遇到问题,可以限制chunks.length的大小,如下面限制为5000。
|
|
|
|
|
|
|
|
|
|
```
|
2018-06-30 18:07:28 +08:00
|
|
|
|
let getChunksCallsNr = 0;
|
2018-06-27 15:47:30 +08:00
|
|
|
|
var getChunks = function (wordpos, pos, text) {
|
2018-06-30 18:07:28 +08:00
|
|
|
|
var words = wordpos[pos] || [];
|
2018-06-27 15:47:30 +08:00
|
|
|
|
// debug('getChunks: ');
|
|
|
|
|
// debug(words);
|
|
|
|
|
// throw new Error();
|
2018-06-30 18:07:28 +08:00
|
|
|
|
var ret = [];
|
2018-07-01 10:28:15 +08:00
|
|
|
|
if(getChunksCallsNr > 150) {
|
2018-06-30 18:07:28 +08:00
|
|
|
|
throw "get Chunks error";
|
|
|
|
|
}
|
2018-07-01 10:28:15 +08:00
|
|
|
|
|
|
|
|
|
getChunksCallsNr++;
|
2018-06-27 15:47:30 +08:00
|
|
|
|
for (var i = 0; i < words.length; i++) {
|
|
|
|
|
var word = words[i];
|
|
|
|
|
//debug(word);
|
|
|
|
|
var nextcur = word.c + word.w.length;
|
|
|
|
|
if (!wordpos[nextcur]) {
|
|
|
|
|
ret.push([word]);
|
2018-06-30 18:07:28 +08:00
|
|
|
|
} else {
|
2018-06-27 15:47:30 +08:00
|
|
|
|
var chunks = getChunks(wordpos, nextcur);
|
|
|
|
|
for (var j = 0; j < chunks.length && j < 5000; j++) {
|
|
|
|
|
ret.push([word].concat(chunks[j]));
|
2018-06-30 18:07:28 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-06-27 15:47:30 +08:00
|
|
|
|
}
|
2018-06-30 18:07:28 +08:00
|
|
|
|
getChunksCallsNr--;
|
|
|
|
|
|
2018-06-27 15:47:30 +08:00
|
|
|
|
return ret;
|
|
|
|
|
};
|
|
|
|
|
```
|
|
|
|
|
|