Skip to content

Instantly share code, notes, and snippets.

@zk-phi
Created February 13, 2019 09:02
Show Gist options
  • Save zk-phi/897529c62e3f73b5c292e5abf881c8a2 to your computer and use it in GitHub Desktop.
Save zk-phi/897529c62e3f73b5c292e5abf881c8a2 to your computer and use it in GitHub Desktop.
genshijin.el
;; Usage: M-x genshify-region
(defun genshify-string (str)
(let ((res (shell-command-to-string
(concat "echo " (shell-quote-argument str) "| /usr/local/bin/mecab"))))
(mapconcat 'identity
(delq nil
(mapcar (lambda (line)
(cond ((string-match "助詞\\|接頭詞\\|非自立\\|^\\(EOS\\)?$" line) nil)
((string-match "*$" line) (car (split-string line)))
(t (car (last (split-string line ","))))))
(split-string res "\n")))
" ")))
(defun genshify-region (b e)
(interactive "r")
(let ((str (genshify-string (buffer-substring b e))))
(delete-region b e)
(insert str)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment