Skip to content

Instantly share code, notes, and snippets.

@vgmoose
Last active November 5, 2018 16:12
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 vgmoose/77e83889a033a51fa4d1181995b796f6 to your computer and use it in GitHub Desktop.
Save vgmoose/77e83889a033a51fa4d1181995b796f6 to your computer and use it in GitHub Desktop.
python3 kanjiextract.py
#/usr/bin/python3
# -*- coding: utf-8 -*-
import re
# regex for hiragana+katakana and a few more characters
blacklist = r'[ぁ-ゟ゠-ヿ「」。、 ?\n]'
# can be copied and pasted from the PDF including linebreaks between the two sets of """
text = u"""いる
今日私は一日中家にいる。
あなたの事を思い出しています。
その
その人形に名前はありますか?
する
お絵かきをするのが昔から大好きでした。
それ
それは、イカの足ですよね?
うちの家は物で溢れかえっている。
この
この帽子は僕には似合わない。
ある
カレー粉は家にあるの?
そう
そういう言い訳が一番嫌い。
折り紙を一枚ください。
ない
白髪はまだ一本もない。
二階で熊を飼っています。
あなた達はまだ未成年でしょう。
自分
自分の名前も思い出せない。
何をしようとしてたのか忘れました。
私はマフィアの一員です。
言う
猿が「アイスクリームをくれ」と僕に言いました。
人はどうして生まれ、死んで行くのだろう。"""
unique_kanji = set(re.sub(blacklist, '', text))
print(unique_kanji)
@cciollaro
Copy link

blacklist = r'[ぁ-ゟa-zA-Z0-9゠-ヿ>%<!?/〜「」。、 ?\n]'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment