awtk/tools/word_gen
2019-11-14 17:58:50 +08:00
..
.gitignore add word_gen 2018-06-26 14:47:03 +08:00
gen.js update tools 2018-07-01 10:28:15 +08:00
package-lock.json Merge pull request #279 from zlgopen/dependabot/npm_and_yarn/tools/word_gen/lodash.merge-4.6.2 2019-11-14 17:58:50 +08:00
package.json add word_gen 2018-06-26 18:19:25 +08:00
README.md update tools 2018-07-01 10:28:15 +08:00
words.bin update tools 2018-07-01 10:28:15 +08:00

抓取网页,生成输入法联想词库。

生成数据

在当前目录下运行:

npm install
node gen.js

更新数据

在awtk目录下运行

./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。

let getChunksCallsNr = 0;
var getChunks = function (wordpos, pos, text) {
  var words = wordpos[pos] || [];
  // debug('getChunks: ');
  // debug(words);
  // throw new Error();
  var ret = [];
  if(getChunksCallsNr > 150) {
    throw "get Chunks error";
  }
  
  getChunksCallsNr++;
  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]);
    } else  {
      var chunks = getChunks(wordpos, nextcur);
      for (var j = 0; j < chunks.length && j < 5000; j++) {
        ret.push([word].concat(chunks[j]));
      }
    }
  }
  getChunksCallsNr--;

  return ret;
};