Today is 02/22 (Cat Day), so I tried to summarize it. → If you notice, the date will come again, and it will be in time for 02/22!
It's usually hard to read and it's embarrassing, so I'll write it normally after that.
I made a quick and easy one using Google colaboratory. To put it simply, it's a Jupyter Notebook environment that can be used free of charge from a browser provided by Google. You can also access, edit and execute from your smartphone. (Very convenient)
The libraries used are as follows.
Library name | Contents | Link |
---|---|---|
pykakasi | Japanese (Kanji / Hiragana / Katakana) → Romaji conversion | https://github.com/miurahr/pykakasi |
romkan | Romaji → Japanese (Hiragana / Katakana) conversion | https://pypi.org/project/romkan/ |
pip install git+https://github.com/miurahr/pykakasi romkan
python
# coding: utf-8
from pykakasi import kakasi
import romkan
#Japanese → Romaji
def j2roma(jtext):
kakasi_ = kakasi()
kakasi_.setMode('H', 'a') #Hiragana → Romaji
kakasi_.setMode('K', 'a') #Katakana → Romaji
#kakasi_.setMode('J', 'a') #Kanji → Romaji
kakasi_.setMode("s", True) #Word-separation
conv = kakasi_.getConverter()
#print(jtext)
return conv.do(jtext)
#char_list = list(conv.do(filename))
#print(char_list)
#Convert like a cat (add romaji to convert here)
def s2h(rtext):
dst = rtext.replace("na","nya")
dst = dst.replace("ta","tanya")
dst = dst.replace("da","danya")
return dst
#Romaji → Japanese
def roma2j(rtext):
return romkan.to_hiragana(rtext)
#Main
def nyaa(jtext):
rtext = j2roma(jtext)
rnyan = s2h(rtext)
jnyan = roma2j(rnyan)
return jnyan
Run
nyaa("Meros was furious. I decided that I had to get rid of the king of the evil wisdom and violence.")
result
'Merosu was furious. Inevitably, I decided that I had to get rid of the king of the evil wisdom and violence.'
It looks like that unexpectedly, and the cat is cute.