Open heibei2020 opened 3 years ago
git clone https://github.com/takuyaa/kuromoji.js.git
cd kuromoji.js
npm install gulp ・・・npm installとかしちゃいけない、、、gulpのみ追加する
<以下から辞書をダウンロードして解凍しておく> https://github.com/neologd/mecab-ipadic-neologd/tree/master/seed mecab-user-dict-seed.20200910.csv.xz
cp ../mecabdic/mecab-user-dict-seed.20200910.csv ./node_modules/mecab-ipadic-seed/lib/dict/.
<何回か実行して、Out of memoryが出て止まったので、メモリ増やしました>
gulp build-dict --max_old_space_size=5120
vi sample.js
"use strict";
var kuromoji = require("./src/kuromoji"); var DIC_DIR = "dict/";
// Load dictionaries from file, and prepare tokenizer kuromoji.builder({ dicPath: DIC_DIR }).build(function (error, tokenizer) { var path = tokenizer.tokenize("鬼滅の刃ととなりのトトロはどちらが面白い"); console.log(path); module.exports = tokenizer; });
node sample.js |more
<分析結果>
[ { word_id: 35387780, word_type: 'KNOWN', word_position: 1, surface_form: '鬼滅の刃', pos: '名詞', pos_detail_1: '固有名詞', pos_detail_2: '一般', pos_detail_3: '', conjugated_type: '', conjugated_form: '', basic_form: '鬼滅の刃', reading: 'キメツノヤイバ', pronunciation: 'キメツノヤイバ' }, { word_id: 77960, word_type: 'KNOWN', word_position: 5, surface_form: 'と', pos: '助詞', pos_detail_1: '並立助詞', pos_detail_2: '', pos_detail_3: '', conjugated_type: '', conjugated_form: '', basic_form: 'と', reading: 'ト', pronunciation: 'ト' }, { word_id: 8261830, word_type: 'KNOWN', word_position: 6, surface_form: 'となりのトトロ', pos: '名詞', pos_detail_1: '固有名詞', pos_detail_2: '一般', pos_detail_3: '', conjugated_type: '', conjugated_form: '', basic_form: 'となりのトトロ', reading: 'トナリノトトロ', pronunciation: 'トナリノトトロ' }, { word_id: 77850, word_type: 'KNOWN', word_position: 13, surface_form: 'は', pos: '助詞', pos_detail_1: '係助詞',
、、、略、、、
gulp build-dict
を実行すると/ほげぱす/kuromoji.js/node_modules/globby/index.js:28 } catch { ^
' 'SyntaxError: Unexpected token {'が発生して実行できないです
辞書の更新ができないです。
自レス: (確認してないが)node_modulesで、勝手に私が実行していた、「npm install」で各モジュールのバージョン等がズレてしまってたことが理由かも。
以下のコメントの手順を実施したら、とりあえずうまく行った感じでした。