It's Cat Day, so I tried to make something that translates into cat-like words.

Why did you put it together?

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.

What is the environment?

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)

how?

  1. Convert input Japanese to Romaji (library: using pykakasi)
  2. Convert Romaji to cat-like (just replace)
  3. Reconvert Romaji to Japanese (library: using romkan)
  4. Above

What about the actual contents?

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/
Crisp library installation
pip install git+https://github.com/miurahr/pykakasi romkan 
code

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

Execution & result

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.'

Summary

It looks like that unexpectedly, and the cat is cute.

reference

I tried to convert it to Fef sister words using Python

Recommended Posts

It's Cat Day, so I tried to make something that translates into cat-like words.
I tried to make a bot that randomly acquires Wikipedia articles and tweets once a day
I tried to make an activity that collectively sets location information
I tried to make a system that fetches only deleted tweets
[Python] I tried to implement stable sorting, so make a note
I tried to make a calculator with Tkinter so I will write it
I tried to make a skill that Alexa will return as cold
I tried to make a Web API
I tried to publish my own module so that I can pip install it
[Python] I tried to make a Shiritori AI that enhances vocabulary through battles
I tried to make a translation BOT that works on Discord using googletrans
I tried to make a dictionary function that does not distinguish between cases
I tried to make OneHotEncoder, which is often used for data analysis, so that it can reach the itch.
I tried to make AI for Smash Bros.
I tried to make a ○ ✕ game using TensorFlow
I uploaded a module to pypl that deletes Japanese stop words, so share it
I tried to make a memo app that can be pomodoro, but a reflection record
A Python beginner made a chat bot, so I tried to summarize how to make it.
I tried to make a "fucking big literary converter"
Continuation ・ I tried to make Slackbot after studying Python3
I tried to put pytest into the actual battle
I tried to make an OCR application with PySimpleGUI
[Python] I tried to make an application that calculates salary according to working hours with tkinter
[1 hour challenge] I tried to make a fortune-telling site that is too suitable with Python
I want to see something beautiful, so I tried to visualize the function used for benchmarking the optimization function.
I tried to make a generator that generates a C # container class from CSV with Python