Skip to content

Instantly share code, notes, and snippets.

@greymd
Created January 20, 2015 14:30
Show Gist options
  • Save greymd/352f9a6ec70d2a5f607f to your computer and use it in GitHub Desktop.
Save greymd/352f9a6ec70d2a5f607f to your computer and use it in GitHub Desktop.
「メロスは激怒した」と同じような語感を持つ文を「走れメロス」から抜き出す
# 形態素解析器を使うのでmecabを事前にインストールされたし
# % brew install mecab
# 青空文庫から「走れメロス」を取得
$ w3m -dump http://www.aozora.gr.jp/cards/000035/files/1567_14913.html | \
mecab | awk -F',' '$0=$1' | awk 'NF==2' | \
egison -F1s -s '(match-all-lambda (list [string string])[<join _ <cons [$a ,"名詞"] <cons [$b ,"助詞"] <cons [$c ,"名詞"] <cons [$d ,"動詞"] <cons [$e ,"助動詞"]>>>>>> [a b c d e]])'
# Result
# ["メロス" "は" "激怒" "し" "た"]
# ["メロス" "が" "嘲笑" "し" "た"]
# ["村" "へ" "到着" "し" "た"]
# ["出発" "を" "決意" "し" "た"]
# ["矢" "の" "如く" "走り出" "た"]
# ["半ば" "に" "到達" "し" "た"]
# ["メロス" "も" "覚悟" "し" "た"]
# ["闘争" "を" "開始" "し" "た"]
# ["隅" "に" "巣" "喰っ" "た"]
# ["これ" "ほど" "努力" "し" "た"]
# ["私" "の" "定" "っ" "た"]
# ["濁流" "を" "突破" "し" "た"]
# ["刑場" "に" "突入" "し" "た"]
# ["君" "と" "抱擁" "でき" "ない"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment