Created
February 13, 2019 09:02
-
-
Save zk-phi/897529c62e3f73b5c292e5abf881c8a2 to your computer and use it in GitHub Desktop.
genshijin.el
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
;; 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