-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
53 lines (46 loc) · 1.7 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import numpy as np
NAME = {
'JP': np.array([]), #TODO
'KR': np.array(['마노', '히오리', '메구루',
'코가네', '마미미', '사쿠야', '유이카', '키리코',
'카호', '치요코', '린제', '나츠하', '쥬리',
'아마나', '텐카', '치유키',
'아사히', '후유코', '메이',
'토오루', '마도카', '코이토', '히나나',
]),
'EN': np.array(['mano', 'hiori', 'meguru',
'kogane', 'mamimi', 'sakyua', 'yuika', 'kiriko',
'kaho', 'chiyoko', 'rinze', 'natsuha', 'juri',
'amana', 'tenka', 'chiyuki',
'asahi', 'fuyuko', 'mei',
'toru', 'madoka', 'koito', 'hinana', ])
}
# TODO: later use textblob
# -1: ValueError, -2:name not found
def name_text_to_num(name, lang=None):
if lang is not None:
if not isinstance(lang, str):
# raise Warning('inappropriate lang') # TODO find for all langs
# return -1
raise ValueError('inappropriate lang')
lang = lang[:2].upper()
if not lang in NAME:
# raise Warning('inappropriate lang') # TODO find for all langs
# return -1
raise ValueError('inappropriate lang')
target = NAME[lang]
if not isinstance(name, str):
# return -2
raise ValueError('inappropriate name')
name = name.lower()
if np.isin(name, target):
return np.argmax(target == name)
else:
return -2
def main():
name = 'Meguru'
lang = 'en'
a = name_text_to_num(name, lang)
print(a)
if __name__ == '__main__':
main()