Fork Me on GitHub

Node-kytea

Node.js binding of KyTea

Download this project as a .zip file Download this project as a tar.gz file

node-kytea

node-kytea は単語分割、品詞推定、読み推定を行うテキスト解析器 Kytea を Node.js から利用するための C++ Addon です。

What is KyTea?

See http://www.phontron.com/kytea/index-ja.html.

Usage

var Kytea = require('kytea').Kytea;
var path = '/path/to/model';
var kytea = new Kytea(path, { tagmax: 3 }, function(err){
  if(err) throw err;
  kytea.getAllTags("これはテストです。", function(err,obj){
    for(var i =0; i< obj.length;i++){
      var word = obj[i].surf;
      var pos = obj[i].tags[0];
      var pron = obj[i].tags[1];
    }
  });
});

Methods

new Kytea(modelPath, options, callback)

modelPathで指定されたモデルを読み込み、KyTeaのオブジェクトを作成します。

getWS(text, callback)

単語分割を実行します。

例:

kytea.getWS('これはテストです。',function(err,words){
  ...
});

getTags(text, callback)

getAllTags(text, callback)

タグ推定(品詞、読み等)を実行します。getTags()の場合はタグが複数ある場合は信頼度が最も高い1つのみを取得し、getAllTags()の場合は全てのタグを取得します。

例:

kytea.getAllTags("これはテストです。", function(err, res){
  if(err) throw err;
  res.forEach(function(elm){
    var surf = elm.surf;
    var tags = elm.tags;
    tags.forEach(function(tag){
        var tag_name = tag[0];
        var confidence = tag[1];
        ...
    });
  });
});

なお、コールバック関数の第2引数は以下のようなオブジェクトです。

[
  {
    surf: 'これ', // 単語表記
    tags:[
      [// 1つ目のタグのリスト(この例では品詞)
        ['代名詞', 3.6951145482572487],//タグと信頼度
        ['名詞', 3.7467785662991857]
      ],
      [// 2つ目のタグのリスト(この例では読み) 
        ['これ', 2.3796118434353652],
      ]
    ]
  }
]

Requirement

node-kytea は KyTea 0.4.2 での動作を確認しています。 インストールの前に、こちらから KyTea をダウンロードして、インストールしてください。

Install

KyTea のヘッダ及びライブラのパスがインクルードパス、ライブラリパスに含まれるようにしたうえで、以下のコマンドを実行してください。

npm install kytea

または

git clone git://github.com/hideo55/node-kytea.git
npm install ./node-kytea

License

(The MIT License)

Copyright (c) 2012 Hideaki Ohno <hide.o.j55{at}gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.