mirror of
https://github.com/bblaz/num2words.git
synced 2025-12-06 06:42:25 +00:00
Merge pull request #98 from williamjmorenor/master
Fix some pep8 issues
This commit is contained in:
@@ -1,2 +1,3 @@
|
|||||||
include CHANGES.rst
|
include CHANGES.rst
|
||||||
include COPYING
|
include COPYING
|
||||||
|
include tests/*
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ CONVERTER_CLASSES = {
|
|||||||
'uk': lang_UK.Num2Word_UK()
|
'uk': lang_UK.Num2Word_UK()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CONVERTES_TYPES = ['cardinal', 'ordinal', 'year', 'currency']
|
CONVERTES_TYPES = ['cardinal', 'ordinal', 'year', 'currency']
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -41,29 +41,24 @@ class Num2Word_Base(object):
|
|||||||
|
|
||||||
self.MAXVAL = 1000 * self.cards.order[0]
|
self.MAXVAL = 1000 * self.cards.order[0]
|
||||||
|
|
||||||
|
|
||||||
def set_numwords(self):
|
def set_numwords(self):
|
||||||
self.set_high_numwords(self.high_numwords)
|
self.set_high_numwords(self.high_numwords)
|
||||||
self.set_mid_numwords(self.mid_numwords)
|
self.set_mid_numwords(self.mid_numwords)
|
||||||
self.set_low_numwords(self.low_numwords)
|
self.set_low_numwords(self.low_numwords)
|
||||||
|
|
||||||
|
|
||||||
def gen_high_numwords(self, units, tens, lows):
|
def gen_high_numwords(self, units, tens, lows):
|
||||||
out = [u + t for t in tens for u in units]
|
out = [u + t for t in tens for u in units]
|
||||||
out.reverse()
|
out.reverse()
|
||||||
return out + lows
|
return out + lows
|
||||||
|
|
||||||
|
|
||||||
def set_mid_numwords(self, mid):
|
def set_mid_numwords(self, mid):
|
||||||
for key, val in mid:
|
for key, val in mid:
|
||||||
self.cards[key] = val
|
self.cards[key] = val
|
||||||
|
|
||||||
|
|
||||||
def set_low_numwords(self, numwords):
|
def set_low_numwords(self, numwords):
|
||||||
for word, n in zip(numwords, range(len(numwords) - 1, -1, -1)):
|
for word, n in zip(numwords, range(len(numwords) - 1, -1, -1)):
|
||||||
self.cards[n] = word
|
self.cards[n] = word
|
||||||
|
|
||||||
|
|
||||||
def splitnum(self, value):
|
def splitnum(self, value):
|
||||||
for elem in self.cards:
|
for elem in self.cards:
|
||||||
if elem > value:
|
if elem > value:
|
||||||
@@ -89,7 +84,6 @@ class Num2Word_Base(object):
|
|||||||
|
|
||||||
return out
|
return out
|
||||||
|
|
||||||
|
|
||||||
def to_cardinal(self, value):
|
def to_cardinal(self, value):
|
||||||
try:
|
try:
|
||||||
assert int(value) == value
|
assert int(value) == value
|
||||||
@@ -110,21 +104,20 @@ class Num2Word_Base(object):
|
|||||||
words, num = self.clean(val)
|
words, num = self.clean(val)
|
||||||
return self.title(out + words)
|
return self.title(out + words)
|
||||||
|
|
||||||
|
|
||||||
def float2tuple(self, value):
|
def float2tuple(self, value):
|
||||||
pre = int(value)
|
pre = int(value)
|
||||||
post = abs(value - pre) * 10**self.precision
|
post = abs(value - pre) * 10**self.precision
|
||||||
if abs(round(post) - post) < 0.01:
|
if abs(round(post) - post) < 0.01:
|
||||||
# We generally floor all values beyond our precision (rather than rounding), but in
|
# We generally floor all values beyond our precision (rather than
|
||||||
# cases where we have something like 1.239999999, which is probably due to python's
|
# rounding), but in cases where we have something like 1.239999999,
|
||||||
# handling of floats, we actually want to consider it as 1.24 instead of 1.23
|
# which is probably due to python's handling of floats, we actually
|
||||||
|
# want to consider it as 1.24 instead of 1.23
|
||||||
post = int(round(post))
|
post = int(round(post))
|
||||||
else:
|
else:
|
||||||
post = int(math.floor(post))
|
post = int(math.floor(post))
|
||||||
|
|
||||||
return pre, post
|
return pre, post
|
||||||
|
|
||||||
|
|
||||||
def to_cardinal_float(self, value):
|
def to_cardinal_float(self, value):
|
||||||
try:
|
try:
|
||||||
float(value) == value
|
float(value) == value
|
||||||
@@ -146,11 +139,9 @@ class Num2Word_Base(object):
|
|||||||
|
|
||||||
return " ".join(out)
|
return " ".join(out)
|
||||||
|
|
||||||
|
|
||||||
def merge(self, curr, next):
|
def merge(self, curr, next):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
|
||||||
def clean(self, val):
|
def clean(self, val):
|
||||||
out = val
|
out = val
|
||||||
while len(val) != 1:
|
while len(val) != 1:
|
||||||
@@ -172,7 +163,6 @@ class Num2Word_Base(object):
|
|||||||
val = out
|
val = out
|
||||||
return out[0]
|
return out[0]
|
||||||
|
|
||||||
|
|
||||||
def title(self, value):
|
def title(self, value):
|
||||||
if self.is_title:
|
if self.is_title:
|
||||||
out = []
|
out = []
|
||||||
@@ -185,30 +175,24 @@ class Num2Word_Base(object):
|
|||||||
value = " ".join(out)
|
value = " ".join(out)
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
def verify_ordinal(self, value):
|
def verify_ordinal(self, value):
|
||||||
if not value == int(value):
|
if not value == int(value):
|
||||||
raise TypeError(self.errmsg_floatord % value)
|
raise TypeError(self.errmsg_floatord % value)
|
||||||
if not abs(value) == value:
|
if not abs(value) == value:
|
||||||
raise TypeError(self.errmsg_negord % value)
|
raise TypeError(self.errmsg_negord % value)
|
||||||
|
|
||||||
|
|
||||||
def verify_num(self, value):
|
def verify_num(self, value):
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
|
||||||
def set_wordnums(self):
|
def set_wordnums(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def to_ordinal(self, value):
|
def to_ordinal(self, value):
|
||||||
return self.to_cardinal(value)
|
return self.to_cardinal(value)
|
||||||
|
|
||||||
|
|
||||||
def to_ordinal_num(self, value):
|
def to_ordinal_num(self, value):
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
# Trivial version
|
# Trivial version
|
||||||
def inflect(self, value, text):
|
def inflect(self, value, text):
|
||||||
text = text.split("/")
|
text = text.split("/")
|
||||||
@@ -216,8 +200,7 @@ class Num2Word_Base(object):
|
|||||||
return text[0]
|
return text[0]
|
||||||
return "".join(text)
|
return "".join(text)
|
||||||
|
|
||||||
|
# //CHECK: generalise? Any others like pounds/shillings/pence?
|
||||||
#//CHECK: generalise? Any others like pounds/shillings/pence?
|
|
||||||
def to_splitnum(self, val, hightxt="", lowtxt="", jointxt="",
|
def to_splitnum(self, val, hightxt="", lowtxt="", jointxt="",
|
||||||
divisor=100, longval=True, cents=True):
|
divisor=100, longval=True, cents=True):
|
||||||
out = []
|
out = []
|
||||||
@@ -252,23 +235,18 @@ class Num2Word_Base(object):
|
|||||||
|
|
||||||
return " ".join(out)
|
return " ".join(out)
|
||||||
|
|
||||||
|
|
||||||
def to_year(self, value, **kwargs):
|
def to_year(self, value, **kwargs):
|
||||||
return self.to_cardinal(value)
|
return self.to_cardinal(value)
|
||||||
|
|
||||||
|
|
||||||
def to_currency(self, value, **kwargs):
|
def to_currency(self, value, **kwargs):
|
||||||
return self.to_cardinal(value)
|
return self.to_cardinal(value)
|
||||||
|
|
||||||
|
|
||||||
def base_setup(self):
|
def base_setup(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def setup(self):
|
def setup(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def test(self, value):
|
def test(self, value):
|
||||||
try:
|
try:
|
||||||
_card = self.to_cardinal(value)
|
_card = self.to_cardinal(value)
|
||||||
@@ -285,5 +263,5 @@ class Num2Word_Base(object):
|
|||||||
except:
|
except:
|
||||||
_ordnum = "invalid"
|
_ordnum = "invalid"
|
||||||
|
|
||||||
print ("For %s, card is %s;\n\tord is %s; and\n\tordnum is %s." %
|
print("For %s, card is %s;\n\tord is %s; and\n\tordnum is %s."
|
||||||
(value, _card, _ord, _ordnum))
|
% (value, _card, _ord, _ordnum))
|
||||||
|
|||||||
@@ -18,9 +18,9 @@ import sys
|
|||||||
|
|
||||||
PY3 = sys.version_info[0] == 3
|
PY3 = sys.version_info[0] == 3
|
||||||
|
|
||||||
|
|
||||||
def to_s(val):
|
def to_s(val):
|
||||||
if PY3:
|
if PY3:
|
||||||
return str(val)
|
return str(val)
|
||||||
else:
|
else:
|
||||||
return unicode(val)
|
return unicode(val)
|
||||||
|
|
||||||
|
|||||||
@@ -18,11 +18,12 @@
|
|||||||
from __future__ import division, unicode_literals, print_function
|
from __future__ import division, unicode_literals, print_function
|
||||||
from . import lang_EU
|
from . import lang_EU
|
||||||
|
|
||||||
|
|
||||||
class Num2Word_AR(lang_EU.Num2Word_EU):
|
class Num2Word_AR(lang_EU.Num2Word_EU):
|
||||||
def set_high_numwords(self, high):
|
def set_high_numwords(self, high):
|
||||||
max = 3 + 3*len(high)
|
max = 3 + 3 * len(high)
|
||||||
for word, n in zip(high, range(max, 3, -3)):
|
for word, n in zip(high, range(max, 3, -3)):
|
||||||
self.cards[10**n] = word + "illion"
|
self.cards[10 ** n] = word + "illion"
|
||||||
|
|
||||||
def setup(self):
|
def setup(self):
|
||||||
self.negword = "سالب "
|
self.negword = "سالب "
|
||||||
@@ -30,7 +31,7 @@ class Num2Word_AR(lang_EU.Num2Word_EU):
|
|||||||
self.errmsg_nornum = "Only numbers may be converted to words."
|
self.errmsg_nornum = "Only numbers may be converted to words."
|
||||||
self.exclude_title = ["و", "فاصلة", "سالب"]
|
self.exclude_title = ["و", "فاصلة", "سالب"]
|
||||||
|
|
||||||
self.mid_numwords = [(1000000, "مليون"),(1000, "ألف"), (100, "مئة"),
|
self.mid_numwords = [(1000000, "مليون"), (1000, "ألف"), (100, "مئة"),
|
||||||
(90, "تسعين"), (80, "ثمانين"), (70, "سبعين"),
|
(90, "تسعين"), (80, "ثمانين"), (70, "سبعين"),
|
||||||
(60, "ستين"), (50, "خمسين"), (40, "أربعين"),
|
(60, "ستين"), (50, "خمسين"), (40, "أربعين"),
|
||||||
(30, "ثلاثين")]
|
(30, "ثلاثين")]
|
||||||
@@ -39,35 +40,33 @@ class Num2Word_AR(lang_EU.Num2Word_EU):
|
|||||||
"اثناعشر", "أحد عشر", "عشرة", "تسعة", "ثمانية",
|
"اثناعشر", "أحد عشر", "عشرة", "تسعة", "ثمانية",
|
||||||
"سبعة", "ستة", "خمسة", "أربعة", "ثلاثة", "اثنين",
|
"سبعة", "ستة", "خمسة", "أربعة", "ثلاثة", "اثنين",
|
||||||
"واحد", "صفر"]
|
"واحد", "صفر"]
|
||||||
self.ords = { "واحد" : "أول",
|
self.ords = {"واحد": "أول",
|
||||||
"اثنين" : "ثاني",
|
"اثنين": "ثاني",
|
||||||
"ثلاثة" : "ثالث",
|
"ثلاثة": "ثالث",
|
||||||
"أربعة": "رابع",
|
"أربعة": "رابع",
|
||||||
"خمسة" : "خامس",
|
"خمسة": "خامس",
|
||||||
"ثمانية" : "ثامن",
|
"ثمانية": "ثامن",
|
||||||
"تسعة" : "تاسع",
|
"تسعة": "تاسع",
|
||||||
"اثناعشر" : "ثاني عشر" }
|
"اثناعشر": "ثاني عشر"}
|
||||||
|
|
||||||
|
|
||||||
def merge(self, lpair, rpair):
|
def merge(self, lpair, rpair):
|
||||||
ltext, lnum = lpair
|
ltext, lnum = lpair
|
||||||
rtext, rnum = rpair
|
rtext, rnum = rpair
|
||||||
if lnum == 1 and rnum < 100:
|
if lnum == 1 and rnum < 100:
|
||||||
return (rtext, rnum)
|
return (rtext, rnum)
|
||||||
elif 100 > lnum > rnum :
|
elif 100 > lnum > rnum:
|
||||||
return ("%s و%s"%(rtext, ltext), rnum + lnum)
|
return ("%s و%s" % (rtext, ltext), rnum + lnum)
|
||||||
elif lnum >= 100 > rnum:
|
elif lnum >= 100 > rnum:
|
||||||
return ("%s و %s"%(ltext, rtext), lnum + rnum)
|
return ("%s و %s" % (ltext, rtext), lnum + rnum)
|
||||||
elif rnum > lnum:
|
elif rnum > lnum:
|
||||||
if lnum == 1 and rnum in [100, 1000, 1000000]:
|
if lnum == 1 and rnum in [100, 1000, 1000000]:
|
||||||
return ("%s"%(rtext), rnum * lnum)
|
return ("%s" % (rtext), rnum * lnum)
|
||||||
if lnum == 2 and rnum == 100:
|
if lnum == 2 and rnum == 100:
|
||||||
return ("مئتين", rnum * lnum)
|
return ("مئتين", rnum * lnum)
|
||||||
if lnum == 2 and rnum in [100, 1000]:
|
if lnum == 2 and rnum in [100, 1000]:
|
||||||
return ("%sين"%(rtext), rnum * lnum)
|
return ("%sين" % (rtext), rnum * lnum)
|
||||||
return ("%s %s"%(ltext, rtext), lnum * rnum)
|
return ("%s %s" % (ltext, rtext), lnum * rnum)
|
||||||
return ("%s، %s"%(ltext, rtext), lnum + rnum)
|
return ("%s، %s" % (ltext, rtext), lnum + rnum)
|
||||||
|
|
||||||
|
|
||||||
def to_ordinal(self, value):
|
def to_ordinal(self, value):
|
||||||
self.verify_ordinal(value)
|
self.verify_ordinal(value)
|
||||||
@@ -82,21 +81,19 @@ class Num2Word_AR(lang_EU.Num2Word_EU):
|
|||||||
outwords[-1] = "،".join(lastwords)
|
outwords[-1] = "،".join(lastwords)
|
||||||
return " ".join(outwords)
|
return " ".join(outwords)
|
||||||
|
|
||||||
|
|
||||||
def to_ordinal_num(self, value):
|
def to_ordinal_num(self, value):
|
||||||
self.verify_ordinal(value)
|
self.verify_ordinal(value)
|
||||||
return "%s%s"%(value, self.to_ordinal(value)[-2:])
|
return "%s%s" % (value, self.to_ordinal(value)[-2:])
|
||||||
|
|
||||||
|
|
||||||
def to_year(self, val, longval=True):
|
def to_year(self, val, longval=True):
|
||||||
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="مئة", jointxt="و",
|
return self.to_splitnum(val, hightxt="مئة", jointxt="و",
|
||||||
longval=longval)
|
longval=longval)
|
||||||
|
|
||||||
def to_currency(self, val, longval=True):
|
def to_currency(self, val, longval=True):
|
||||||
return self.to_splitnum(val, hightxt="ريال", lowtxt="هللة",
|
return self.to_splitnum(val, hightxt="ريال", lowtxt="هللة",
|
||||||
jointxt="و", longval=longval, cents = True)
|
jointxt="و", longval=longval, cents=True)
|
||||||
|
|
||||||
|
|
||||||
n2w = Num2Word_AR()
|
n2w = Num2Word_AR()
|
||||||
@@ -105,14 +102,15 @@ to_ord = n2w.to_ordinal
|
|||||||
to_ordnum = n2w.to_ordinal_num
|
to_ordnum = n2w.to_ordinal_num
|
||||||
to_year = n2w.to_year
|
to_year = n2w.to_year
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
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, 1000, 1120, 1800, 1976, 2000, 2010, 2099, 2171]:
|
||||||
print(val, "is", n2w.to_currency(val))
|
print(val, "is", n2w.to_currency(val))
|
||||||
print(val, "is", n2w.to_year(val))
|
print(val, "is", n2w.to_year(val))
|
||||||
|
|
||||||
|
|||||||
@@ -18,21 +18,34 @@
|
|||||||
from __future__ import unicode_literals, print_function
|
from __future__ import unicode_literals, print_function
|
||||||
from .lang_EU import Num2Word_EU
|
from .lang_EU import Num2Word_EU
|
||||||
|
|
||||||
|
|
||||||
class Num2Word_DE(Num2Word_EU):
|
class Num2Word_DE(Num2Word_EU):
|
||||||
def set_high_numwords(self, high):
|
def set_high_numwords(self, high):
|
||||||
max = 3 + 6*len(high)
|
max = 3 + 6 * len(high)
|
||||||
|
|
||||||
for word, n in zip(high, range(max, 3, -6)):
|
for word, n in zip(high, range(max, 3, -6)):
|
||||||
self.cards[10**n] = word + "illiarde"
|
self.cards[10 ** n] = word + "illiarde"
|
||||||
self.cards[10**(n-3)] = word + "illion"
|
self.cards[10 ** (n - 3)] = word + "illion"
|
||||||
|
|
||||||
def setup(self):
|
def setup(self):
|
||||||
self.negword = "minus "
|
self.negword = "minus "
|
||||||
self.pointword = "Komma"
|
self.pointword = "Komma"
|
||||||
self.errmsg_floatord = "Die Gleitkommazahl %s kann nicht in eine Ordnungszahl konvertiert werden." # "Cannot treat float %s as ordinal."
|
# "Cannot treat float %s as ordinal."
|
||||||
self.errmsg_nonnum = "Nur Zahlen (type(%s)) können in Wörter konvertiert werden." # "type(((type(%s)) ) not in [long, int, float]"
|
self.errmsg_floatord = (
|
||||||
self.errmsg_negord = "Die negative Zahl %s kann nicht in eine Ordnungszahl konvertiert werden." # "Cannot treat negative num %s as ordinal."
|
"Die Gleitkommazahl %s kann nicht in eine Ordnungszahl " +
|
||||||
self.errmsg_toobig = "Die Zahl %s muss kleiner als %s sein." # "abs(%s) must be less than %s."
|
"konvertiert werden."
|
||||||
|
)
|
||||||
|
# "type(((type(%s)) ) not in [long, int, float]"
|
||||||
|
self.errmsg_nonnum = (
|
||||||
|
"Nur Zahlen (type(%s)) können in Wörter konvertiert werden."
|
||||||
|
)
|
||||||
|
# "Cannot treat negative num %s as ordinal."
|
||||||
|
self.errmsg_negord = (
|
||||||
|
"Die negative Zahl %s kann nicht in eine Ordnungszahl " +
|
||||||
|
"konvertiert werden."
|
||||||
|
)
|
||||||
|
# "abs(%s) must be less than %s."
|
||||||
|
self.errmsg_toobig = "Die Zahl %s muss kleiner als %s sein."
|
||||||
self.exclude_title = []
|
self.exclude_title = []
|
||||||
|
|
||||||
lows = ["non", "okt", "sept", "sext", "quint", "quadr", "tr", "b", "m"]
|
lows = ["non", "okt", "sept", "sext", "quint", "quadr", "tr", "b", "m"]
|
||||||
@@ -40,16 +53,18 @@ class Num2Word_DE(Num2Word_EU):
|
|||||||
"okto", "novem"]
|
"okto", "novem"]
|
||||||
tens = ["dez", "vigint", "trigint", "quadragint", "quinquagint",
|
tens = ["dez", "vigint", "trigint", "quadragint", "quinquagint",
|
||||||
"sexagint", "septuagint", "oktogint", "nonagint"]
|
"sexagint", "septuagint", "oktogint", "nonagint"]
|
||||||
self.high_numwords = ["zent"]+self.gen_high_numwords(units, tens, lows)
|
self.high_numwords = (
|
||||||
|
["zent"] + self.gen_high_numwords(units, tens, lows)
|
||||||
|
)
|
||||||
self.mid_numwords = [(1000, "tausend"), (100, "hundert"),
|
self.mid_numwords = [(1000, "tausend"), (100, "hundert"),
|
||||||
(90, "neunzig"), (80, "achtzig"), (70, "siebzig"),
|
(90, "neunzig"), (80, "achtzig"), (70, "siebzig"),
|
||||||
(60, "sechzig"), (50, "f\xFCnfzig"), (40, "vierzig"),
|
(60, "sechzig"), (50, "f\xFCnfzig"),
|
||||||
(30, "drei\xDFig")]
|
(40, "vierzig"), (30, "drei\xDFig")]
|
||||||
self.low_numwords = ["zwanzig", "neunzehn", "achtzehn", "siebzehn",
|
self.low_numwords = ["zwanzig", "neunzehn", "achtzehn", "siebzehn",
|
||||||
"sechzehn", "f\xFCnfzehn", "vierzehn", "dreizehn",
|
"sechzehn", "f\xFCnfzehn", "vierzehn", "dreizehn",
|
||||||
"zw\xF6lf", "elf", "zehn", "neun", "acht", "sieben",
|
"zw\xF6lf", "elf", "zehn", "neun", "acht",
|
||||||
"sechs", "f\xFCnf", "vier", "drei", "zwei", "eins",
|
"sieben", "sechs", "f\xFCnf", "vier", "drei",
|
||||||
"null"]
|
"zwei", "eins", "null"]
|
||||||
self.ords = {"eins": "ers",
|
self.ords = {"eins": "ers",
|
||||||
"drei": "drit",
|
"drei": "drit",
|
||||||
"acht": "ach",
|
"acht": "ach",
|
||||||
@@ -66,12 +81,12 @@ class Num2Word_DE(Num2Word_EU):
|
|||||||
ctext, cnum, ntext, nnum = curr + next
|
ctext, cnum, ntext, nnum = curr + next
|
||||||
|
|
||||||
if cnum == 1:
|
if cnum == 1:
|
||||||
if nnum < 10**6:
|
if nnum < 10 ** 6:
|
||||||
return next
|
return next
|
||||||
ctext = "eine"
|
ctext = "eine"
|
||||||
|
|
||||||
if nnum > cnum:
|
if nnum > cnum:
|
||||||
if nnum >= 10**6:
|
if nnum >= 10 ** 6:
|
||||||
if cnum > 1:
|
if cnum > 1:
|
||||||
if ntext.endswith("e"):
|
if ntext.endswith("e"):
|
||||||
ntext += "n"
|
ntext += "n"
|
||||||
@@ -84,7 +99,7 @@ class Num2Word_DE(Num2Word_EU):
|
|||||||
if nnum == 1:
|
if nnum == 1:
|
||||||
ntext = "ein"
|
ntext = "ein"
|
||||||
ntext, ctext = ctext, ntext + "und"
|
ntext, ctext = ctext, ntext + "und"
|
||||||
elif cnum >= 10**6:
|
elif cnum >= 10 ** 6:
|
||||||
ctext += " "
|
ctext += " "
|
||||||
val = cnum + nnum
|
val = cnum + nnum
|
||||||
|
|
||||||
@@ -107,15 +122,16 @@ class Num2Word_DE(Num2Word_EU):
|
|||||||
def to_currency(self, val, longval=True, old=False):
|
def to_currency(self, val, longval=True, old=False):
|
||||||
if old:
|
if old:
|
||||||
return self.to_splitnum(val, hightxt="mark/s", lowtxt="pfennig/e",
|
return self.to_splitnum(val, hightxt="mark/s", lowtxt="pfennig/e",
|
||||||
jointxt="und",longval=longval)
|
jointxt="und", longval=longval)
|
||||||
return super(Num2Word_DE, self).to_currency(val, jointxt="und",
|
return super(Num2Word_DE, self).to_currency(val, jointxt="und",
|
||||||
longval=longval)
|
longval=longval)
|
||||||
|
|
||||||
def to_year(self, val, longval=True):
|
def to_year(self, val, longval=True):
|
||||||
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="hundert", longval=longval)
|
return self.to_splitnum(val, hightxt="hundert", longval=longval)
|
||||||
|
|
||||||
|
|
||||||
n2w = Num2Word_DE()
|
n2w = Num2Word_DE()
|
||||||
to_card = n2w.to_cardinal
|
to_card = n2w.to_cardinal
|
||||||
to_ord = n2w.to_ordinal
|
to_ord = n2w.to_ordinal
|
||||||
@@ -138,6 +154,6 @@ def main():
|
|||||||
print(n2w.to_year(1820))
|
print(n2w.to_year(1820))
|
||||||
print(n2w.to_year(2001))
|
print(n2w.to_year(2001))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
|||||||
@@ -17,12 +17,13 @@
|
|||||||
from __future__ import division, unicode_literals, print_function
|
from __future__ import division, unicode_literals, print_function
|
||||||
from . import lang_EU
|
from . import lang_EU
|
||||||
|
|
||||||
|
|
||||||
class Num2Word_DK(lang_EU.Num2Word_EU):
|
class Num2Word_DK(lang_EU.Num2Word_EU):
|
||||||
def set_high_numwords(self, high):
|
def set_high_numwords(self, high):
|
||||||
max = 3 + 6*len(high)
|
max = 3 + 6 * len(high)
|
||||||
for word, n in zip(high, range(max, 3, -6)):
|
for word, n in zip(high, range(max, 3, -6)):
|
||||||
self.cards[10**n] = word + "illarder"
|
self.cards[10 ** n] = word + "illarder"
|
||||||
self.cards[10**(n-3)] = word + "illioner"
|
self.cards[10 ** (n - 3)] = word + "illioner"
|
||||||
|
|
||||||
def setup(self):
|
def setup(self):
|
||||||
self.negword = "minus "
|
self.negword = "minus "
|
||||||
@@ -31,35 +32,35 @@ class Num2Word_DK(lang_EU.Num2Word_EU):
|
|||||||
self.exclude_title = ["og", "komma", "minus"]
|
self.exclude_title = ["og", "komma", "minus"]
|
||||||
|
|
||||||
self.mid_numwords = [(1000, "tusind"), (100, "hundrede"),
|
self.mid_numwords = [(1000, "tusind"), (100, "hundrede"),
|
||||||
(90, "halvfems"), (80, "firs"), (70, "halvfjerds"),
|
(90, "halvfems"), (80, "firs"),
|
||||||
(60, "treds"), (50, "halvtreds"), (40, "fyrre"),
|
(70, "halvfjerds"), (60, "treds"),
|
||||||
(30, "tredive")]
|
(50, "halvtreds"), (40, "fyrre"), (30, "tredive")]
|
||||||
self.low_numwords = ["tyve", "nitten", "atten", "sytten",
|
self.low_numwords = ["tyve", "nitten", "atten", "sytten",
|
||||||
"seksten", "femten", "fjorten", "tretten",
|
"seksten", "femten", "fjorten", "tretten",
|
||||||
"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 = { "nul" : "nul",
|
self.ords = {"nul": "nul",
|
||||||
"et" : "f\xf8rste",
|
"et": "f\xf8rste",
|
||||||
"to" : "anden",
|
"to": "anden",
|
||||||
"tre" : "tredje",
|
"tre": "tredje",
|
||||||
"fire" : "fjerde",
|
"fire": "fjerde",
|
||||||
"fem" : "femte",
|
"fem": "femte",
|
||||||
"seks" : "sjette",
|
"seks": "sjette",
|
||||||
"syv" : "syvende",
|
"syv": "syvende",
|
||||||
"otte" : "ottende",
|
"otte": "ottende",
|
||||||
"ni" : "niende",
|
"ni": "niende",
|
||||||
"ti" : "tiende",
|
"ti": "tiende",
|
||||||
"elleve" : "ellevte",
|
"elleve": "ellevte",
|
||||||
"tolv" : "tolvte",
|
"tolv": "tolvte",
|
||||||
"tretten" : "trett",
|
"tretten": "trett",
|
||||||
"fjorten" : "fjort",
|
"fjorten": "fjort",
|
||||||
"femten" : "femt",
|
"femten": "femt",
|
||||||
"seksten" : "sekst",
|
"seksten": "sekst",
|
||||||
"sytten" : "sytt",
|
"sytten": "sytt",
|
||||||
"atten" : "att",
|
"atten": "att",
|
||||||
"nitten" : "nitt",
|
"nitten": "nitt",
|
||||||
"tyve" : "tyv"}
|
"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,11 +70,11 @@ class Num2Word_DK(lang_EU.Num2Word_EU):
|
|||||||
next = tuple(lst)
|
next = tuple(lst)
|
||||||
|
|
||||||
if cnum == 1:
|
if cnum == 1:
|
||||||
if nnum < 10**6 or self.ordflag:
|
if nnum < 10 ** 6 or self.ordflag:
|
||||||
return next
|
return next
|
||||||
ctext = "en"
|
ctext = "en"
|
||||||
if nnum > cnum:
|
if nnum > cnum:
|
||||||
if nnum >= 10**6:
|
if nnum >= 10 ** 6:
|
||||||
ctext += " "
|
ctext += " "
|
||||||
val = cnum * nnum
|
val = cnum * nnum
|
||||||
else:
|
else:
|
||||||
@@ -85,13 +86,12 @@ class Num2Word_DK(lang_EU.Num2Word_EU):
|
|||||||
if nnum == 1:
|
if nnum == 1:
|
||||||
ntext = "en"
|
ntext = "en"
|
||||||
ntext, ctext = ctext, ntext + "og"
|
ntext, ctext = ctext, ntext + "og"
|
||||||
elif cnum >= 10**6:
|
elif cnum >= 10 ** 6:
|
||||||
ctext += " "
|
ctext += " "
|
||||||
val = cnum + nnum
|
val = cnum + nnum
|
||||||
word = ctext + ntext
|
word = ctext + ntext
|
||||||
return (word, val)
|
return (word, val)
|
||||||
|
|
||||||
|
|
||||||
def to_ordinal(self, value):
|
def to_ordinal(self, value):
|
||||||
self.verify_ordinal(value)
|
self.verify_ordinal(value)
|
||||||
self.ordflag = True
|
self.ordflag = True
|
||||||
@@ -101,54 +101,57 @@ 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
|
||||||
if value %100 >= 30 and value %100 <= 39 or value %100 == 0:
|
if value % 100 >= 30 and value % 100 <= 39 or value % 100 == 0:
|
||||||
outword += "te"
|
outword += "te"
|
||||||
elif value % 100 > 12 or value %100 == 0:
|
elif value % 100 > 12 or value % 100 == 0:
|
||||||
outword += "ende"
|
outword += "ende"
|
||||||
return outword
|
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)
|
vaerdte = (0, 1, 5, 6, 11, 12)
|
||||||
if value %100 >= 30 and value %100 <= 39 or value % 100 in vaerdte:
|
if value % 100 >= 30 and value % 100 <= 39 or value % 100 in vaerdte:
|
||||||
return str(value) + "te"
|
return str(value) + "te"
|
||||||
elif value % 100 == 2:
|
elif value % 100 == 2:
|
||||||
return str(value) + "en"
|
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:
|
if val // 100 == 1 or val == 1:
|
||||||
ret = self.to_splitnum(val, hightxt="kr", lowtxt="\xf8re",
|
ret = self.to_splitnum(val, hightxt="kr", lowtxt="\xf8re",
|
||||||
jointxt="og",longval=longval)
|
jointxt="og", longval=longval)
|
||||||
return "en " + ret[3:]
|
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:
|
if val == 1:
|
||||||
return 'en'
|
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)
|
||||||
|
|
||||||
|
|
||||||
n2w = Num2Word_DK()
|
n2w = Num2Word_DK()
|
||||||
to_card = n2w.to_cardinal
|
to_card = n2w.to_cardinal
|
||||||
to_ord = n2w.to_ordinal
|
to_ord = n2w.to_ordinal
|
||||||
to_ordnum = n2w.to_ordinal_num
|
to_ordnum = n2w.to_ordinal_num
|
||||||
to_year = n2w.to_year
|
to_year = n2w.to_year
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
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(
|
||||||
for val in [1,120, 160, 1000,1120,1800, 1976,2000,2010,2099,2171]:
|
1325325436067876801768700107601001012212132143210473207540327057320957032975032975093275093275093270957329057320975093272950730)
|
||||||
|
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)
|
n2w.test(65132)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
@@ -17,11 +17,12 @@
|
|||||||
from __future__ import division, unicode_literals, print_function
|
from __future__ import division, unicode_literals, print_function
|
||||||
from . import lang_EU
|
from . import lang_EU
|
||||||
|
|
||||||
|
|
||||||
class Num2Word_EN(lang_EU.Num2Word_EU):
|
class Num2Word_EN(lang_EU.Num2Word_EU):
|
||||||
def set_high_numwords(self, high):
|
def set_high_numwords(self, high):
|
||||||
max = 3 + 3*len(high)
|
max = 3 + 3 * len(high)
|
||||||
for word, n in zip(high, range(max, 3, -3)):
|
for word, n in zip(high, range(max, 3, -3)):
|
||||||
self.cards[10**n] = word + "illion"
|
self.cards[10 ** n] = word + "illion"
|
||||||
|
|
||||||
def setup(self):
|
def setup(self):
|
||||||
self.negword = "minus "
|
self.negword = "minus "
|
||||||
@@ -38,28 +39,26 @@ class Num2Word_EN(lang_EU.Num2Word_EU):
|
|||||||
"twelve", "eleven", "ten", "nine", "eight",
|
"twelve", "eleven", "ten", "nine", "eight",
|
||||||
"seven", "six", "five", "four", "three", "two",
|
"seven", "six", "five", "four", "three", "two",
|
||||||
"one", "zero"]
|
"one", "zero"]
|
||||||
self.ords = { "one" : "first",
|
self.ords = {"one": "first",
|
||||||
"two" : "second",
|
"two": "second",
|
||||||
"three" : "third",
|
"three": "third",
|
||||||
"five" : "fifth",
|
"five": "fifth",
|
||||||
"eight" : "eighth",
|
"eight": "eighth",
|
||||||
"nine" : "ninth",
|
"nine": "ninth",
|
||||||
"twelve" : "twelfth" }
|
"twelve": "twelfth"}
|
||||||
|
|
||||||
|
|
||||||
def merge(self, lpair, rpair):
|
def merge(self, lpair, rpair):
|
||||||
ltext, lnum = lpair
|
ltext, lnum = lpair
|
||||||
rtext, rnum = rpair
|
rtext, rnum = rpair
|
||||||
if lnum == 1 and rnum < 100:
|
if lnum == 1 and rnum < 100:
|
||||||
return (rtext, rnum)
|
return (rtext, rnum)
|
||||||
elif 100 > lnum > rnum :
|
elif 100 > lnum > rnum:
|
||||||
return ("%s-%s"%(ltext, rtext), lnum + rnum)
|
return ("%s-%s" % (ltext, rtext), lnum + rnum)
|
||||||
elif lnum >= 100 > rnum:
|
elif lnum >= 100 > rnum:
|
||||||
return ("%s and %s"%(ltext, rtext), lnum + rnum)
|
return ("%s and %s" % (ltext, rtext), lnum + rnum)
|
||||||
elif rnum > lnum:
|
elif rnum > lnum:
|
||||||
return ("%s %s"%(ltext, rtext), lnum * rnum)
|
return ("%s %s" % (ltext, rtext), lnum * rnum)
|
||||||
return ("%s, %s"%(ltext, rtext), lnum + rnum)
|
return ("%s, %s" % (ltext, rtext), lnum + rnum)
|
||||||
|
|
||||||
|
|
||||||
def to_ordinal(self, value):
|
def to_ordinal(self, value):
|
||||||
self.verify_ordinal(value)
|
self.verify_ordinal(value)
|
||||||
@@ -76,21 +75,19 @@ class Num2Word_EN(lang_EU.Num2Word_EU):
|
|||||||
outwords[-1] = "-".join(lastwords)
|
outwords[-1] = "-".join(lastwords)
|
||||||
return " ".join(outwords)
|
return " ".join(outwords)
|
||||||
|
|
||||||
|
|
||||||
def to_ordinal_num(self, value):
|
def to_ordinal_num(self, value):
|
||||||
self.verify_ordinal(value)
|
self.verify_ordinal(value)
|
||||||
return "%s%s"%(value, self.to_ordinal(value)[-2:])
|
return "%s%s" % (value, self.to_ordinal(value)[-2:])
|
||||||
|
|
||||||
|
|
||||||
def to_year(self, val, longval=True):
|
def to_year(self, val, longval=True):
|
||||||
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="hundred", jointxt="and",
|
return self.to_splitnum(val, hightxt="hundred", jointxt="and",
|
||||||
longval=longval)
|
longval=longval)
|
||||||
|
|
||||||
def to_currency(self, val, longval=True):
|
def to_currency(self, val, longval=True):
|
||||||
return self.to_splitnum(val, hightxt="dollar/s", lowtxt="cent/s",
|
return self.to_splitnum(val, hightxt="dollar/s", lowtxt="cent/s",
|
||||||
jointxt="and", longval=longval, cents = True)
|
jointxt="and", longval=longval, cents=True)
|
||||||
|
|
||||||
|
|
||||||
n2w = Num2Word_EN()
|
n2w = Num2Word_EN()
|
||||||
@@ -99,14 +96,16 @@ to_ord = n2w.to_ordinal
|
|||||||
to_ordnum = n2w.to_ordinal_num
|
to_ordnum = n2w.to_ordinal_num
|
||||||
to_year = n2w.to_year
|
to_year = n2w.to_year
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
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(
|
||||||
for val in [1,120,1000,1120,1800, 1976,2000,2010,2099,2171]:
|
1325325436067876801768700107601001012212132143210473207540327057320957032975032975093275093275093270957329057320975093272950730)
|
||||||
|
for val in [1, 120, 1000, 1120, 1800, 1976, 2000, 2010, 2099, 2171]:
|
||||||
print(val, "is", n2w.to_currency(val))
|
print(val, "is", n2w.to_currency(val))
|
||||||
print(val, "is", n2w.to_year(val))
|
print(val, "is", n2w.to_year(val))
|
||||||
|
|
||||||
|
|||||||
@@ -14,13 +14,14 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
# MA 02110-1301 USA
|
# MA 02110-1301 USA
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals, print_function
|
||||||
from .lang_EN import Num2Word_EN
|
from .lang_EN import Num2Word_EN
|
||||||
|
|
||||||
|
|
||||||
class Num2Word_EN_EUR(Num2Word_EN):
|
class Num2Word_EN_EUR(Num2Word_EN):
|
||||||
def to_currency(self, val, longval=True, cents=True, jointxt="and"):
|
def to_currency(self, val, longval=True, cents=True, jointxt="and"):
|
||||||
return self.to_splitnum(val, hightxt="euro/s", lowtxt="cents",
|
return self.to_splitnum(val, hightxt="euro/s", lowtxt="cents",
|
||||||
jointxt=jointxt, longval=longval, cents = cents)
|
jointxt=jointxt, longval=longval, cents=cents)
|
||||||
|
|
||||||
|
|
||||||
n2w = Num2Word_EN_EUR()
|
n2w = Num2Word_EN_EUR()
|
||||||
@@ -30,16 +31,18 @@ to_ordnum = n2w.to_ordinal_num
|
|||||||
to_year = n2w.to_year
|
to_year = n2w.to_year
|
||||||
to_currency = n2w.to_currency
|
to_currency = n2w.to_currency
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
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(
|
||||||
for val in [1,120,1000,1120,1800, 1976,2000,2010,2099,2171]:
|
1325325436067876801768700107601001012212132143210473207540327057320957032975032975093275093275093270957329057320975093272950730)
|
||||||
print val, "is", n2w.to_currency(val)
|
for val in [1, 120, 1000, 1120, 1800, 1976, 2000, 2010, 2099, 2171]:
|
||||||
print val, "is", n2w.to_year(val)
|
print(val, "is", n2w.to_currency(val))
|
||||||
|
print(val, "is", n2w.to_year(val))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -30,14 +30,16 @@ to_ord = n2w.to_ordinal
|
|||||||
to_ordnum = n2w.to_ordinal_num
|
to_ordnum = n2w.to_ordinal_num
|
||||||
to_year = n2w.to_year
|
to_year = n2w.to_year
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
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(
|
||||||
for val in [1,120,1000,1120,1800, 1976,2000,2010,2099,2171]:
|
1325325436067876801768700107601001012212132143210473207540327057320957032975032975093275093275093270957329057320975093272950730)
|
||||||
|
for val in [1, 120, 1000, 1120, 1800, 1976, 2000, 2010, 2099, 2171]:
|
||||||
print(val, "is", n2w.to_currency(val))
|
print(val, "is", n2w.to_currency(val))
|
||||||
print(val, "is", n2w.to_year(val))
|
print(val, "is", n2w.to_year(val))
|
||||||
|
|
||||||
|
|||||||
@@ -14,9 +14,10 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
# MA 02110-1301 USA
|
# MA 02110-1301 USA
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals, print_function
|
||||||
from .lang_EN_GB import Num2Word_EN_GB
|
from .lang_EN_GB import Num2Word_EN_GB
|
||||||
|
|
||||||
|
|
||||||
class Num2Word_EN_GB_old(Num2Word_EN_GB):
|
class Num2Word_EN_GB_old(Num2Word_EN_GB):
|
||||||
def base_setup(self):
|
def base_setup(self):
|
||||||
sclass = super(Num2Word_EN_GB, self)
|
sclass = super(Num2Word_EN_GB, self)
|
||||||
@@ -29,17 +30,20 @@ to_card = n2w.to_cardinal
|
|||||||
to_ord = n2w.to_ordinal
|
to_ord = n2w.to_ordinal
|
||||||
to_ordnum = n2w.to_ordinal_num
|
to_ordnum = n2w.to_ordinal_num
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
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(
|
||||||
for val in [1,120,1000,1120,1800, 1976,2000,2010,2099,2171]:
|
1325325436067876801768700107601001012212132143210473207540327057320957032975032975093275093275093270957329057320975093272950730)
|
||||||
print val, "is", n2w.to_currency(val)
|
for val in [1, 120, 1000, 1120, 1800, 1976, 2000, 2010, 2099, 2171]:
|
||||||
print val, "is", n2w.to_year(val)
|
print(val, "is", n2w.to_currency(val))
|
||||||
|
print(val, "is", n2w.to_year(val))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
@@ -17,10 +17,11 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
from .lang_EN import Num2Word_EN
|
from .lang_EN import Num2Word_EN
|
||||||
|
|
||||||
|
|
||||||
class Num2Word_EN_IN(Num2Word_EN):
|
class Num2Word_EN_IN(Num2Word_EN):
|
||||||
def set_high_numwords(self, high):
|
def set_high_numwords(self, high):
|
||||||
self.cards[10**7] = "crore"
|
self.cards[10 ** 7] = "crore"
|
||||||
self.cards[10**5] = "lakh"
|
self.cards[10 ** 5] = "lakh"
|
||||||
|
|
||||||
|
|
||||||
n2w = Num2Word_EN_IN()
|
n2w = Num2Word_EN_IN()
|
||||||
@@ -28,15 +29,17 @@ to_card = n2w.to_cardinal
|
|||||||
to_ord = n2w.to_ordinal
|
to_ord = n2w.to_ordinal
|
||||||
to_ordnum = n2w.to_ordinal_num
|
to_ordnum = n2w.to_ordinal_num
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
for val in (15000,
|
for val in (15000,
|
||||||
15*10**5,
|
15 * 10 ** 5,
|
||||||
15*10**6,
|
15 * 10 ** 6,
|
||||||
15*10**7,
|
15 * 10 ** 7,
|
||||||
15*10**8,
|
15 * 10 ** 8,
|
||||||
15*10**9,
|
15 * 10 ** 9,
|
||||||
15*10**10):
|
15 * 10 ** 10):
|
||||||
n2w.test(val)
|
n2w.test(val)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
@@ -21,13 +21,12 @@ from .lang_EU import Num2Word_EU
|
|||||||
|
|
||||||
|
|
||||||
class Num2Word_ES(Num2Word_EU):
|
class Num2Word_ES(Num2Word_EU):
|
||||||
|
|
||||||
# //CHECK: Is this sufficient??
|
# //CHECK: Is this sufficient??
|
||||||
def set_high_numwords(self, high):
|
def set_high_numwords(self, high):
|
||||||
max = 3 + 6*len(high)
|
max = 3 + 6 * len(high)
|
||||||
|
|
||||||
for word, n in zip(high, range(max, 3, -6)):
|
for word, n in zip(high, range(max, 3, -6)):
|
||||||
self.cards[10**(n-3)] = word + "illón"
|
self.cards[10 ** (n - 3)] = word + "illón"
|
||||||
|
|
||||||
def setup(self):
|
def setup(self):
|
||||||
lows = ["cuatr", "tr", "b", "m"]
|
lows = ["cuatr", "tr", "b", "m"]
|
||||||
@@ -35,12 +34,15 @@ class Num2Word_ES(Num2Word_EU):
|
|||||||
self.negword = "menos "
|
self.negword = "menos "
|
||||||
self.pointword = "punto"
|
self.pointword = "punto"
|
||||||
self.errmsg_nonnum = "Solo números pueden ser convertidos a palabras."
|
self.errmsg_nonnum = "Solo números pueden ser convertidos a palabras."
|
||||||
self.errmsg_toobig = "Numero muy grande para ser convertido a palabras."
|
self.errmsg_toobig = (
|
||||||
|
"Numero muy grande para ser convertido a palabras."
|
||||||
|
)
|
||||||
self.gender_stem = "o"
|
self.gender_stem = "o"
|
||||||
self.exclude_title = ["y", "menos", "punto"]
|
self.exclude_title = ["y", "menos", "punto"]
|
||||||
self.mid_numwords = [(1000, "mil"), (100, "cien"), (90, "noventa"),
|
self.mid_numwords = [(1000, "mil"), (100, "cien"), (90, "noventa"),
|
||||||
(80, "ochenta"), (70, "setenta"), (60, "sesenta"),
|
(80, "ochenta"), (70, "setenta"), (60, "sesenta"),
|
||||||
(50, "cincuenta"), (40, "cuarenta"), (30, "treinta")]
|
(50, "cincuenta"), (40, "cuarenta"),
|
||||||
|
(30, "treinta")]
|
||||||
self.low_numwords = ["veintinueve", "veintiocho", "veintisiete",
|
self.low_numwords = ["veintinueve", "veintiocho", "veintisiete",
|
||||||
"veintiséis", "veinticinco", "veinticuatro",
|
"veintiséis", "veinticinco", "veinticuatro",
|
||||||
"veintitrés", "veintidós", "veintiuno",
|
"veintitrés", "veintidós", "veintiuno",
|
||||||
@@ -48,38 +50,38 @@ class Num2Word_ES(Num2Word_EU):
|
|||||||
"dieciseis", "quince", "catorce", "trece", "doce",
|
"dieciseis", "quince", "catorce", "trece", "doce",
|
||||||
"once", "diez", "nueve", "ocho", "siete", "seis",
|
"once", "diez", "nueve", "ocho", "siete", "seis",
|
||||||
"cinco", "cuatro", "tres", "dos", "uno", "cero"]
|
"cinco", "cuatro", "tres", "dos", "uno", "cero"]
|
||||||
self.ords = { 1 : "primer",
|
self.ords = {1: "primer",
|
||||||
2 : "segund",
|
2: "segund",
|
||||||
3 : "tercer",
|
3: "tercer",
|
||||||
4 : "cuart",
|
4: "cuart",
|
||||||
5 : "quint",
|
5: "quint",
|
||||||
6 : "sext",
|
6: "sext",
|
||||||
7 : "séptim",
|
7: "séptim",
|
||||||
8 : "octav",
|
8: "octav",
|
||||||
9 : "noven",
|
9: "noven",
|
||||||
10 : "décim",
|
10: "décim",
|
||||||
20 : "vigésim",
|
20: "vigésim",
|
||||||
30 : "trigésim",
|
30: "trigésim",
|
||||||
40 : "quadragésim",
|
40: "quadragésim",
|
||||||
50 : "quincuagésim",
|
50: "quincuagésim",
|
||||||
60 : "sexagésim",
|
60: "sexagésim",
|
||||||
70 : "septuagésim",
|
70: "septuagésim",
|
||||||
80 : "octogésim",
|
80: "octogésim",
|
||||||
90 : "nonagésim",
|
90: "nonagésim",
|
||||||
100 : "centésim",
|
100: "centésim",
|
||||||
200 : "ducentésim",
|
200: "ducentésim",
|
||||||
300 : "tricentésim",
|
300: "tricentésim",
|
||||||
400 : "cuadrigentésim",
|
400: "cuadrigentésim",
|
||||||
500 : "quingentésim",
|
500: "quingentésim",
|
||||||
600 : "sexcentésim",
|
600: "sexcentésim",
|
||||||
700 : "septigentésim",
|
700: "septigentésim",
|
||||||
800 : "octigentésim",
|
800: "octigentésim",
|
||||||
900 : "noningentésim",
|
900: "noningentésim",
|
||||||
1e3 : "milésim",
|
1e3: "milésim",
|
||||||
1e6 : "millonésim",
|
1e6: "millonésim",
|
||||||
1e9 : "billonésim",
|
1e9: "billonésim",
|
||||||
1e12 : "trillonésim",
|
1e12: "trillonésim",
|
||||||
1e15 : "cuadrillonésim" }
|
1e15: "cuadrillonésim"}
|
||||||
|
|
||||||
def merge(self, curr, next):
|
def merge(self, curr, next):
|
||||||
ctext, cnum, ntext, nnum = curr + next
|
ctext, cnum, ntext, nnum = curr + next
|
||||||
@@ -93,8 +95,8 @@ class Num2Word_ES(Num2Word_EU):
|
|||||||
|
|
||||||
if nnum < cnum:
|
if nnum < cnum:
|
||||||
if cnum < 100:
|
if cnum < 100:
|
||||||
return "%s y %s"%(ctext, ntext), cnum + nnum
|
return "%s y %s" % (ctext, ntext), cnum + nnum
|
||||||
return "%s %s"%(ctext, ntext), cnum + nnum
|
return "%s %s" % (ctext, ntext), cnum + nnum
|
||||||
elif (not nnum % 1000000) and cnum > 1:
|
elif (not nnum % 1000000) and cnum > 1:
|
||||||
ntext = ntext[:-3] + "lones"
|
ntext = ntext[:-3] + "lones"
|
||||||
|
|
||||||
@@ -121,13 +123,22 @@ class Num2Word_ES(Num2Word_EU):
|
|||||||
elif value <= 10:
|
elif value <= 10:
|
||||||
text = "%s%s" % (self.ords[value], self.gender_stem)
|
text = "%s%s" % (self.ords[value], self.gender_stem)
|
||||||
elif value <= 12:
|
elif value <= 12:
|
||||||
text = "%s%s%s" % (self.ords[10], self.gender_stem, self.to_ordinal(value - 10))
|
text = (
|
||||||
|
"%s%s%s" % (self.ords[10], self.gender_stem,
|
||||||
|
self.to_ordinal(value - 10))
|
||||||
|
)
|
||||||
elif value <= 100:
|
elif value <= 100:
|
||||||
dec = (value // 10) * 10
|
dec = (value // 10) * 10
|
||||||
text = "%s%s %s" % (self.ords[dec], self.gender_stem, self.to_ordinal(value - dec))
|
text = (
|
||||||
|
"%s%s %s" % (self.ords[dec], self.gender_stem,
|
||||||
|
self.to_ordinal(value - dec))
|
||||||
|
)
|
||||||
elif value <= 1e3:
|
elif value <= 1e3:
|
||||||
cen = (value // 100) * 100
|
cen = (value // 100) * 100
|
||||||
text = "%s%s %s" % (self.ords[cen], self.gender_stem, self.to_ordinal(value - cen))
|
text = (
|
||||||
|
"%s%s %s" % (self.ords[cen], self.gender_stem,
|
||||||
|
self.to_ordinal(value - cen))
|
||||||
|
)
|
||||||
elif value < 1e18:
|
elif value < 1e18:
|
||||||
# dec contains the following:
|
# dec contains the following:
|
||||||
# [ 1e3, 1e6): 1e3
|
# [ 1e3, 1e6): 1e3
|
||||||
@@ -137,8 +148,13 @@ class Num2Word_ES(Num2Word_EU):
|
|||||||
# [1e15, 1e18): 1e15
|
# [1e15, 1e18): 1e15
|
||||||
dec = 10 ** ((((len(str(int(value))) - 1) / 3 - 1) + 1) * 3)
|
dec = 10 ** ((((len(str(int(value))) - 1) / 3 - 1) + 1) * 3)
|
||||||
part = int(float(value / dec) * dec)
|
part = int(float(value / dec) * dec)
|
||||||
cardinal = self.to_cardinal(part / dec) if part / dec != 1 else ""
|
cardinal = (
|
||||||
text = "%s%s%s %s" % (cardinal, self.ords[dec], self.gender_stem, self.to_ordinal(value - part))
|
self.to_cardinal(part / dec) if part / dec != 1 else ""
|
||||||
|
)
|
||||||
|
text = (
|
||||||
|
"%s%s%s %s" % (cardinal, self.ords[dec], self.gender_stem,
|
||||||
|
self.to_ordinal(value - part))
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
text = self.to_cardinal(value)
|
text = self.to_cardinal(value)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
@@ -170,10 +186,12 @@ def main():
|
|||||||
-21212121211221211111, -2.121212, -1.0000100]:
|
-21212121211221211111, -2.121212, -1.0000100]:
|
||||||
n2w.test(val)
|
n2w.test(val)
|
||||||
|
|
||||||
n2w.test(1325325436067876801768700107601001012212132143210473207540327057320957032975032975093275093275093270957329057320975093272950730)
|
n2w.test(
|
||||||
|
1325325436067876801768700107601001012212132143210473207540327057320957032975032975093275093275093270957329057320975093272950730)
|
||||||
print(n2w.to_currency(1222))
|
print(n2w.to_currency(1222))
|
||||||
print(n2w.to_currency(1222, old=True))
|
print(n2w.to_currency(1222, old=True))
|
||||||
print(n2w.to_year(1222))
|
print(n2w.to_year(1222))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
@@ -23,9 +23,11 @@ from .lang_ES import Num2Word_ES
|
|||||||
class Num2Word_ES_VE(Num2Word_ES):
|
class Num2Word_ES_VE(Num2Word_ES):
|
||||||
|
|
||||||
def to_currency(self, val, longval=True, old=False):
|
def to_currency(self, val, longval=True, old=False):
|
||||||
return self.to_splitnum(val, hightxt="bolívar/es Fuerte/s", lowtxt="bolívar/es fuerte/s",
|
return self.to_splitnum(val, hightxt="bolívar/es Fuerte/s",
|
||||||
|
lowtxt="bolívar/es fuerte/s",
|
||||||
divisor=1000, jointxt="y", longval=longval)
|
divisor=1000, jointxt="y", longval=longval)
|
||||||
|
|
||||||
|
|
||||||
n2w = Num2Word_ES_VE()
|
n2w = Num2Word_ES_VE()
|
||||||
to_card = n2w.to_cardinal
|
to_card = n2w.to_cardinal
|
||||||
to_ord = n2w.to_ordinal
|
to_ord = n2w.to_ordinal
|
||||||
|
|||||||
@@ -17,24 +17,23 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
from .base import Num2Word_Base
|
from .base import Num2Word_Base
|
||||||
|
|
||||||
|
|
||||||
class Num2Word_EU(Num2Word_Base):
|
class Num2Word_EU(Num2Word_Base):
|
||||||
def set_high_numwords(self, high):
|
def set_high_numwords(self, high):
|
||||||
max = 3 + 6*len(high)
|
max = 3 + 6 * len(high)
|
||||||
|
|
||||||
for word, n in zip(high, range(max, 3, -6)):
|
for word, n in zip(high, range(max, 3, -6)):
|
||||||
self.cards[10**n] = word + "illiard"
|
self.cards[10 ** n] = word + "illiard"
|
||||||
self.cards[10**(n-3)] = word + "illion"
|
self.cards[10 ** (n - 3)] = word + "illion"
|
||||||
|
|
||||||
|
|
||||||
def base_setup(self):
|
def base_setup(self):
|
||||||
lows = ["non","oct","sept","sext","quint","quadr","tr","b","m"]
|
lows = ["non", "oct", "sept", "sext", "quint", "quadr", "tr", "b", "m"]
|
||||||
units = ["", "un", "duo", "tre", "quattuor", "quin", "sex", "sept",
|
units = ["", "un", "duo", "tre", "quattuor", "quin", "sex", "sept",
|
||||||
"octo", "novem"]
|
"octo", "novem"]
|
||||||
tens = ["dec", "vigint", "trigint", "quadragint", "quinquagint",
|
tens = ["dec", "vigint", "trigint", "quadragint", "quinquagint",
|
||||||
"sexagint", "septuagint", "octogint", "nonagint"]
|
"sexagint", "septuagint", "octogint", "nonagint"]
|
||||||
self.high_numwords = ["cent"]+self.gen_high_numwords(units, tens, lows)
|
self.high_numwords = ["cent"] + self.gen_high_numwords(units, tens, lows)
|
||||||
|
|
||||||
def to_currency(self, val, longval=True, jointxt=""):
|
def to_currency(self, val, longval=True, jointxt=""):
|
||||||
return self.to_splitnum(val, hightxt="Euro/s", lowtxt="Euro cent/s",
|
return self.to_splitnum(val, hightxt="Euro/s", lowtxt="Euro cent/s",
|
||||||
jointxt=jointxt, longval=longval)
|
jointxt=jointxt, longval=longval)
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,9 @@ class Num2Word_FR(Num2Word_EU):
|
|||||||
|
|
||||||
self.negword = "moins "
|
self.negword = "moins "
|
||||||
self.pointword = "virgule"
|
self.pointword = "virgule"
|
||||||
self.errmsg_nonnum = u"Seulement des nombres peuvent être convertis en mots."
|
self.errmsg_nonnum = (
|
||||||
|
u"Seulement des nombres peuvent être convertis en mots."
|
||||||
|
)
|
||||||
self.errmsg_toobig = u"Nombre trop grand pour être converti en mots."
|
self.errmsg_toobig = u"Nombre trop grand pour être converti en mots."
|
||||||
self.exclude_title = ["et", "virgule", "moins"]
|
self.exclude_title = ["et", "virgule", "moins"]
|
||||||
self.mid_numwords = [(1000, "mille"), (100, "cent"),
|
self.mid_numwords = [(1000, "mille"), (100, "cent"),
|
||||||
@@ -41,7 +43,6 @@ class Num2Word_FR(Num2Word_EU):
|
|||||||
"neuf": "neuvième",
|
"neuf": "neuvième",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def merge(self, curr, next):
|
def merge(self, curr, next):
|
||||||
ctext, cnum, ntext, nnum = curr + next
|
ctext, cnum, ntext, nnum = curr + next
|
||||||
|
|
||||||
@@ -49,24 +50,23 @@ class Num2Word_FR(Num2Word_EU):
|
|||||||
if nnum < 1000000:
|
if nnum < 1000000:
|
||||||
return next
|
return next
|
||||||
else:
|
else:
|
||||||
if (not (cnum - 80)%100 or not cnum%100) and ctext[-1] == "s":
|
if (not (cnum - 80) % 100 or not cnum % 100) and ctext[-1] == "s":
|
||||||
ctext = ctext[:-1]
|
ctext = ctext[:-1]
|
||||||
if cnum < 1000 and nnum != 1000 and ntext[-1] != "s" and not nnum % 100:
|
if cnum < 1000 and nnum != 1000 and ntext[-1] != "s" and not nnum % 100:
|
||||||
ntext += "s"
|
ntext += "s"
|
||||||
|
|
||||||
if nnum < cnum < 100:
|
if nnum < cnum < 100:
|
||||||
if nnum % 10 == 1 and cnum != 80:
|
if nnum % 10 == 1 and cnum != 80:
|
||||||
return ("%s et %s"%(ctext, ntext), cnum + nnum)
|
return ("%s et %s" % (ctext, ntext), cnum + nnum)
|
||||||
return ("%s-%s"%(ctext, ntext), cnum + nnum)
|
return ("%s-%s" % (ctext, ntext), cnum + nnum)
|
||||||
if nnum > cnum:
|
if nnum > cnum:
|
||||||
return ("%s %s"%(ctext, ntext), cnum * nnum)
|
return ("%s %s" % (ctext, ntext), cnum * nnum)
|
||||||
return ("%s %s"%(ctext, ntext), cnum + nnum)
|
return ("%s %s" % (ctext, ntext), cnum + nnum)
|
||||||
|
|
||||||
|
|
||||||
# Is this right for such things as 1001 - "mille unième" instead of
|
# Is this right for such things as 1001 - "mille unième" instead of
|
||||||
# "mille premier"?? "millième"??
|
# "mille premier"?? "millième"??
|
||||||
|
|
||||||
def to_ordinal(self,value):
|
def to_ordinal(self, value):
|
||||||
self.verify_ordinal(value)
|
self.verify_ordinal(value)
|
||||||
if value == 1:
|
if value == 1:
|
||||||
return "premier"
|
return "premier"
|
||||||
@@ -84,7 +84,7 @@ class Num2Word_FR(Num2Word_EU):
|
|||||||
def to_ordinal_num(self, value):
|
def to_ordinal_num(self, value):
|
||||||
self.verify_ordinal(value)
|
self.verify_ordinal(value)
|
||||||
out = str(value)
|
out = str(value)
|
||||||
out += {"1" : "er"}.get(out[-1], "me")
|
out += {"1": "er"}.get(out[-1], "me")
|
||||||
return out
|
return out
|
||||||
|
|
||||||
def to_currency(self, val, longval=True, old=False):
|
def to_currency(self, val, longval=True, old=False):
|
||||||
@@ -94,11 +94,13 @@ class Num2Word_FR(Num2Word_EU):
|
|||||||
return self.to_splitnum(val, hightxt=hightxt, lowtxt="centime/s",
|
return self.to_splitnum(val, hightxt=hightxt, lowtxt="centime/s",
|
||||||
jointxt="et", longval=longval)
|
jointxt="et", longval=longval)
|
||||||
|
|
||||||
|
|
||||||
n2w = Num2Word_FR()
|
n2w = Num2Word_FR()
|
||||||
to_card = n2w.to_cardinal
|
to_card = n2w.to_cardinal
|
||||||
to_ord = n2w.to_ordinal
|
to_ord = n2w.to_ordinal
|
||||||
to_ordnum = n2w.to_ordinal_num
|
to_ordnum = n2w.to_ordinal_num
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
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,
|
||||||
@@ -106,7 +108,8 @@ def main():
|
|||||||
-21212121211221211111, -2.121212, -1.0000100]:
|
-21212121211221211111, -2.121212, -1.0000100]:
|
||||||
n2w.test(val)
|
n2w.test(val)
|
||||||
|
|
||||||
n2w.test(1325325436067876801768700107601001012212132143210473207540327057320957032975032975093275093275093270957329057320975093272950730)
|
n2w.test(
|
||||||
|
1325325436067876801768700107601001012212132143210473207540327057320957032975032975093275093275093270957329057320975093272950730)
|
||||||
print(n2w.to_currency(112121))
|
print(n2w.to_currency(112121))
|
||||||
print(n2w.to_year(1996))
|
print(n2w.to_year(1996))
|
||||||
|
|
||||||
|
|||||||
@@ -24,10 +24,9 @@ class Num2Word_FR_CH(Num2Word_FR):
|
|||||||
Num2Word_FR.setup(self)
|
Num2Word_FR.setup(self)
|
||||||
|
|
||||||
self.mid_numwords = [(1000, "mille"), (100, "cent"), (90, "nonante"),
|
self.mid_numwords = [(1000, "mille"), (100, "cent"), (90, "nonante"),
|
||||||
(80, "huitante"), (70, "septante"), (60, "soixante"),
|
(80, "huitante"), (70, "septante"),
|
||||||
(50, "cinquante"), (40, "quarante"),
|
(60, "soixante"), (50, "cinquante"),
|
||||||
(30, "trente")]
|
(40, "quarante"), (30, "trente")]
|
||||||
|
|
||||||
|
|
||||||
def merge(self, curr, next):
|
def merge(self, curr, next):
|
||||||
ctext, cnum, ntext, nnum = curr + next
|
ctext, cnum, ntext, nnum = curr + next
|
||||||
@@ -41,11 +40,11 @@ class Num2Word_FR_CH(Num2Word_FR):
|
|||||||
|
|
||||||
if nnum < cnum < 100:
|
if nnum < cnum < 100:
|
||||||
if nnum % 10 == 1:
|
if nnum % 10 == 1:
|
||||||
return ("%s et %s"%(ctext, ntext), cnum + nnum)
|
return ("%s et %s" % (ctext, ntext), cnum + nnum)
|
||||||
return ("%s-%s"%(ctext, ntext), cnum + nnum)
|
return ("%s-%s" % (ctext, ntext), cnum + nnum)
|
||||||
if nnum > cnum:
|
if nnum > cnum:
|
||||||
return ("%s %s"%(ctext, ntext), cnum * nnum)
|
return ("%s %s" % (ctext, ntext), cnum * nnum)
|
||||||
return ("%s %s"%(ctext, ntext), cnum + nnum)
|
return ("%s %s" % (ctext, ntext), cnum + nnum)
|
||||||
|
|
||||||
|
|
||||||
n2w = Num2Word_FR_CH()
|
n2w = Num2Word_FR_CH()
|
||||||
@@ -53,6 +52,7 @@ to_card = n2w.to_cardinal
|
|||||||
to_ord = n2w.to_ordinal
|
to_ord = n2w.to_ordinal
|
||||||
to_ordnum = n2w.to_ordinal_num
|
to_ordnum = n2w.to_ordinal_num
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
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,
|
||||||
@@ -60,7 +60,8 @@ def main():
|
|||||||
-21212121211221211111, -2.121212, -1.0000100]:
|
-21212121211221211111, -2.121212, -1.0000100]:
|
||||||
n2w.test(val)
|
n2w.test(val)
|
||||||
|
|
||||||
n2w.test(1325325436067876801768700107601001012212132143210473207540327057320957032975032975093275093275093270957329057320975093272950730)
|
n2w.test(
|
||||||
|
1325325436067876801768700107601001012212132143210473207540327057320957032975032975093275093275093270957329057320975093272950730)
|
||||||
print(n2w.to_currency(112121))
|
print(n2w.to_currency(112121))
|
||||||
print(n2w.to_year(1996))
|
print(n2w.to_year(1996))
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ to_ordnum = n2w.to_ordinal_num
|
|||||||
to_year = n2w.to_year
|
to_year = n2w.to_year
|
||||||
to_currency = n2w.to_currency
|
to_currency = n2w.to_currency
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
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,
|
||||||
@@ -38,7 +39,8 @@ def main():
|
|||||||
-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, 1000, 1120, 1800, 1976, 2000, 2010, 2099, 2171]:
|
||||||
print(val, "is", n2w.to_currency(val))
|
print(val, "is", n2w.to_currency(val))
|
||||||
print(val, "is", n2w.to_year(val))
|
print(val, "is", n2w.to_year(val))
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ THOUSANDS = {
|
|||||||
|
|
||||||
AND = u'ו'
|
AND = u'ו'
|
||||||
|
|
||||||
|
|
||||||
def splitby3(n):
|
def splitby3(n):
|
||||||
length = len(n)
|
length = len(n)
|
||||||
if length > 3:
|
if length > 3:
|
||||||
@@ -76,7 +77,7 @@ def splitby3(n):
|
|||||||
if start > 0:
|
if start > 0:
|
||||||
yield int(n[:start])
|
yield int(n[:start])
|
||||||
for i in range(start, length, 3):
|
for i in range(start, length, 3):
|
||||||
yield int(n[i:i+3])
|
yield int(n[i:i + 3])
|
||||||
else:
|
else:
|
||||||
yield int(n)
|
yield int(n)
|
||||||
|
|
||||||
@@ -95,7 +96,7 @@ def pluralize(n, forms):
|
|||||||
|
|
||||||
|
|
||||||
def int2word(n):
|
def int2word(n):
|
||||||
if n > 9999: #doesn't yet work for numbers this big
|
if n > 9999: # doesn't yet work for numbers this big
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
if n == 0:
|
if n == 0:
|
||||||
@@ -159,4 +160,3 @@ if __name__ == '__main__':
|
|||||||
nums = [1, 11, 21, 24, 99, 100, 101, 200, 211, 345, 1000, 1011]
|
nums = [1, 11, 21, 24, 99, 100, 101, 200, 211, 345, 1000, 1011]
|
||||||
for num in nums:
|
for num in nums:
|
||||||
print(num, yo.to_cardinal(num))
|
print(num, yo.to_cardinal(num))
|
||||||
|
|
||||||
|
|||||||
@@ -16,8 +16,8 @@
|
|||||||
|
|
||||||
from __future__ import unicode_literals, print_function
|
from __future__ import unicode_literals, print_function
|
||||||
|
|
||||||
class Num2Word_ID():
|
|
||||||
|
|
||||||
|
class Num2Word_ID():
|
||||||
BASE = {0: [],
|
BASE = {0: [],
|
||||||
1: ["satu"],
|
1: ["satu"],
|
||||||
2: ["dua"],
|
2: ["dua"],
|
||||||
@@ -44,7 +44,7 @@ class Num2Word_ID():
|
|||||||
errmsg_floatord = "Cannot treat float number as ordinal"
|
errmsg_floatord = "Cannot treat float number as ordinal"
|
||||||
errmsg_negord = "Cannot treat negative number as ordinal"
|
errmsg_negord = "Cannot treat negative number as ordinal"
|
||||||
errmsg_toobig = "Too large"
|
errmsg_toobig = "Too large"
|
||||||
max_num = 10**36
|
max_num = 10 ** 36
|
||||||
|
|
||||||
def split_by_koma(self, number):
|
def split_by_koma(self, number):
|
||||||
return str(number).split('.')
|
return str(number).split('.')
|
||||||
@@ -69,7 +69,7 @@ class Num2Word_ID():
|
|||||||
blocks += first_block,
|
blocks += first_block,
|
||||||
|
|
||||||
for i in range(len_of_first_block, length, 3):
|
for i in range(len_of_first_block, length, 3):
|
||||||
next_block = (number[i:i+3],),
|
next_block = (number[i:i + 3],),
|
||||||
blocks += next_block
|
blocks += next_block
|
||||||
|
|
||||||
return blocks
|
return blocks
|
||||||
@@ -77,7 +77,9 @@ class Num2Word_ID():
|
|||||||
def spell(self, blocks):
|
def spell(self, blocks):
|
||||||
"""
|
"""
|
||||||
it adds the list of spelling to the blocks
|
it adds the list of spelling to the blocks
|
||||||
(('1',),('034',)) -> (('1',['satu']),('234',['tiga', 'puluh', 'empat']))
|
(
|
||||||
|
('1',),('034',)) -> (('1',['satu']),('234',['tiga', 'puluh', 'empat'])
|
||||||
|
)
|
||||||
:param blocks: tuple
|
:param blocks: tuple
|
||||||
:rtype: tuple
|
:rtype: tuple
|
||||||
"""
|
"""
|
||||||
@@ -91,7 +93,9 @@ class Num2Word_ID():
|
|||||||
elif len(first_block[0]) == 2:
|
elif len(first_block[0]) == 2:
|
||||||
spelling = self.puluh(first_block[0])
|
spelling = self.puluh(first_block[0])
|
||||||
else:
|
else:
|
||||||
spelling = self.ratus(first_block[0][0]) + self.puluh(first_block[0][1:3])
|
spelling = (
|
||||||
|
self.ratus(first_block[0][0]) + self.puluh(first_block[0][1:3])
|
||||||
|
)
|
||||||
|
|
||||||
word_blocks += (first_block[0], spelling),
|
word_blocks += (first_block[0], spelling),
|
||||||
|
|
||||||
@@ -109,21 +113,23 @@ class Num2Word_ID():
|
|||||||
elif number == '0':
|
elif number == '0':
|
||||||
return []
|
return []
|
||||||
else:
|
else:
|
||||||
return self.BASE[int(number)]+['ratus']
|
return self.BASE[int(number)] + ['ratus']
|
||||||
|
|
||||||
def puluh(self, number):
|
def puluh(self, number):
|
||||||
# it is used to spell
|
# it is used to spell
|
||||||
if number[0] == '1':
|
if number[0] == '1':
|
||||||
if number[1]== '0':
|
if number[1] == '0':
|
||||||
return ['sepuluh']
|
return ['sepuluh']
|
||||||
elif number[1] == '1':
|
elif number[1] == '1':
|
||||||
return ['sebelas']
|
return ['sebelas']
|
||||||
else:
|
else:
|
||||||
return self.BASE[int(number[1])]+['belas']
|
return self.BASE[int(number[1])] + ['belas']
|
||||||
elif number[0] == '0':
|
elif number[0] == '0':
|
||||||
return self.BASE[int(number[1])]
|
return self.BASE[int(number[1])]
|
||||||
else:
|
else:
|
||||||
return self.BASE[int(number[0])]+['puluh']+ self.BASE[int(number[1])]
|
return (
|
||||||
|
self.BASE[int(number[0])] + ['puluh'] + self.BASE[int(number[1])]
|
||||||
|
)
|
||||||
|
|
||||||
def spell_float(self, float_part):
|
def spell_float(self, float_part):
|
||||||
# spell the float number
|
# spell the float number
|
||||||
@@ -133,7 +139,7 @@ class Num2Word_ID():
|
|||||||
word_list += ['nol']
|
word_list += ['nol']
|
||||||
continue
|
continue
|
||||||
word_list += self.BASE[int(n)]
|
word_list += self.BASE[int(n)]
|
||||||
return ' '.join(['','koma']+word_list)
|
return ' '.join(['', 'koma'] + word_list)
|
||||||
|
|
||||||
def join(self, word_blocks, float_part):
|
def join(self, word_blocks, float_part):
|
||||||
"""
|
"""
|
||||||
@@ -142,7 +148,7 @@ class Num2Word_ID():
|
|||||||
:rtype: str
|
:rtype: str
|
||||||
"""
|
"""
|
||||||
word_list = []
|
word_list = []
|
||||||
length = len(word_blocks)-1
|
length = len(word_blocks) - 1
|
||||||
first_block = word_blocks[0],
|
first_block = word_blocks[0],
|
||||||
start = 0
|
start = 0
|
||||||
|
|
||||||
@@ -150,15 +156,15 @@ class Num2Word_ID():
|
|||||||
word_list += ['seribu']
|
word_list += ['seribu']
|
||||||
start = 1
|
start = 1
|
||||||
|
|
||||||
for i in range(start, length+1, 1):
|
for i in range(start, length + 1, 1):
|
||||||
word_list += word_blocks[i][1]
|
word_list += word_blocks[i][1]
|
||||||
if not word_blocks[i][1]:
|
if not word_blocks[i][1]:
|
||||||
continue
|
continue
|
||||||
if i == length:
|
if i == length:
|
||||||
break
|
break
|
||||||
word_list += [self.TENS_TO[(length-i)*3]]
|
word_list += [self.TENS_TO[(length - i) * 3]]
|
||||||
|
|
||||||
return ' '.join(word_list)+float_part
|
return ' '.join(word_list) + float_part
|
||||||
|
|
||||||
def to_cardinal(self, number):
|
def to_cardinal(self, number):
|
||||||
if number >= self.max_num:
|
if number >= self.max_num:
|
||||||
@@ -168,7 +174,7 @@ class Num2Word_ID():
|
|||||||
minus = 'min '
|
minus = 'min '
|
||||||
float_word = ''
|
float_word = ''
|
||||||
n = self.split_by_koma(abs(number))
|
n = self.split_by_koma(abs(number))
|
||||||
if len(n)==2:
|
if len(n) == 2:
|
||||||
float_word = self.spell_float(n[1])
|
float_word = self.spell_float(n[1])
|
||||||
return minus + self.join(self.spell(self.split_by_3(n[0])), float_word)
|
return minus + self.join(self.spell(self.split_by_3(n[0])), float_word)
|
||||||
|
|
||||||
@@ -184,7 +190,7 @@ class Num2Word_ID():
|
|||||||
return "ke-" + str(number)
|
return "ke-" + str(number)
|
||||||
|
|
||||||
def to_currency(self, value):
|
def to_currency(self, value):
|
||||||
return self.to_cardinal(value)+" rupiah"
|
return self.to_cardinal(value) + " rupiah"
|
||||||
|
|
||||||
def to_year(self, value):
|
def to_year(self, value):
|
||||||
return self.to_cardinal(value)
|
return self.to_cardinal(value)
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ EXPONENT_PREFIXES = [
|
|||||||
ZERO, "m", "b", "tr", "quadr", "quint", "sest", "sett", "ott", "nov", "dec"
|
ZERO, "m", "b", "tr", "quadr", "quint", "sest", "sett", "ott", "nov", "dec"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
# Utils
|
# Utils
|
||||||
# =====
|
# =====
|
||||||
|
|
||||||
@@ -53,6 +54,7 @@ def phonetic_contraction(string):
|
|||||||
.replace("au", "u") # ex. "trentauno"
|
.replace("au", "u") # ex. "trentauno"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def exponent_length_to_string(exponent_length):
|
def exponent_length_to_string(exponent_length):
|
||||||
# We always assume `exponent` to be a multiple of 3. If it's not true, then
|
# We always assume `exponent` to be a multiple of 3. If it's not true, then
|
||||||
# Num2Word_IT.big_number_to_cardinal did something wrong.
|
# Num2Word_IT.big_number_to_cardinal did something wrong.
|
||||||
@@ -62,6 +64,7 @@ def exponent_length_to_string(exponent_length):
|
|||||||
else:
|
else:
|
||||||
return prefix + "iliardo"
|
return prefix + "iliardo"
|
||||||
|
|
||||||
|
|
||||||
def accentuate(string):
|
def accentuate(string):
|
||||||
# This is inefficient: it may do several rewritings when deleting
|
# This is inefficient: it may do several rewritings when deleting
|
||||||
# half-sentence accents. However, it is the easiest method and speed is
|
# half-sentence accents. However, it is the easiest method and speed is
|
||||||
@@ -78,14 +81,15 @@ def accentuate(string):
|
|||||||
for w in string.split()
|
for w in string.split()
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
def omitt_if_zero(number_to_string):
|
def omitt_if_zero(number_to_string):
|
||||||
return "" if number_to_string == ZERO else number_to_string
|
return "" if number_to_string == ZERO else number_to_string
|
||||||
|
|
||||||
|
|
||||||
# Main class
|
# Main class
|
||||||
# ==========
|
# ==========
|
||||||
|
|
||||||
class Num2Word_IT:
|
class Num2Word_IT:
|
||||||
|
|
||||||
MINUS_PREFIX_WORD = "meno "
|
MINUS_PREFIX_WORD = "meno "
|
||||||
FLOAT_INFIX_WORD = " virgola "
|
FLOAT_INFIX_WORD = " virgola "
|
||||||
|
|
||||||
|
|||||||
@@ -153,6 +153,7 @@ CURRENCIES = {
|
|||||||
'EUR': ((u'euras', u'eurai', u'eurų'), (u'centas', u'centai', u'centų')),
|
'EUR': ((u'euras', u'eurai', u'eurų'), (u'centas', u'centai', u'centų')),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def splitby3(n):
|
def splitby3(n):
|
||||||
length = len(n)
|
length = len(n)
|
||||||
if length > 3:
|
if length > 3:
|
||||||
@@ -160,7 +161,7 @@ def splitby3(n):
|
|||||||
if start > 0:
|
if start > 0:
|
||||||
yield int(n[:start])
|
yield int(n[:start])
|
||||||
for i in range(start, length, 3):
|
for i in range(start, length, 3):
|
||||||
yield int(n[i:i+3])
|
yield int(n[i:i + 3])
|
||||||
else:
|
else:
|
||||||
yield int(n)
|
yield int(n)
|
||||||
|
|
||||||
@@ -168,6 +169,7 @@ def splitby3(n):
|
|||||||
def get_digits(n):
|
def get_digits(n):
|
||||||
return [int(x) for x in reversed(list(('%03d' % n)[-3:]))]
|
return [int(x) for x in reversed(list(('%03d' % n)[-3:]))]
|
||||||
|
|
||||||
|
|
||||||
def pluralize(n, forms):
|
def pluralize(n, forms):
|
||||||
n1, n2, n3 = get_digits(n)
|
n1, n2, n3 = get_digits(n)
|
||||||
if n2 == 1 or n1 == 0 or n == 0:
|
if n2 == 1 or n1 == 0 or n == 0:
|
||||||
@@ -177,6 +179,7 @@ def pluralize(n, forms):
|
|||||||
else:
|
else:
|
||||||
return forms[1]
|
return forms[1]
|
||||||
|
|
||||||
|
|
||||||
def int2word(n):
|
def int2word(n):
|
||||||
if n == 0:
|
if n == 0:
|
||||||
return ZERO[0]
|
return ZERO[0]
|
||||||
@@ -209,6 +212,7 @@ def int2word(n):
|
|||||||
|
|
||||||
return ' '.join(words)
|
return ' '.join(words)
|
||||||
|
|
||||||
|
|
||||||
def n2w(n):
|
def n2w(n):
|
||||||
n = str(n).replace(',', '.')
|
n = str(n).replace(',', '.')
|
||||||
if '.' in n:
|
if '.' in n:
|
||||||
@@ -217,7 +221,8 @@ def n2w(n):
|
|||||||
else:
|
else:
|
||||||
return int2word(int(n))
|
return int2word(int(n))
|
||||||
|
|
||||||
def to_currency(n, currency='EUR', cents = True):
|
|
||||||
|
def to_currency(n, currency='EUR', cents=True):
|
||||||
if type(n) == int:
|
if type(n) == int:
|
||||||
if n < 0:
|
if n < 0:
|
||||||
minus = True
|
minus = True
|
||||||
@@ -247,9 +252,11 @@ def to_currency(n, currency='EUR', cents = True):
|
|||||||
else:
|
else:
|
||||||
cents_str = "%02d" % right
|
cents_str = "%02d" % right
|
||||||
|
|
||||||
return u'%s%s %s, %s %s' % (minus_str, int2word(left), pluralize(left, cr1),
|
return u'%s%s %s, %s %s' % (minus_str, int2word(left),
|
||||||
|
pluralize(left, cr1),
|
||||||
cents_str, pluralize(right, cr2))
|
cents_str, pluralize(right, cr2))
|
||||||
|
|
||||||
|
|
||||||
class Num2Word_LT(object):
|
class Num2Word_LT(object):
|
||||||
def to_cardinal(self, number):
|
def to_cardinal(self, number):
|
||||||
return n2w(number)
|
return n2w(number)
|
||||||
@@ -257,6 +264,8 @@ class Num2Word_LT(object):
|
|||||||
def to_ordinal(self, number):
|
def to_ordinal(self, number):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import doctest
|
import doctest
|
||||||
|
|
||||||
doctest.testmod()
|
doctest.testmod()
|
||||||
|
|||||||
@@ -18,21 +18,35 @@
|
|||||||
from __future__ import unicode_literals, print_function
|
from __future__ import unicode_literals, print_function
|
||||||
from .lang_EU import Num2Word_EU
|
from .lang_EU import Num2Word_EU
|
||||||
|
|
||||||
|
|
||||||
class Num2Word_NL(Num2Word_EU):
|
class Num2Word_NL(Num2Word_EU):
|
||||||
def set_high_numwords(self, high):
|
def set_high_numwords(self, high):
|
||||||
max = 3 + 6*len(high)
|
max = 3 + 6 * len(high)
|
||||||
|
|
||||||
for word, n in zip(high, range(max, 3, -6)):
|
for word, n in zip(high, range(max, 3, -6)):
|
||||||
self.cards[10**n] = word + "iljard"
|
self.cards[10 ** n] = word + "iljard"
|
||||||
self.cards[10**(n-3)] = word + "iljoen"
|
self.cards[10 ** (n - 3)] = word + "iljoen"
|
||||||
|
|
||||||
def setup(self):
|
def setup(self):
|
||||||
self.negword = "min "
|
self.negword = "min "
|
||||||
self.pointword = "komma"
|
self.pointword = "komma"
|
||||||
self.errmsg_floatord = "Het zwevende puntnummer %s kan niet omgezet worden naar een ordernummer." # "Cannot treat float %s as ordinal."
|
# "Cannot treat float %s as ordinal."
|
||||||
self.errmsg_nonnum = "Alleen nummers (type (%s)) kunnen naar woorden omgezet worden." # "type(((type(%s)) ) not in [long, int, float]"
|
self.errmsg_floatord = (
|
||||||
self.errmsg_negord = "Het negatieve getal %s kan niet omgezet worden naar een ordernummer." # "Cannot treat negative num %s as ordinal."
|
"Het zwevende puntnummer %s kan niet omgezet worden " +
|
||||||
self.errmsg_toobig = "Het getal %s moet minder zijn dan %s." # "abs(%s) must be less than %s."
|
"naar een ordernummer."
|
||||||
|
)
|
||||||
|
# "type(((type(%s)) ) not in [long, int, float]"
|
||||||
|
self.errmsg_nonnum = (
|
||||||
|
"Alleen nummers (type (%s)) kunnen naar " +
|
||||||
|
"woorden omgezet worden."
|
||||||
|
)
|
||||||
|
# "Cannot treat negative num %s as ordinal."
|
||||||
|
self.errmsg_negord = (
|
||||||
|
"Het negatieve getal %s kan niet omgezet " +
|
||||||
|
"worden naar een ordernummer."
|
||||||
|
)
|
||||||
|
# "abs(%s) must be less than %s."
|
||||||
|
self.errmsg_toobig = "Het getal %s moet minder zijn dan %s."
|
||||||
self.exclude_title = []
|
self.exclude_title = []
|
||||||
|
|
||||||
lows = ["non", "okt", "sept", "sext", "quint", "quadr", "tr", "b", "m"]
|
lows = ["non", "okt", "sept", "sext", "quint", "quadr", "tr", "b", "m"]
|
||||||
@@ -41,13 +55,13 @@ class Num2Word_NL(Num2Word_EU):
|
|||||||
tens = ["dez", "vigint", "trigint", "quadragint", "quinquagint",
|
tens = ["dez", "vigint", "trigint", "quadragint", "quinquagint",
|
||||||
"sexagint", "septuagint", "oktogint", "nonagint"]
|
"sexagint", "septuagint", "oktogint", "nonagint"]
|
||||||
|
|
||||||
|
self.high_numwords = (
|
||||||
|
["zend"] + self.gen_high_numwords(units, tens, lows)
|
||||||
|
)
|
||||||
self.high_numwords = ["zend"]+self.gen_high_numwords(units, tens, lows)
|
|
||||||
self.mid_numwords = [(1000, "duizend"), (100, "honderd"),
|
self.mid_numwords = [(1000, "duizend"), (100, "honderd"),
|
||||||
(90, "negentig"), (80, "tachtig"), (70, "zeventig"),
|
(90, "negentig"), (80, "tachtig"),
|
||||||
(60, "zestig"), (50, "vijftig"), (40, "veertig"),
|
(70, "zeventig"), (60, "zestig"),
|
||||||
|
(50, "vijftig"), (40, "veertig"),
|
||||||
(30, "dertig")]
|
(30, "dertig")]
|
||||||
self.low_numwords = ["twintig", "negentien", "achttien", "zeventien",
|
self.low_numwords = ["twintig", "negentien", "achttien", "zeventien",
|
||||||
"zestien", "vijftien", "veertien", "dertien",
|
"zestien", "vijftien", "veertien", "dertien",
|
||||||
@@ -64,9 +78,9 @@ class Num2Word_NL(Num2Word_EU):
|
|||||||
"zeven": "zevend",
|
"zeven": "zevend",
|
||||||
"acht": "achtst",
|
"acht": "achtst",
|
||||||
"negen": "negend",
|
"negen": "negend",
|
||||||
"tien":"tiend",
|
"tien": "tiend",
|
||||||
"elf":"elfd",
|
"elf": "elfd",
|
||||||
"twaalf":"twaalfd",
|
"twaalf": "twaalfd",
|
||||||
|
|
||||||
"ig": "igst",
|
"ig": "igst",
|
||||||
"erd": "erdst",
|
"erd": "erdst",
|
||||||
@@ -78,12 +92,12 @@ class Num2Word_NL(Num2Word_EU):
|
|||||||
ctext, cnum, ntext, nnum = curr + next
|
ctext, cnum, ntext, nnum = curr + next
|
||||||
|
|
||||||
if cnum == 1:
|
if cnum == 1:
|
||||||
if nnum < 10**6:
|
if nnum < 10 ** 6:
|
||||||
return next
|
return next
|
||||||
ctext = "een"
|
ctext = "een"
|
||||||
|
|
||||||
if nnum > cnum:
|
if nnum > cnum:
|
||||||
if nnum >= 10**6:
|
if nnum >= 10 ** 6:
|
||||||
ctext += " "
|
ctext += " "
|
||||||
val = cnum * nnum
|
val = cnum * nnum
|
||||||
else:
|
else:
|
||||||
@@ -92,11 +106,11 @@ class Num2Word_NL(Num2Word_EU):
|
|||||||
ntext = "een"
|
ntext = "een"
|
||||||
|
|
||||||
if ntext.endswith("e"):
|
if ntext.endswith("e"):
|
||||||
ntext += "ën"#"n"
|
ntext += "ën" # "n"
|
||||||
else:
|
else:
|
||||||
ntext += "en"
|
ntext += "en"
|
||||||
ntext, ctext = ctext, ntext #+ "en"
|
ntext, ctext = ctext, ntext # + "en"
|
||||||
elif cnum >= 10**6:
|
elif cnum >= 10 ** 6:
|
||||||
ctext += " "
|
ctext += " "
|
||||||
val = cnum + nnum
|
val = cnum + nnum
|
||||||
|
|
||||||
@@ -119,15 +133,16 @@ class Num2Word_NL(Num2Word_EU):
|
|||||||
def to_currency(self, val, longval=True, old=False):
|
def to_currency(self, val, longval=True, old=False):
|
||||||
if old:
|
if old:
|
||||||
return self.to_splitnum(val, hightxt="euro/s", lowtxt="cent/s",
|
return self.to_splitnum(val, hightxt="euro/s", lowtxt="cent/s",
|
||||||
jointxt="en",longval=longval)
|
jointxt="en", longval=longval)
|
||||||
return super(Num2Word_NL, self).to_currency(val, jointxt="en",
|
return super(Num2Word_NL, self).to_currency(val, jointxt="en",
|
||||||
longval=longval)
|
longval=longval)
|
||||||
|
|
||||||
def to_year(self, val, longval=True):
|
def to_year(self, val, longval=True):
|
||||||
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="honderd", longval=longval)
|
return self.to_splitnum(val, hightxt="honderd", longval=longval)
|
||||||
|
|
||||||
|
|
||||||
n2w = Num2Word_NL()
|
n2w = Num2Word_NL()
|
||||||
to_card = n2w.to_cardinal
|
to_card = n2w.to_cardinal
|
||||||
to_ord = n2w.to_ordinal
|
to_ord = n2w.to_ordinal
|
||||||
@@ -135,10 +150,11 @@ to_ordnum = n2w.to_ordinal_num
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
for val in [1, 7, 8, 12, 17, 62,81, 91, 99, 100, 101, 102, 155,
|
for val in [1, 7, 8, 12, 17, 62, 81, 91, 99, 100, 101, 102, 155,
|
||||||
180, 300, 308, 832, 1000, 1001, 1061,1062, 1100, 1500, 1701, 3000,
|
180, 300, 308, 832, 1000, 1001, 1061, 1062, 1100, 1500, 1701,
|
||||||
8280, 8291, 150000, 500000, 3000000, 1000000, 2000001, 1000000000, 2000000000,
|
3000, 8280, 8291, 150000, 500000, 3000000, 1000000, 2000001,
|
||||||
-21212121211221211111, -2.121212, -1.0000100]:
|
1000000000, 2000000000, -21212121211221211111, -2.121212,
|
||||||
|
-1.0000100]:
|
||||||
n2w.test(val)
|
n2w.test(val)
|
||||||
|
|
||||||
n2w.test(3000000)
|
n2w.test(3000000)
|
||||||
@@ -149,6 +165,6 @@ def main():
|
|||||||
print(n2w.to_year(1820))
|
print(n2w.to_year(1820))
|
||||||
print(n2w.to_year(2001))
|
print(n2w.to_year(2001))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
|||||||
@@ -17,12 +17,13 @@
|
|||||||
from __future__ import division, unicode_literals, print_function
|
from __future__ import division, unicode_literals, print_function
|
||||||
from . import lang_EU
|
from . import lang_EU
|
||||||
|
|
||||||
|
|
||||||
class Num2Word_NO(lang_EU.Num2Word_EU):
|
class Num2Word_NO(lang_EU.Num2Word_EU):
|
||||||
def set_high_numwords(self, high):
|
def set_high_numwords(self, high):
|
||||||
max = 3 + 6*len(high)
|
max = 3 + 6 * len(high)
|
||||||
for word, n in zip(high, range(max, 3, -6)):
|
for word, n in zip(high, range(max, 3, -6)):
|
||||||
self.cards[10**n] = word + "illard"
|
self.cards[10 ** n] = word + "illard"
|
||||||
self.cards[10**(n-3)] = word + "illion"
|
self.cards[10 ** (n - 3)] = word + "illion"
|
||||||
|
|
||||||
def setup(self):
|
def setup(self):
|
||||||
self.negword = "minus "
|
self.negword = "minus "
|
||||||
@@ -39,34 +40,32 @@ class Num2Word_NO(lang_EU.Num2Word_EU):
|
|||||||
"tolv", "elleve", "ti", "ni", "\xe5tte",
|
"tolv", "elleve", "ti", "ni", "\xe5tte",
|
||||||
"syv", "seks", "fem", "fire", "tre", "to",
|
"syv", "seks", "fem", "fire", "tre", "to",
|
||||||
"en", "null"]
|
"en", "null"]
|
||||||
self.ords = { "en" : "f\xf8rste",
|
self.ords = {"en": "f\xf8rste",
|
||||||
"to" : "andre",
|
"to": "andre",
|
||||||
"tre" : "tredje",
|
"tre": "tredje",
|
||||||
"fire" : "fjerde",
|
"fire": "fjerde",
|
||||||
"fem" : "femte",
|
"fem": "femte",
|
||||||
"seks" : "sjette",
|
"seks": "sjette",
|
||||||
"syv" : "syvende",
|
"syv": "syvende",
|
||||||
"\xe5tte" : "\xe5ttende",
|
"\xe5tte": "\xe5ttende",
|
||||||
"ni" : "niende",
|
"ni": "niende",
|
||||||
"ti" : "tiende",
|
"ti": "tiende",
|
||||||
"elleve" : "ellevte",
|
"elleve": "ellevte",
|
||||||
"tolv" : "tolvte",
|
"tolv": "tolvte",
|
||||||
"tjue" : "tjuende" }
|
"tjue": "tjuende"}
|
||||||
|
|
||||||
|
|
||||||
def merge(self, lpair, rpair):
|
def merge(self, lpair, rpair):
|
||||||
ltext, lnum = lpair
|
ltext, lnum = lpair
|
||||||
rtext, rnum = rpair
|
rtext, rnum = rpair
|
||||||
if lnum == 1 and rnum < 100:
|
if lnum == 1 and rnum < 100:
|
||||||
return (rtext, rnum)
|
return (rtext, rnum)
|
||||||
elif 100 > lnum > rnum :
|
elif 100 > lnum > rnum:
|
||||||
return ("%s-%s"%(ltext, rtext), lnum + rnum)
|
return ("%s-%s" % (ltext, rtext), lnum + rnum)
|
||||||
elif lnum >= 100 > rnum:
|
elif lnum >= 100 > rnum:
|
||||||
return ("%s og %s"%(ltext, rtext), lnum + rnum)
|
return ("%s og %s" % (ltext, rtext), lnum + rnum)
|
||||||
elif rnum > lnum:
|
elif rnum > lnum:
|
||||||
return ("%s %s"%(ltext, rtext), lnum * rnum)
|
return ("%s %s" % (ltext, rtext), lnum * rnum)
|
||||||
return ("%s, %s"%(ltext, rtext), lnum + rnum)
|
return ("%s, %s" % (ltext, rtext), lnum + rnum)
|
||||||
|
|
||||||
|
|
||||||
def to_ordinal(self, value):
|
def to_ordinal(self, value):
|
||||||
self.verify_ordinal(value)
|
self.verify_ordinal(value)
|
||||||
@@ -84,21 +83,19 @@ class Num2Word_NO(lang_EU.Num2Word_EU):
|
|||||||
outwords[-1] = "".join(lastwords)
|
outwords[-1] = "".join(lastwords)
|
||||||
return " ".join(outwords)
|
return " ".join(outwords)
|
||||||
|
|
||||||
|
|
||||||
def to_ordinal_num(self, value):
|
def to_ordinal_num(self, value):
|
||||||
self.verify_ordinal(value)
|
self.verify_ordinal(value)
|
||||||
return "%s%s"%(value, self.to_ordinal(value)[-2:])
|
return "%s%s" % (value, self.to_ordinal(value)[-2:])
|
||||||
|
|
||||||
|
|
||||||
def to_year(self, val, longval=True):
|
def to_year(self, val, longval=True):
|
||||||
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="hundre", jointxt="og",
|
return self.to_splitnum(val, hightxt="hundre", jointxt="og",
|
||||||
longval=longval)
|
longval=longval)
|
||||||
|
|
||||||
def to_currency(self, val, longval=True):
|
def to_currency(self, val, longval=True):
|
||||||
return self.to_splitnum(val, hightxt="krone/r", lowtxt="\xf8re/r",
|
return self.to_splitnum(val, hightxt="krone/r", lowtxt="\xf8re/r",
|
||||||
jointxt="og", longval=longval, cents = True)
|
jointxt="og", longval=longval, cents=True)
|
||||||
|
|
||||||
|
|
||||||
n2w = Num2Word_NO()
|
n2w = Num2Word_NO()
|
||||||
@@ -107,14 +104,15 @@ to_ord = n2w.to_ordinal
|
|||||||
to_ordnum = n2w.to_ordinal_num
|
to_ordnum = n2w.to_ordinal_num
|
||||||
to_year = n2w.to_year
|
to_year = n2w.to_year
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
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, 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))
|
||||||
|
|
||||||
|
|||||||
@@ -163,7 +163,7 @@ THOUSANDS = {
|
|||||||
6: (u'trylion', u'tryliony', u'trylionów'), # 10^18
|
6: (u'trylion', u'tryliony', u'trylionów'), # 10^18
|
||||||
7: (u'tryliard', u'tryliardy', u'tryliardów'), # 10^21
|
7: (u'tryliard', u'tryliardy', u'tryliardów'), # 10^21
|
||||||
8: (u'kwadrylion', u'kwadryliony', u'kwadrylionów'), # 10^24
|
8: (u'kwadrylion', u'kwadryliony', u'kwadrylionów'), # 10^24
|
||||||
9: (u'kwaryliard', u'kwadryliardy', u'kwadryliardów'), #10^27
|
9: (u'kwaryliard', u'kwadryliardy', u'kwadryliardów'), # 10^27
|
||||||
10: (u'kwintylion', u'kwintyliony', u'kwintylionów'), # 10^30
|
10: (u'kwintylion', u'kwintyliony', u'kwintylionów'), # 10^30
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -235,7 +235,7 @@ def n2w(n):
|
|||||||
return int2word(int(n))
|
return int2word(int(n))
|
||||||
|
|
||||||
|
|
||||||
def to_currency(n, currency = 'EUR', cents = True, seperator = ','):
|
def to_currency(n, currency='EUR', cents=True, seperator=','):
|
||||||
if type(n) == int:
|
if type(n) == int:
|
||||||
if n < 0:
|
if n < 0:
|
||||||
minus = True
|
minus = True
|
||||||
@@ -287,4 +287,5 @@ class Num2Word_PL(object):
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import doctest
|
import doctest
|
||||||
|
|
||||||
doctest.testmod()
|
doctest.testmod()
|
||||||
|
|||||||
@@ -174,7 +174,7 @@ THOUSANDS = {
|
|||||||
6: (u'квинтиллион', u'квинтиллиона', u'квинтиллионов'), # 10^18
|
6: (u'квинтиллион', u'квинтиллиона', u'квинтиллионов'), # 10^18
|
||||||
7: (u'секстиллион', u'секстиллиона', u'секстиллионов'), # 10^21
|
7: (u'секстиллион', u'секстиллиона', u'секстиллионов'), # 10^21
|
||||||
8: (u'септиллион', u'септиллиона', u'септиллионов'), # 10^24
|
8: (u'септиллион', u'септиллиона', u'септиллионов'), # 10^24
|
||||||
9: (u'октиллион', u'октиллиона', u'октиллионов'), #10^27
|
9: (u'октиллион', u'октиллиона', u'октиллионов'), # 10^27
|
||||||
10: (u'нониллион', u'нониллиона', u'нониллионов'), # 10^30
|
10: (u'нониллион', u'нониллиона', u'нониллионов'), # 10^30
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,7 +195,7 @@ def splitby3(n):
|
|||||||
if start > 0:
|
if start > 0:
|
||||||
yield int(n[:start])
|
yield int(n[:start])
|
||||||
for i in range(start, length, 3):
|
for i in range(start, length, 3):
|
||||||
yield int(n[i:i+3])
|
yield int(n[i:i + 3])
|
||||||
else:
|
else:
|
||||||
yield int(n)
|
yield int(n)
|
||||||
|
|
||||||
@@ -309,4 +309,5 @@ class Num2Word_RU(object):
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import doctest
|
import doctest
|
||||||
|
|
||||||
doctest.testmod()
|
doctest.testmod()
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
from .lang_EU import Num2Word_EU
|
from .lang_EU import Num2Word_EU
|
||||||
|
|
||||||
|
|
||||||
class Num2Word_SL(Num2Word_EU):
|
class Num2Word_SL(Num2Word_EU):
|
||||||
def set_high_numwords(self, high):
|
def set_high_numwords(self, high):
|
||||||
max = 3 + 6*len(high)
|
max = 3 + 6*len(high)
|
||||||
@@ -29,7 +30,6 @@ class Num2Word_SL(Num2Word_EU):
|
|||||||
self.cards[10**n] = word + "iljard"
|
self.cards[10**n] = word + "iljard"
|
||||||
self.cards[10**(n-3)] = word + "iljon"
|
self.cards[10**(n-3)] = word + "iljon"
|
||||||
|
|
||||||
|
|
||||||
def setup(self):
|
def setup(self):
|
||||||
self.negword = "minus "
|
self.negword = "minus "
|
||||||
self.pointword = "celih"
|
self.pointword = "celih"
|
||||||
@@ -37,30 +37,33 @@ class Num2Word_SL(Num2Word_EU):
|
|||||||
self.errmsg_toobig = "Number is too large to convert to words."
|
self.errmsg_toobig = "Number is too large to convert to words."
|
||||||
self.exclude_title = []
|
self.exclude_title = []
|
||||||
|
|
||||||
self.mid_numwords = [(1000, "tisoč"), (900, "devetsto"), (800, "osemsto"),
|
self.mid_numwords = [(1000, "tisoč"), (900, "devetsto"),
|
||||||
(700, "sedemsto"), (600, "šesto"), (500, "petsto"), (400, "štiristo"), (300, "tristo"),
|
(800, "osemsto"), (700, "sedemsto"),
|
||||||
|
(600, "šesto"), (500, "petsto"),
|
||||||
|
(400, "štiristo"), (300, "tristo"),
|
||||||
(200, "dvesto"), (100, "sto"),
|
(200, "dvesto"), (100, "sto"),
|
||||||
(90, "devetdeset"), (80, "osemdeset"), (70, "sedemdeset"),
|
(90, "devetdeset"), (80, "osemdeset"),
|
||||||
(60, "šestdeset"), (50, "petdeset"), (40, "štirideset"),
|
(70, "sedemdeset"), (60, "šestdeset"),
|
||||||
|
(50, "petdeset"), (40, "štirideset"),
|
||||||
(30, "trideset")]
|
(30, "trideset")]
|
||||||
self.low_numwords = ["dvajset", "devetnajst", "osemnajst", "sedemnajst",
|
self.low_numwords = ["dvajset", "devetnajst", "osemnajst",
|
||||||
"šestnajst", "petnajst", "štirinajst", "trinajst",
|
"sedemnajst", "šestnajst", "petnajst",
|
||||||
"dvanajst", "enajst", "deset", "devet", "osem", "sedem",
|
"štirinajst", "trinajst", "dvanajst",
|
||||||
|
"enajst", "deset", "devet", "osem", "sedem",
|
||||||
"šest", "pet", "štiri", "tri", "dve", "ena",
|
"šest", "pet", "štiri", "tri", "dve", "ena",
|
||||||
"nič"]
|
"nič"]
|
||||||
self.ords = { "ena" : "prv",
|
self.ords = {"ena": "prv",
|
||||||
"dve" : "drug",
|
"dve": "drug",
|
||||||
"tri" : "tretj",
|
"tri": "tretj",
|
||||||
"štiri" : "četrt",
|
"štiri": "četrt",
|
||||||
"sedem" : "sedm",
|
"sedem": "sedm",
|
||||||
"osem" : "osm",
|
"osem": "osm",
|
||||||
"sto" : "stot",
|
"sto": "stot",
|
||||||
"tisoč" : "tisoč",
|
"tisoč": "tisoč",
|
||||||
"miljon" : "miljont"
|
"miljon": "miljont"
|
||||||
}
|
}
|
||||||
self.ordflag = False
|
self.ordflag = False
|
||||||
|
|
||||||
|
|
||||||
def merge(self, curr, next):
|
def merge(self, curr, next):
|
||||||
ctext, cnum, ntext, nnum = curr + next
|
ctext, cnum, ntext, nnum = curr + next
|
||||||
|
|
||||||
@@ -97,21 +100,20 @@ class Num2Word_SL(Num2Word_EU):
|
|||||||
else:
|
else:
|
||||||
ntext += "ov"
|
ntext += "ov"
|
||||||
|
|
||||||
if nnum >= 10**2 and self.ordflag == False:
|
if nnum >= 10**2 and self.ordflag is False:
|
||||||
ctext += " "
|
ctext += " "
|
||||||
|
|
||||||
val = cnum * nnum
|
val = cnum * nnum
|
||||||
else:
|
else:
|
||||||
if nnum < 10 < cnum < 100:
|
if nnum < 10 < cnum < 100:
|
||||||
ntext, ctext = ctext, ntext + "in"
|
ntext, ctext = ctext, ntext + "in"
|
||||||
elif cnum >= 10**2 and self.ordflag == False:
|
elif cnum >= 10**2 and self.ordflag is False:
|
||||||
ctext += " "
|
ctext += " "
|
||||||
val = cnum + nnum
|
val = cnum + nnum
|
||||||
|
|
||||||
word = ctext + ntext
|
word = ctext + ntext
|
||||||
return (word, val)
|
return (word, val)
|
||||||
|
|
||||||
|
|
||||||
def to_ordinal(self, value):
|
def to_ordinal(self, value):
|
||||||
self.verify_ordinal(value)
|
self.verify_ordinal(value)
|
||||||
self.ordflag = True
|
self.ordflag = True
|
||||||
@@ -123,27 +125,25 @@ class Num2Word_SL(Num2Word_EU):
|
|||||||
break
|
break
|
||||||
return outword + "i"
|
return outword + "i"
|
||||||
|
|
||||||
|
|
||||||
# Is this correct??
|
# Is this correct??
|
||||||
def to_ordinal_num(self, value):
|
def to_ordinal_num(self, value):
|
||||||
self.verify_ordinal(value)
|
self.verify_ordinal(value)
|
||||||
return str(value) + "."
|
return str(value) + "."
|
||||||
|
|
||||||
|
|
||||||
def to_currency(self, val, longval=True, old=False):
|
def to_currency(self, val, longval=True, old=False):
|
||||||
if old:
|
if old:
|
||||||
return self.to_splitnum(val, hightxt="evro/a/v", lowtxt="stotin/a/i/ov",
|
return self.to_splitnum(val, hightxt="evro/a/v",
|
||||||
jointxt="in",longval=longval)
|
lowtxt="stotin/a/i/ov",
|
||||||
|
jointxt="in", longval=longval)
|
||||||
return super(Num2Word_SL, self).to_currency(val, jointxt="in",
|
return super(Num2Word_SL, self).to_currency(val, jointxt="in",
|
||||||
longval=longval)
|
longval=longval)
|
||||||
|
|
||||||
def to_year(self, val, longval=True):
|
def to_year(self, val, longval=True):
|
||||||
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="hundert", longval=longval)
|
return self.to_splitnum(val, hightxt="hundert", longval=longval)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
n2w = Num2Word_SL()
|
n2w = Num2Word_SL()
|
||||||
to_card = n2w.to_cardinal
|
to_card = n2w.to_cardinal
|
||||||
to_ord = n2w.to_ordinal
|
to_ord = n2w.to_ordinal
|
||||||
@@ -151,7 +151,7 @@ to_ordnum = n2w.to_ordinal_num
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
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]:
|
||||||
@@ -161,5 +161,6 @@ def main():
|
|||||||
print(n2w.to_currency(112121))
|
print(n2w.to_currency(112121))
|
||||||
print(n2w.to_year(2000))
|
print(n2w.to_year(2000))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
@@ -541,7 +541,8 @@ class Num2Word_TR(object):
|
|||||||
if not int(val) == 0:
|
if not int(val) == 0:
|
||||||
self.integers_to_read = [str(int(val)), float_digits[len(float_digits) - self.precision:]]
|
self.integers_to_read = [str(int(val)), float_digits[len(float_digits) - self.precision:]]
|
||||||
else:
|
else:
|
||||||
self.integers_to_read = ["0", "0" * (self.precision - len(float_digits)) + float_digits[len(float_digits) - self.precision:]]
|
self.integers_to_read = ["0", "0" * (self.precision - len(float_digits))
|
||||||
|
+ float_digits[len(float_digits) - self.precision:]]
|
||||||
if len(self.integers_to_read[0]) % 3 > 0:
|
if len(self.integers_to_read[0]) % 3 > 0:
|
||||||
self.total_triplets_to_read = (len(self.integers_to_read[0]) // 3) + 1
|
self.total_triplets_to_read = (len(self.integers_to_read[0]) // 3) + 1
|
||||||
elif len(self.integers_to_read[0]) % 3 == 0:
|
elif len(self.integers_to_read[0]) % 3 == 0:
|
||||||
|
|||||||
@@ -174,13 +174,14 @@ THOUSANDS = {
|
|||||||
6: (u'квiнтильйон', u'квiнтильйони', u'квiнтильйонiв'), # 10^18
|
6: (u'квiнтильйон', u'квiнтильйони', u'квiнтильйонiв'), # 10^18
|
||||||
7: (u'секстильйон', u'секстильйони', u'секстильйонiв'), # 10^21
|
7: (u'секстильйон', u'секстильйони', u'секстильйонiв'), # 10^21
|
||||||
8: (u'септильйон', u'септильйони', u'септильйонiв'), # 10^24
|
8: (u'септильйон', u'септильйони', u'септильйонiв'), # 10^24
|
||||||
9: (u'октильйон', u'октильйони', u'октильйонiв'), #10^27
|
9: (u'октильйон', u'октильйони', u'октильйонiв'), # 10^27
|
||||||
10: (u'нонiльйон', u'нонiльйони', u'нонiльйонiв'), # 10^30
|
10: (u'нонiльйон', u'нонiльйони', u'нонiльйонiв'), # 10^30
|
||||||
}
|
}
|
||||||
|
|
||||||
CURRENCIES = {
|
CURRENCIES = {
|
||||||
'UAH': (
|
'UAH': (
|
||||||
(u'гривня', u'гривнi', u'гривень'), (u'копiйка', u'копiйки', u'копiйок')
|
(u'гривня', u'гривнi', u'гривень'),
|
||||||
|
(u'копiйка', u'копiйки', u'копiйок')
|
||||||
),
|
),
|
||||||
'EUR': (
|
'EUR': (
|
||||||
(u'евро', u'евро', u'евро'), (u'цент', u'центи', u'центiв')
|
(u'евро', u'евро', u'евро'), (u'цент', u'центи', u'центiв')
|
||||||
@@ -195,7 +196,7 @@ def splitby3(n):
|
|||||||
if start > 0:
|
if start > 0:
|
||||||
yield int(n[:start])
|
yield int(n[:start])
|
||||||
for i in range(start, length, 3):
|
for i in range(start, length, 3):
|
||||||
yield int(n[i:i+3])
|
yield int(n[i:i + 3])
|
||||||
else:
|
else:
|
||||||
yield int(n)
|
yield int(n)
|
||||||
|
|
||||||
@@ -205,7 +206,8 @@ def get_digits(n):
|
|||||||
|
|
||||||
|
|
||||||
def pluralize(n, forms):
|
def pluralize(n, forms):
|
||||||
#form = 0 if n==1 else 1 if (n % 10 > 1 and n % 10 < 5 and (n % 100 < 10 or n % 100 > 20)) else 2
|
# form = 0 if n==1 else 1 if (n % 10 > 1 and n % 10 < 5 and (n % 100 < 10
|
||||||
|
# or n % 100 > 20)) else 2
|
||||||
if (n % 100 < 10 or n % 100 > 20):
|
if (n % 100 < 10 or n % 100 > 20):
|
||||||
if n % 10 == 1:
|
if n % 10 == 1:
|
||||||
form = 0
|
form = 0
|
||||||
@@ -241,13 +243,12 @@ def int2word(n, feminine=True):
|
|||||||
|
|
||||||
if n2 == 1:
|
if n2 == 1:
|
||||||
words.append(TENS[n1][0])
|
words.append(TENS[n1][0])
|
||||||
#elif n1 > 0 and not (i > 0 and x == 1):
|
# elif n1 > 0 and not (i > 0 and x == 1):
|
||||||
elif n1 > 0:
|
elif n1 > 0:
|
||||||
ones = ONES_FEMININE if i == 1 or feminine and i == 0 else ONES
|
ones = ONES_FEMININE if i == 1 or feminine and i == 0 else ONES
|
||||||
words.append(ones[n1][0])
|
words.append(ones[n1][0])
|
||||||
|
|
||||||
|
if i > 0 and ((n1 + n2 + n3) > 0):
|
||||||
if i > 0 and ((n1+n2+n3) > 0):
|
|
||||||
words.append(pluralize(x, THOUSANDS[i]))
|
words.append(pluralize(x, THOUSANDS[i]))
|
||||||
|
|
||||||
return ' '.join(words)
|
return ' '.join(words)
|
||||||
@@ -313,4 +314,5 @@ class Num2Word_UK(object):
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import doctest
|
import doctest
|
||||||
|
|
||||||
doctest.testmod()
|
doctest.testmod()
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
# MA 02110-1301 USA
|
# MA 02110-1301 USA
|
||||||
|
|
||||||
|
|
||||||
class OrderedMapping(dict):
|
class OrderedMapping(dict):
|
||||||
def __init__(self, *pairs):
|
def __init__(self, *pairs):
|
||||||
self.order = []
|
self.order = []
|
||||||
@@ -30,6 +31,6 @@ class OrderedMapping(dict):
|
|||||||
yield item
|
yield item
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
out = ["%s: %s"%(repr(item), repr(self[item])) for item in self]
|
out = ["%s: %s" % (repr(item), repr(self[item])) for item in self]
|
||||||
out = ", ".join(out)
|
out = ", ".join(out)
|
||||||
return "{%s}"%out
|
return "{%s}" % out
|
||||||
|
|||||||
Reference in New Issue
Block a user