mirror of
https://github.com/nvbn/thefuck.git
synced 2025-03-14 14:48:49 +00:00
switch korean letters to english
This commit is contained in:
parent
4f165bf6df
commit
ad8f1e5163
@ -9,7 +9,8 @@ from thefuck.types import Command
|
||||
Command(u'фзе-пуе', 'command not found: фзе-пуе'),
|
||||
Command(u'λσ', 'command not found: λσ'),
|
||||
Command(u'שפא-עקא', 'command not found: שפא-עקא'),
|
||||
Command(u'ךד', 'command not found: ךד')])
|
||||
Command(u'ךד', 'command not found: ךד'),
|
||||
Command(u'녀애 ㅣㄴ', 'command not found: 녀애 ㅣㄴ')])
|
||||
def test_match(command):
|
||||
assert switch_lang.match(command)
|
||||
|
||||
@ -19,7 +20,8 @@ def test_match(command):
|
||||
Command(u'ls', 'command not found: ls'),
|
||||
Command(u'агсл', 'command not found: агсл'),
|
||||
Command(u'фзе-пуе', 'some info'),
|
||||
Command(u'שפא-עקא', 'some info')])
|
||||
Command(u'שפא-עקא', 'some info'),
|
||||
Command(u'녀애 ㅣㄴ', 'some info')])
|
||||
def test_not_match(command):
|
||||
assert not switch_lang.match(command)
|
||||
|
||||
@ -28,6 +30,8 @@ def test_not_match(command):
|
||||
(Command(u'фзе-пуе штыефдд мшь', ''), 'apt-get install vim'),
|
||||
(Command(u'λσ -λα', ''), 'ls -la'),
|
||||
(Command(u'שפא-עקא ןמדאשךך הןצ', ''), 'apt-get install vim'),
|
||||
(Command(u'ךד -ךש', ''), 'ls -la')])
|
||||
(Command(u'ךד -ךש', ''), 'ls -la'),
|
||||
(Command(u'멧-ㅎㄷㅅ ㅑㅜㄴㅅ미ㅣ 퍄ㅡ', ''), 'apt-get install vim'),
|
||||
(Command(u'ㅣㄴ -ㅣㅁ', ''), 'ls- la')])
|
||||
def test_get_new_command(command, new_command):
|
||||
assert switch_lang.get_new_command(command) == new_command
|
||||
|
@ -5,13 +5,15 @@ target_layout = '''qwertyuiop[]asdfghjkl;'zxcvbnm,./QWERTYUIOP{}ASDFGHJKL:"ZXCVB
|
||||
# any new keyboard layout must be appended
|
||||
|
||||
greek = u''';ςερτυθιοπ[]ασδφγηξκλ΄ζχψωβνμ,./:΅ΕΡΤΥΘΙΟΠ{}ΑΣΔΦΓΗΞΚΛ¨"ΖΧΨΩΒΝΜ<>?'''
|
||||
korean = u'''ㅂㅈㄷㄱㅅㅛㅕㅑㅐㅔ[]ㅁㄴㅇㄹㅎㅗㅓㅏㅣ;'ㅋㅌㅊㅍㅠㅜㅡ,./ㅃㅉㄸㄲㅆㅛㅕㅑㅒㅖ{}ㅁㄴㅇㄹㅎㅗㅓㅏㅣ:"ㅋㅌㅊㅍㅠㅜㅡ<>?'''
|
||||
|
||||
source_layouts = [u'''йцукенгшщзхъфывапролджэячсмитьбю.ЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮ,''',
|
||||
u'''йцукенгшщзхїфівапролджєячсмитьбю.ЙЦУКЕНГШЩЗХЇФІВАПРОЛДЖЄЯЧСМИТЬБЮ,''',
|
||||
u'''ضصثقفغعهخحجچشسیبلاتنمکگظطزرذدپو./ًٌٍَُِّْ][}{ؤئيإأآة»«:؛كٓژٰٔء><؟''',
|
||||
u''';ςερτυθιοπ[]ασδφγηξκλ΄ζχψωβνμ,./:΅ΕΡΤΥΘΙΟΠ{}ΑΣΔΦΓΗΞΚΛ¨"ΖΧΨΩΒΝΜ<>?''',
|
||||
u'''/'קראטוןםפ][שדגכעיחלךף,זסבהנמצתץ.QWERTYUIOP{}ASDFGHJKL:"ZXCVBNM<>?''',
|
||||
greek]
|
||||
|
||||
greek,
|
||||
korean]
|
||||
|
||||
source_to_target = {
|
||||
greek: {u';': "q", u'ς': "w", u'ε': "e", u'ρ': "r", u'τ': "t", u'υ': "y",
|
||||
@ -30,6 +32,19 @@ source_to_target = {
|
||||
u'Ώ': "V"},
|
||||
}
|
||||
|
||||
'''Lists used for decomposing korean letters.'''
|
||||
HEAD_LIST = ['ㄱ', 'ㄲ', 'ㄴ', 'ㄷ', 'ㄸ', 'ㄹ', 'ㅁ', 'ㅂ', 'ㅃ', 'ㅅ', 'ㅆ',
|
||||
'ㅇ', 'ㅈ', 'ㅉ', 'ㅊ', 'ㅋ', 'ㅌ', 'ㅍ', 'ㅎ']
|
||||
BODY_LIST = ['ㅏ', 'ㅐ', 'ㅑ', 'ㅒ', 'ㅓ', 'ㅔ', 'ㅕ', 'ㅖ', 'ㅗ', 'ㅘ', 'ㅙ',
|
||||
'ㅚ', 'ㅛ', 'ㅜ', 'ㅝ', 'ㅞ', 'ㅟ', 'ㅠ', 'ㅡ', 'ㅢ', 'ㅣ']
|
||||
TAIL_LIST = [' ', 'ㄱ', 'ㄲ', 'ㄳ', 'ㄴ', 'ㄵ', 'ㄶ', 'ㄷ', 'ㄹ', 'ㄺ', 'ㄻ',
|
||||
'ㄼ', 'ㄽ', 'ㄾ', 'ㄿ', 'ㅀ', 'ㅁ', 'ㅂ', 'ㅄ', 'ㅅ', 'ㅆ', 'ㅇ', 'ㅈ',
|
||||
'ㅊ', 'ㅋ', 'ㅌ', 'ㅍ', 'ㅎ']
|
||||
DOUBLE_LIST = ['ㅘ', 'ㅙ', 'ㅚ', 'ㅝ', 'ㅞ', 'ㅟ', 'ㅢ', 'ㄳ', 'ㄵ', 'ㄶ', 'ㄺ',
|
||||
'ㄻ', 'ㄼ', 'ㄽ', 'ㄾ', 'ㅀ', 'ㅄ']
|
||||
DOUBLE_MOD_LIST = ['ㅗㅏ', 'ㅗㅐ', 'ㅗㅣ', 'ㅜㅓ', 'ㅜㅔ', 'ㅜㅣ', 'ㅡㅣ', 'ㄱㅅ',
|
||||
'ㄴㅈ', 'ㄴㅎ', 'ㄹㄱ', 'ㄹㅁ', 'ㄹㅂ', 'ㄹㅅ', 'ㄹㅌ', 'ㄹㅎ', 'ㅂㅅ']
|
||||
|
||||
|
||||
@memoize
|
||||
def _get_matched_layout(command):
|
||||
@ -63,9 +78,34 @@ def _switch_command(command, layout):
|
||||
return ''.join(_switch(ch, layout) for ch in command.script)
|
||||
|
||||
|
||||
def _decompose_korean(command):
|
||||
def _change_double(ch):
|
||||
if ch in DOUBLE_LIST:
|
||||
return DOUBLE_MOD_LIST[DOUBLE_LIST.index(ch)]
|
||||
else:
|
||||
return ch
|
||||
|
||||
hg_str = ''
|
||||
for ch in command.script:
|
||||
if '가' <= ch <= '힣':
|
||||
ord_ch = ord(ch) - ord('가')
|
||||
hd = ord_ch // 588
|
||||
bd = (ord_ch - 588 * hd) // 28
|
||||
tl = ord_ch - 588 * hd - 28 * bd
|
||||
for ch in [HEAD_LIST[hd], BODY_LIST[bd], TAIL_LIST[tl]]:
|
||||
if ch != ' ':
|
||||
hg_str += _change_double(ch)
|
||||
else:
|
||||
hg_str += _change_double(ch)
|
||||
return hg_str
|
||||
|
||||
|
||||
def match(command):
|
||||
if 'not found' not in command.output:
|
||||
return False
|
||||
if any(['ㄱ' <= ch <= 'ㅎ' or 'ㅏ' <= ch <= 'ㅣ' or '가' <= ch <= '힣'
|
||||
for ch in command.script]):
|
||||
command.script = _decompose_korean(command)
|
||||
|
||||
matched_layout = _get_matched_layout(command)
|
||||
return (matched_layout and
|
||||
|
Loading…
x
Reference in New Issue
Block a user