A code that corrects the yoon / sokuon (sokuon)

With older systems, payment processing may not be accepted if the name of the bank account uses a yoon or a sokuon.

The system (SQLserver) of the company I work for is exactly that, and in the case of manual input, it does not accept yoon and sokuon, but if it is copy and paste etc. it slips in and an error occurs when payment processing is applied. ... (depending on the bank) was not a little. Also, as a future plan, I want to extract the data from the document (created in Excel) to be registered in the system and post it directly to SQL server with pyodbc, so I do not correct the yoon / sokuon at that time at the latest. It was necessary to write such a code because it would follow the same rut as, and if I wrote it with an idea, it worked reasonably well.

That's why there may not be much demand, but I will make my debut on Qiita here!

code


you_soku = 'ァ ゥ ゥ ゥ ァ'
print('Change before-->', you_soku)    #For confirmation

ys_dict = {'ァ': 'A', 'I': 'I', 'ゥ': 'C', 'E': 'E', 'Oh': 'O', '㽬': 'ヤ', 'Shu': 'Yu', 'YO': 'Yo', 'Tsu': 'Tsu'}
for ys in ys_dict.keys():
    while ys in you_soku:
        you_soku = you_soku.replace(ys, ys_dict[ys])
print('After change-->', you_soku)    #For confirmation

Output result


Change before-->ァ ゥ ゥ ゥ ァ
After change-->Yayuyo

Loop the yoon / sokuon dictionary and replace the character (value) corresponding to the key as long as the key is in the target character string (in the above case, in the character string stored in you_soku). There is. As some of you may have noticed, if you change the variable of the nested target string (you_soku in the above case), you will end up in an infinite loop. .. (Actually, it ’s the mouth I did w)

I will try it under the name of an account that is likely to actually exist. Of course, he is a fictional person. (It's a light name like a rock musician, but I'm not a fan.)

code


account_name = 'Kikkawa Shoji'
print('Change before-->', account_name)    #For confirmation

ys_dict = {'ァ': 'A', 'I': 'I', 'ゥ': 'C', 'E': 'E', 'Oh': 'O', '㽬': 'ヤ', 'Shu': 'Yu', 'YO': 'Yo', 'Tsu': 'Tsu'}
for ys in ys_dict.keys():
    while ys in account_name:
        account_name = account_name.replace(ys, ys_dict[ys])
print('After change-->', account_name)    #For confirmation

Output result


Change before-->Kikkawa Shoji
After change-->Kiwashi

Normally, the system should handle it so that it is not necessary to use such code. Well, it doesn't start even if I say it, so I wrote it.

We welcome your suggestions and opinions. I'm still an apprentice, so I'd like you to put in a tsukkomi frankly.

Recommended Posts

A code that corrects the yoon / sokuon (sokuon)
# Function that returns the character code of a string
A class that hits the DMM API
[Python] A program that rounds the score
A model that identifies the guitar with fast.ai
[Django] Create a form that automatically fills in the address from the zip code
A shell program that displays the Fibonacci sequence
A story that reduces the effort of operation / maintenance
[Python] A program that counts the number of valleys
Create a QR code for the URL on Linux
A story that struggled with the common set HTTP_PROXY = ~
Generate that shape of the bottom of a PET bottle
A memo that I touched the Datastore with python
A story that analyzed the delivery of Nico Nama.
[Python] A program that compares the positions of kangaroos.
A tool that automatically turns the gacha of a social game
Create a QR code that displays "Izumi Oishi" by scratch
A string permutation code that uses an algorithm that generates permutations.
Let's make a robot that solves the Rubik's Cube! 2 Algorithm
Creating a Python script that supports the e-Stat API (ver.2)
A shell script that just emails the SQL execution result
Let's make a robot that solves the Rubik's Cube! 3 Software
Create code that outputs "A and pretending B" in python
A program that just presses and releases the Esc key
The story that Python stopped working with VS Code (Windows 10)
Is there a bias in the numbers that appear in the Fibonacci numbers?
[Python] A program that finds the most common bird types
A memo that solves the knapsack problem by the greedy algorithm
A script that displays the running CloudFormation stack like a mannequin
[Golang] A program that determines the turn with random numbers
A Python script that compares the contents of two directories
I wrote a script that splits the image in two