-
Notifications
You must be signed in to change notification settings - Fork 5
/
igo.js
24 lines (19 loc) · 1004 Bytes
/
igo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/env node
var fs = require('fs');
var igo = require('./build/igo.min.js');
function loadTagger(dicdir) {
var dicfiles = ['char.category', 'code2category', 'word2id', 'word.dat', 'word.ary.idx', 'word.inf', 'matrix.bin'];
var files = new Array();
for(var i=0;i<dicfiles.length;++i) {
files[dicfiles[i]] = fs.readFileSync(dicdir + '/' + dicfiles[i]);
}
var category = new igo.CharCategory(files['code2category'], files['char.category']);
var wdc = new igo.WordDic(files['word2id'], files['word.dat'], files['word.ary.idx'], files['word.inf']);
var unk = new igo.Unknown(category);
var mtx = new igo.Matrix(files['matrix.bin']);
return new igo.Tagger(wdc, unk, mtx);
}
var tagger = loadTagger('./ipadic');
console.log(tagger.wakati('node.jsで形態素解析をしてみるテスト'));
console.log(tagger.parse('node.jsで形態素解析をしてみるテスト'));
console.log(tagger.parseNBest('node.jsで形態素解析をしてみるテスト', 5));