OSDN Git Service

auto suggest keyword implemented.
[rec10/rec10-git.git] / rec10 / trunk / src / zenhan.py
1 #!/usr/bin/python
2 # coding: UTF-8
3 # Rec10 TS Recording Tools
4 # Copyright (C) 2009 Yukikaze
5
6 global z_ascii
7 global h_ascii
8 global z_number
9 global h_number
10 z_ascii = u"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz !”#$%&’()*+,−./:;<=>?@[¥]^_‘{|}〜 "
11 h_ascii = u"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz !\"#$%&'()*+,-./:;<=>?@[\]^_`{|}~ "
12 z_number = u"0123456789"
13 h_number = u"0123456789"
14 z_alphabet = u"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz #"
15 h_alphabet = u"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz #"
16 def toHankaku(str):
17     retstr = u""
18     for s in str:
19         i = z_ascii.find(s)
20         if (i != -1):
21             s = h_ascii[i]
22         i = z_number.find(s)
23         if (i != -1):
24             s = h_number[i]
25         retstr = retstr + s
26     return retstr
27 def toHankaku_ABC123(str):
28     retstr = u""
29     for s in str:
30         i = z_alphabet.find(s)
31         if (i != -1):
32             s = h_alphabet[i]
33         i = z_number.find(s)
34         if (i != -1):
35             s = h_number[i]
36         retstr = retstr + s
37     return retstr
38 def check_Character_Type(character):
39     """
40     return code is 1:Alphabet 2:Hiragana 3:Katakana 4:Kanji
41     """
42     #character=character.encode('UTF-8')
43     chcode=ord(character)
44     #print ord(chcode)
45     if chcode>=0x0000 and chcode<=0x007F:
46         return 1
47     elif chcode>=0x3040 and chcode<=0x309F:
48         return 2
49     elif chcode>=0x30A0 and chcode<=0x30FF:
50         return 3
51     elif chcode>=0x4E00 and chcode<=0x9FFF:
52         return 4