Skip to content

Instantly share code, notes, and snippets.

@kakajika
Created September 1, 2016 11:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kakajika/a431a0228ad80c36baf5a554992df9c3 to your computer and use it in GitHub Desktop.
Save kakajika/a431a0228ad80c36baf5a554992df9c3 to your computer and use it in GitHub Desktop.
Hubot script for showing result of kuromoji.
# 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