PK!y -TYYchinesenumber/__init__.pyimport re number_prefix = { 1: '1一弌壱壹幺', 2: '2二弍贰貳两兩', 3: '3三参叁叄仨', 4: '4四肆', 5: '5五伍', 6: '6六陆陸', 7: '7七柒拐', 8: '8八捌', 9: '9九玖勾' } number_multiplier = { 10**(-6): '微', 0.001: '毫毛', 0.01: '厘釐', 0.1: '分割', 0: '0〇零洞', 10: '十拾呀', # 20: '廿念', # 30: '卅', # 40: '卌', 100: '百佰', # 200: '皕', 1000: '千仟', 10**4: '万萬', 10**8: '亿億', 10**12: '兆', 10**16: '京', 10**20: '垓', 10**24: '𥝱秭', 10**28: '穣', 10**32: '溝', 10**36: '澗', 10**40: '正', 10**44: '載', 10**48: '極' } class NumberParser: def __init__(self): self.pre = dict() for k, v in number_prefix.items(): for c in v: self.pre[c] = k self.mul = dict() for k, v in number_multiplier.items(): for c in v: self.mul[c] = k def simple_parse(self, s): v_str_array = re.findall(r'[{pre}]?[{mul}]?'.format( pre=''.join(self.pre.keys()), mul=''.join(self.mul.keys()) ), s) output = 0 for v_str in v_str_array: if len(v_str) == 1: output += float(self.pre.get(v_str[0], self.mul.get(v_str[0]))) elif len(v_str) == 2: output += int(self.pre[v_str[0]]) * float(self.mul[v_str[1]]) return self._coerce_int(output) def numberify(self, s): return re.sub(r'[%s]+' % ( ''.join(self.pre.keys()) + ''.join(self.mul.keys()) ), lambda x: str(self.simple_parse(x.group(0))), s) @staticmethod def _coerce_int(i: float): if i.is_integer(): return int(i) else: return i PK! ::%chinesenumber-0.1.1.dist-info/LICENSEMIT License Copyright (c) 2018 Pacharapol Withayasakpunt Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. PK!HW"TT#chinesenumber-0.1.1.dist-info/WHEEL A н#J."jm)Afb~ ڡ5 G7hiޅF4+-3ڦ/̖?XPK!HT&chinesenumber-0.1.1.dist-info/METADATATn@SCCl"YjD5%"dboUewޡ+O Y;fvo~?{&+t<8[.b xt 2)M@sn 4g;mh&7"DYhmT1jsFaH*BM*_۽KKpNJ)㬁kʁZ\R5 y>N/^0vaihXN%!d'ZuSelTj(LeZҜߔΌÝG;3'FhG "34w.$,mr֜~Z=ؔ~0(s,Z!U5=tԮʝEWĤVr/<}*B?)Neˡ;LӃ3D蘿`/dx}