negaposi-analyzer-ja
形態素解析したテキストからネガティブ/ポジティブ(単語感情極性)を判定したスコアを返すJavaScriptライブラリ
Install
Install with npm:
npm install negaposi-analyzer-ja
辞書
辞書には単語感情極性対応表を利用します。 このモジュールには辞書のダウンロードスクリプトが同梱されているので、モジュールをインストール後次のコマンドでダウンロードできます。
./node_modules/.bin/download-negaposi-dict
Usage
CLI
echo "これは良い文章だと思います。" | negaposi-analyzer
# 0.08096107836464397
Node.js
このライブラリ自体は形態素解析をしていません。 形態素解析した結果のtoken配列を引数として受け取ります。
形態素解析にはkuromoji.js(またはラッパーであるkuromojin)を想定しています。
const assert = ;const kuromojin = ;const analyze = ;;
analyze(tokens: Object[], options?: Object): number
kuromojiの形態素解析した結果のtoken配列(tokens
)を受け取り、スコアを返します。
辞書には単語(品詞付き)毎に-1から1の範囲のスコアが設定されています。
analyze
の返すスコアは各単語のスコアを合計をtokenの数で割った値です。
Options
const defaultOptions = // 辞書にない単語のスコア unknownWordRank: 0 // ポジティブな単語に対する補正値(スコアに乗算) positiveCorrections: 1 // ネガティブな単語に対する補正値(スコアに乗算) negativeCorrections: 5122 / 49983 // 辞書の配列 posiNegaDict: ;
デフォルトではネガティブ単語に補正値をかけています。 理由としては、単語感情極性対応表にはネガティブな単語の割合が多いため、 補正値なしでは大体のケースがネガティブと判断されるためです。
const posiNegaRatio = posi: 5122 nega: 49983 zero: 20;
Related
- ネガポジ判定を行うGem作ってみた - Qiita
- ハセテツラボ » PythonでTwitterでのツイートをネガポジ判定してみた結果。。。
- Atrae Tech Blog — 僕が感情豊かであることをネガ・ポジ判定で証明する
Changelog
See Releases page.
Running tests
Install devDependencies and Run npm test
:
npm i -d && npm test
Contributing
Pull requests and stars are always welcome.
For bugs and feature requests, please create an issue.
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
Author
License
MIT © azu
Dictionary
This library not includes the dictionary, but includes download tool.
高村大也, 乾孝司, 奥村学
"スピンモデルによる単語の感情極性抽出", 情報処理学会論文誌ジャーナル, Vol.47 No.02 pp. 627--637, 2006.
Hiroya Takamura, Takashi Inui, Manabu Okumura,
"Extracting Semantic Orientations of Words using Spin Model", In Proceedings of the 43rd Annual Meeting of the Association for Computational Linguistics (ACL2005) , pages 133--140, 2005.