Created
September 1, 2016 11:14
-
-
Save kakajika/a431a0228ad80c36baf5a554992df9c3 to your computer and use it in GitHub Desktop.
Hubot script for showing result of kuromoji.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# kuromoji.coffee | |
# | |
# Description: | |
# Bot for detecting ikku pattern. | |
# | |
{tokenize} = require 'kuromojin' | |
{nfkc} = require 'unorm' | |
listit = require 'list-it' | |
formatText = (text) => | |
return nfkc(text | |
.replace /^<.+?>:?/, '' | |
.replace /^[A-z]+ +/, '' # for DM | |
.replace /[「」()\(\)]/g, ' ' | |
) | |
module.exports = (robot) -> | |
robot.hear /kuromoji( | )(.+)/i, (msg) => | |
tokenize(formatText msg.match[2]) | |
.then (tokens) => | |
buf = listit.buffer() | |
buf.d("表層形") | |
.d("品詞") | |
.d("品詞細分類1") | |
.d("品詞細分類2") | |
.d("読み") | |
.d("発音") | |
.nl() | |
tokens.forEach (token) => | |
buf.d(token.surface_form) | |
.d(token.pos) | |
.d(token.pos_detail_1) | |
.d(token.pos_detail_2) | |
.d(token.reading) | |
.d(token.pronunciation) | |
.nl() | |
msg.send "```#{buf.toString()}```" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment