Corrected for special cases of currency and year

This commit is contained in:
mdc
2016-03-21 16:11:54 +01:00
parent 8fff34e318
commit b1bbe109fc

View File

@@ -39,7 +39,8 @@ class Num2Word_DK(lang_EU.Num2Word_EU):
"tolv", "elleve", "ti", "ni", "otte", "tolv", "elleve", "ti", "ni", "otte",
"syv", "seks", "fem", "fire", "tre", "to", "syv", "seks", "fem", "fire", "tre", "to",
"et", "nul"] "et", "nul"]
self.ords = { "en" : "f\xf8rste", self.ords = { "nul" : "nul",
"et" : "f\xf8rste",
"to" : "anden", "to" : "anden",
"tre" : "tredje", "tre" : "tredje",
"fire" : "fjerde", "fire" : "fjerde",
@@ -51,7 +52,14 @@ class Num2Word_DK(lang_EU.Num2Word_EU):
"ti" : "tiende", "ti" : "tiende",
"elleve" : "ellevte", "elleve" : "ellevte",
"tolv" : "tolvte", "tolv" : "tolvte",
"tyve" : "tyvende" } "tretten" : "trett",
"fjorten" : "fjort",
"femten" : "femt",
"seksten" : "sekst",
"sytten" : "sytt",
"atten" : "att",
"nitten" : "nitt",
"tyve" : "tyv"}
def merge(self, curr, next): def merge(self, curr, next):
ctext, cnum, ntext, nnum = curr + next ctext, cnum, ntext, nnum = curr + next
@@ -69,8 +77,10 @@ class Num2Word_DK(lang_EU.Num2Word_EU):
ctext += " " ctext += " "
val = cnum * nnum val = cnum * nnum
else: else:
if cnum >= 100 and cnum < 10000: if cnum >= 100 and cnum < 1000:
ctext += "og" ctext += " og "
elif cnum >= 1000 and cnum <= 100000:
ctext += "e og "
if nnum < 10 < cnum < 100: if nnum < 10 < cnum < 100:
if nnum == 1: if nnum == 1:
ntext = "en" ntext = "en"
@@ -91,18 +101,33 @@ class Num2Word_DK(lang_EU.Num2Word_EU):
if outword.endswith(key): if outword.endswith(key):
outword = outword[:len(outword) - len(key)] + self.ords[key] outword = outword[:len(outword) - len(key)] + self.ords[key]
break break
return outword + "ende" if value %100 >= 30 and value %100 <= 39 or value %100 == 0:
outword += "te"
elif value % 100 > 12 or value %100 == 0:
outword += "ende"
return outword
def to_ordinal_num(self, value): def to_ordinal_num(self, value):
self.verify_ordinal(value) self.verify_ordinal(value)
vaerdte = (0,1,5,6,11,12)
if value %100 >= 30 and value %100 <= 39 or value % 100 in vaerdte:
return str(value) + "te"
elif value % 100 == 2:
return str(value) + "en"
return str(value) + "ende" return str(value) + "ende"
def to_currency(self, val, longval=True): def to_currency(self, val, longval=True):
if val//100 == 1 or val == 1:
ret = self.to_splitnum(val, hightxt="kr", lowtxt="\xf8re",
jointxt="og",longval=longval)
return "en " + ret[3:]
return self.to_splitnum(val, hightxt="kr", lowtxt="\xf8re", return self.to_splitnum(val, hightxt="kr", lowtxt="\xf8re",
jointxt="og",longval=longval) jointxt="og",longval=longval)
def to_year(self, val, longval=True): def to_year(self, val, longval=True):
if val == 1:
return 'en'
if not (val//100)%10: if not (val//100)%10:
return self.to_cardinal(val) return self.to_cardinal(val)
return self.to_splitnum(val, hightxt="hundrede", longval=longval) return self.to_splitnum(val, hightxt="hundrede", longval=longval)
@@ -114,17 +139,16 @@ to_ordnum = n2w.to_ordinal_num
to_year = n2w.to_year to_year = n2w.to_year
def main(): def main():
#print to_card(308)
for val in [ 1, 11, 12, 21, 31, 33, 71, 80, 81, 91, 99, 100, 101, 102, 155, for val in [ 1, 11, 12, 21, 31, 33, 71, 80, 81, 91, 99, 100, 101, 102, 155,
180, 300, 308, 832, 1000, 1001, 1061, 1100, 1500, 1701, 3000, 180, 300, 308, 832, 1000, 1001, 1061, 1100, 1500, 1701, 3000,
8280, 8291, 150000, 500000, 1000000, 2000000, 2000001, 8280, 8291, 150000, 500000, 1000000, 2000000, 2000001,
-21212121211221211111, -2.121212, -1.0000100]: -21212121211221211111, -2.121212, -1.0000100]:
n2w.test(val) n2w.test(val)
n2w.test(1325325436067876801768700107601001012212132143210473207540327057320957032975032975093275093275093270957329057320975093272950730) n2w.test(1325325436067876801768700107601001012212132143210473207540327057320957032975032975093275093275093270957329057320975093272950730)
for val in [1,120,1000,1120,1800, 1976,2000,2010,2099,2171]: for val in [1,120, 160, 1000,1120,1800, 1976,2000,2010,2099,2171]:
print val, "er", n2w.to_currency(val) print val, "er", n2w.to_currency(val)
print val, "er", n2w.to_year(val) print val, "er", n2w.to_year(val)
n2w.test(65132)
if __name__ == "__main__": if __name__ == "__main__":
main() main()