Last active
September 15, 2016 13:29
-
-
Save boronology/14c3c075be29c5e47372be9ac24eecbf to your computer and use it in GitHub Desktop.
言語処理100本ノック http://www.cl.ecei.tohoku.ac.jp/nlp100/
This file contains hidden or 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
#第3章: 正規表現 | |
#前準備 | |
wget http://www.cl.ecei.tohoku.ac.jp/nlp100/data/jawiki-country.json.gz | |
#20. JSONデータの読み込み | |
zcat jawiki-country.json.gz |jq 'select(.title=="イギリス")' > uk.txt | |
#21. カテゴリ名を含む行を抽出 | |
cat uk.txt|jq ".text" --raw-output| grep Category: | |
#22. カテゴリ名の抽出 | |
#↓でいいんだろうか……? | |
cat uk.txt|jq ".text" --raw-output| grep Category:|sed -e 's/^\[\[Category://' -e 's/\]\]$//' | |
#|とか*も除去するなら | |
cat uk.txt|jq ".text" --raw-output| grep Category:|sed -e 's/^\[\[Category:\([^]|]*\).*/\1/' | |
#23. セクション構造 | |
#だいぶしんどくなってきたぞ…… | |
cat uk.txt|jq ".text" --raw-output |grep ^=|awk '{print((split($0,A,"=")-3)/2,$0)}'|sed -e 's/=//g' | |
#24. ファイル参照の抽出 | |
#これでいいんだろうか……? | |
cat uk.txt|jq ".text" --raw-output |grep -Ei '(jpg|png)'|sed -e 's/^[^:]*://' -e 's/|.*//' | |
#25. テンプレートの抽出 | |
#辞書オブジェクト……だと? | |
#zshなら連想配列もあるけどこれってPython使えって話ですよね | |
#26. 強調マークアップの除去 | |
#27. 内部リンクの除去 | |
#28. MediaWikiマークアップの除去 | |
#29. 国旗画像のURLを取得する |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment