|
| 1 | +# -*- encoding: utf-8 -*- |
| 2 | +# Copyright (c) 2003, Taro Ogawa. All Rights Reserved. |
| 3 | +# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved. |
| 4 | + |
| 5 | +# This library is free software; you can redistribute it and/or |
| 6 | +# modify it under the terms of the GNU Lesser General Public |
| 7 | +# License as published by the Free Software Foundation; either |
| 8 | +# version 2.1 of the License, or (at your option) any later version. |
| 9 | +# This library is distributed in the hope that it will be useful, |
| 10 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | +# Lesser General Public License for more details. |
| 13 | +# You should have received a copy of the GNU Lesser General Public |
| 14 | +# License along with this library; if not, write to the Free Software |
| 15 | +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
| 16 | +# MA 02110-1301 USA |
| 17 | + |
| 18 | +from __future__ import unicode_literals |
| 19 | + |
| 20 | +import string |
| 21 | + |
| 22 | +from num2words.base import Num2Word_Base |
| 23 | + |
| 24 | + |
| 25 | +class Num2Word_HI(Num2Word_Base): |
| 26 | + """ |
| 27 | + Hindi (HI) Num2Word class |
| 28 | + """ |
| 29 | + |
| 30 | + _irregular_ordinals = { |
| 31 | + 0: "शून्य", |
| 32 | + 1: "पहला", |
| 33 | + 2: "दूसरा", |
| 34 | + 3: "तीसरा", |
| 35 | + 4: "चौथा", |
| 36 | + 6: "छठा", |
| 37 | + } |
| 38 | + _irregular_ordinals_nums = { |
| 39 | + 0: "०", |
| 40 | + 1: "१ला", |
| 41 | + 2: "२रा", |
| 42 | + 3: "३रा", |
| 43 | + 4: "४था", |
| 44 | + 6: "६ठा", |
| 45 | + } |
| 46 | + _hindi_digits = "०१२३४५६७८९" # 0-9 |
| 47 | + _digits_to_hindi_digits = dict(zip(string.digits, _hindi_digits)) |
| 48 | + _regular_ordinal_suffix = "वाँ" |
| 49 | + |
| 50 | + def setup(self): |
| 51 | + # Note: alternative forms are informal |
| 52 | + self.low_numwords = [ |
| 53 | + "निन्यानवे", |
| 54 | + "अट्ठानवे", |
| 55 | + "सत्तानवे", # alternative "सतानवे" |
| 56 | + "छियानवे", |
| 57 | + "पचानवे", |
| 58 | + "चौरानवे", |
| 59 | + "तिरानवे", |
| 60 | + "बानवे", |
| 61 | + "इक्यानवे", |
| 62 | + "नब्बे", |
| 63 | + "नवासी", |
| 64 | + "अट्ठासी", |
| 65 | + "सतासी", |
| 66 | + "छियासी", |
| 67 | + "पचासी", |
| 68 | + "चौरासी", |
| 69 | + "तिरासी", |
| 70 | + "बयासी", |
| 71 | + "इक्यासी", |
| 72 | + "अस्सी", |
| 73 | + "उनासी", # alternative "उन्नासी" |
| 74 | + "अठहत्तर", # alternative "अठहतर" |
| 75 | + "सतहत्तर", # alternative "सतहतर" |
| 76 | + "छिहत्तर", # alternative "छिहतर" |
| 77 | + "पचहत्तर", # alternative "पचहतर" |
| 78 | + "चौहत्तर", # alternative "चौहतर" |
| 79 | + "तिहत्तर", # alternative "तिहतर" |
| 80 | + "बहत्तर", # alternative "बहतर" |
| 81 | + "इकहत्तर", # alternative "इकहतर" |
| 82 | + "सत्तर", |
| 83 | + "उनहत्तर", # alternative "उनहतर" |
| 84 | + "अड़सठ", # alternative "अड़सठ" |
| 85 | + "सड़सठ", # alternative "सड़सठ" |
| 86 | + "छियासठ", |
| 87 | + "पैंसठ", |
| 88 | + "चौंसठ", |
| 89 | + "तिरसठ", |
| 90 | + "बासठ", |
| 91 | + "इकसठ", |
| 92 | + "साठ", |
| 93 | + "उनसठ", |
| 94 | + "अट्ठावन", # alternative "अठावन" |
| 95 | + "सत्तावन", # alternative "सतावन" |
| 96 | + "छप्पन", |
| 97 | + "पचपन", |
| 98 | + "चौवन", |
| 99 | + "तिरेपन", # alternative "तिरपन" |
| 100 | + "बावन", |
| 101 | + "इक्यावन", |
| 102 | + "पचास", |
| 103 | + "उनचास", |
| 104 | + "अड़तालीस", # alternative "अड़तालीस" |
| 105 | + "सैंतालीस", |
| 106 | + "छियालीस", # alternative "छयालिस" |
| 107 | + "पैंतालीस", |
| 108 | + "चौवालीस", # alternative "चवालीस" |
| 109 | + "तैंतालीस", # alternative "तैतालीस" |
| 110 | + "बयालीस", |
| 111 | + "इकतालीस", |
| 112 | + "चालीस", |
| 113 | + "उनतालीस", |
| 114 | + "अड़तीस", # alternative "अड़तीस" |
| 115 | + "सैंतीस", |
| 116 | + "छत्तीस", # alternative "छतीस" |
| 117 | + "पैंतीस", |
| 118 | + "चौंतीस", |
| 119 | + "तैंतीस", |
| 120 | + "बत्तीस", # alternative "बतीस" |
| 121 | + "इकत्तीस", # alternative "इकतीस" |
| 122 | + "तीस", |
| 123 | + "उनतीस", |
| 124 | + "अट्ठाईस", # alternative "अट्ठाइस" |
| 125 | + "सत्ताईस", # alternative "सताइस" |
| 126 | + "छब्बीस", |
| 127 | + "पच्चीस", |
| 128 | + "चौबीस", |
| 129 | + "तेईस", # alternative "तेइस" |
| 130 | + "बाईस", |
| 131 | + "इक्कीस", # alternative "इकीस" |
| 132 | + "बीस", |
| 133 | + "उन्नीस", |
| 134 | + "अट्ठारह", # alternative "अठारह" |
| 135 | + "सत्रह", |
| 136 | + "सोलह", |
| 137 | + "पंद्रह", |
| 138 | + "चौदह", |
| 139 | + "तेरह", |
| 140 | + "बारह", |
| 141 | + "ग्यारह", |
| 142 | + "दस", |
| 143 | + "नौ", |
| 144 | + "आठ", |
| 145 | + "सात", |
| 146 | + "छः", # alternative "छह" |
| 147 | + "पाँच", # alternative "पांच" |
| 148 | + "चार", |
| 149 | + "तीन", |
| 150 | + "दो", |
| 151 | + "एक", |
| 152 | + "शून्य", |
| 153 | + ] |
| 154 | + |
| 155 | + self.mid_numwords = [(100, "सौ")] |
| 156 | + self.high_numwords = [ |
| 157 | + (11, "ख़रब"), |
| 158 | + (9, "अरब"), |
| 159 | + (7, "करोड़"), # alternative "करोड़" |
| 160 | + (5, "लाख"), |
| 161 | + (3, "हज़ार"), # alternative "हज़ार" |
| 162 | + ] |
| 163 | + self.pointword = "दशमलव" |
| 164 | + self.negword = "माइनस " |
| 165 | + |
| 166 | + def set_high_numwords(self, high): |
| 167 | + for n, word in self.high_numwords: |
| 168 | + self.cards[10**n] = word |
| 169 | + |
| 170 | + def merge(self, lpair, rpair): |
| 171 | + ltext, lnum = lpair |
| 172 | + rtext, rnum = rpair |
| 173 | + if lnum == 1 and rnum < 100: |
| 174 | + return rtext, rnum |
| 175 | + elif 100 > lnum > rnum: |
| 176 | + return "%s-%s" % (ltext, rtext), lnum + rnum |
| 177 | + elif lnum >= 100 > rnum: |
| 178 | + return "%s %s" % (ltext, rtext), lnum + rnum |
| 179 | + elif rnum > lnum: |
| 180 | + return "%s %s" % (ltext, rtext), lnum * rnum |
| 181 | + return "%s %s" % (ltext, rtext), lnum + rnum |
| 182 | + |
| 183 | + def to_ordinal(self, value): |
| 184 | + if value in self._irregular_ordinals: |
| 185 | + return self._irregular_ordinals[value] |
| 186 | + |
| 187 | + # regular Hindi ordinals are derived from cardinals |
| 188 | + # by modifying the last member of the expression. |
| 189 | + cardinal = self.to_cardinal(value) |
| 190 | + return cardinal + self._regular_ordinal_suffix |
| 191 | + |
| 192 | + def _convert_to_hindi_numerals(self, value): |
| 193 | + return "".join(map(self._digits_to_hindi_digits.__getitem__, |
| 194 | + str(value))) |
| 195 | + |
| 196 | + def to_ordinal_num(self, value): |
| 197 | + if value in self._irregular_ordinals_nums: |
| 198 | + return self._irregular_ordinals_nums[value] |
| 199 | + |
| 200 | + return self._convert_to_hindi_numerals(value) \ |
| 201 | + + self._regular_ordinal_suffix |
0 commit comments