python3 kanjiextract.py
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
#/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) |
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
updated regex:
blacklist = r'[ぁ-ゟa-zA-Z0-9゠-ヿ〜「」。、 ?\n]'