File indexing completed on 2024-05-12 05:47:02

0001 # -*- coding: UTF-8 -*
0002 
0003 """
0004 Retain only Katakana words in the text, separated by spaces.
0005 
0006 @author: Chusslove Illich (Часлав Илић) <caslav.ilic@gmx.net>
0007 @license: GPLv3
0008 """
0009 
0010 
0011 def katakana (text):
0012     """
0013     Type F1A hook.
0014 
0015     @return: text
0016     """
0017 
0018     ntext = []
0019     for i in range(len(text)):
0020         c = text[i]
0021         if _is_katakana(c):
0022             ntext.append(c)
0023         elif c == "・":
0024             c_prev = text[i-1:i]
0025             c_next = text[i+1:i+2]
0026             if _is_katakana(c_prev) and _is_katakana(c_next):
0027                 ntext.append(c)
0028         else:
0029             if ntext and ntext[-1] != " ":
0030                 ntext.append(" ")
0031     ntext = ("".join(ntext)).strip()
0032     return ntext
0033 
0034 
0035 def _is_katakana (c):
0036 
0037     return (c >= "ァ" and c <= "ヴ") or c == "ー"
0038