mirror of
https://github.com/bblaz/num2words.git
synced 2025-12-06 06:42:25 +00:00
Issue 229: Add explicit encoding, license and unix line separators.
Some maintainers for different linux distribution are having some problems with the encoding on different python versions. This change intents to make all python files define explicitly the encoding, license and unix line separators. Remove one example of the README.rst file where a possible non UTF-8 character is used.
This commit is contained in:
@@ -46,8 +46,6 @@ Command line::
|
|||||||
|
|
||||||
$ num2words 10001
|
$ num2words 10001
|
||||||
ten thousand and one
|
ten thousand and one
|
||||||
$ num2words 10123123 --lang es
|
|
||||||
diez millones ciento veintitrés mil ciento veintitrés
|
|
||||||
$ num2words 24,120.10
|
$ num2words 24,120.10
|
||||||
twenty-four thousand, one hundred and twenty point one
|
twenty-four thousand, one hundred and twenty point one
|
||||||
$ num2words 24,120.10 -l es
|
$ num2words 24,120.10 -l es
|
||||||
|
|||||||
@@ -1,5 +1,21 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
|
# This library is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU Lesser General Public
|
||||||
|
# License as published by the Free Software Foundation; either
|
||||||
|
# version 2.1 of the License, or (at your option) any later version.
|
||||||
|
# This library is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
# Lesser General Public License for more details.
|
||||||
|
# You should have received a copy of the GNU Lesser General Public
|
||||||
|
# License along with this library; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
# MA 02110-1301 USA
|
||||||
|
|
||||||
"""num2words: convert numbers into words.
|
"""num2words: convert numbers into words.
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
@@ -22,9 +38,6 @@ Options:
|
|||||||
Examples:
|
Examples:
|
||||||
$ num2words 10001
|
$ num2words 10001
|
||||||
ten thousand and one
|
ten thousand and one
|
||||||
|
|
||||||
$ num2words 10123123 --lang es
|
|
||||||
diez millones ciento veintitrés mil ciento veintitrés
|
|
||||||
|
|
||||||
$ num2words 24,120.10
|
$ num2words 24,120.10
|
||||||
twenty-four thousand, one hundred and twenty point one
|
twenty-four thousand, one hundred and twenty point one
|
||||||
@@ -35,6 +48,7 @@ Examples:
|
|||||||
$num2words 2.14 -l es --to currency
|
$num2words 2.14 -l es --to currency
|
||||||
dos euros con catorce centimos
|
dos euros con catorce centimos
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import print_function, unicode_literals
|
from __future__ import print_function, unicode_literals
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|||||||
7
docker-compose.yml
Normal file
7
docker-compose.yml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
version: '3.0'
|
||||||
|
services:
|
||||||
|
web:
|
||||||
|
image: python:3-alpine
|
||||||
|
command: python3 -m http.server 8080
|
||||||
|
volumes:
|
||||||
|
- .:/num2words
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
# Copyright (c) 2016, Savoir-faire Linux inc. All Rights Reserved.
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
# This library is free software; you can redistribute it and/or
|
# This library is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU Lesser General Public
|
# modify it under the terms of the GNU Lesser General Public
|
||||||
|
|||||||
@@ -1,3 +1,20 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
|
# This library is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU Lesser General Public
|
||||||
|
# License as published by the Free Software Foundation; either
|
||||||
|
# version 2.1 of the License, or (at your option) any later version.
|
||||||
|
# This library is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
# Lesser General Public License for more details.
|
||||||
|
# You should have received a copy of the GNU Lesser General Public
|
||||||
|
# License along with this library; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
# MA 02110-1301 USA
|
||||||
|
|
||||||
from __future__ import division
|
from __future__ import division
|
||||||
|
|
||||||
from decimal import ROUND_HALF_UP, Decimal
|
from decimal import ROUND_HALF_UP, Decimal
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
@@ -14,6 +14,7 @@
|
|||||||
# License along with this library; if not, write to the Free Software
|
# License along with this library; if not, write to the Free Software
|
||||||
# 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
|
||||||
|
|
||||||
from .base import Num2Word_Base
|
from .base import Num2Word_Base
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
# encoding: UTF-8
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
# encoding: UTF-8
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
# encoding: UTF-8
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
@@ -14,7 +14,6 @@
|
|||||||
# License along with this library; if not, write to the Free Software
|
# License along with this library; if not, write to the Free Software
|
||||||
# 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 print_function, unicode_literals
|
from __future__ import print_function, unicode_literals
|
||||||
|
|
||||||
from .lang_FR import Num2Word_FR
|
from .lang_FR import Num2Word_FR
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
|
|||||||
@@ -1,150 +1,150 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
# This library is free software; you can redistribute it and/or
|
# This library is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU Lesser General Public
|
# modify it under the terms of the GNU Lesser General Public
|
||||||
# License as published by the Free Software Foundation; either
|
# License as published by the Free Software Foundation; either
|
||||||
# version 2.1 of the License, or (at your option) any later version.
|
# version 2.1 of the License, or (at your option) any later version.
|
||||||
# This library is distributed in the hope that it will be useful,
|
# This library is distributed in the hope that it will be useful,
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
# Lesser General Public License for more details.
|
# Lesser General Public License for more details.
|
||||||
# You should have received a copy of the GNU Lesser General Public
|
# You should have received a copy of the GNU Lesser General Public
|
||||||
# License along with this library; if not, write to the Free Software
|
# License along with this library; if not, write to the Free Software
|
||||||
# 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 print_function, unicode_literals
|
from __future__ import print_function, unicode_literals
|
||||||
|
|
||||||
from .utils import get_digits, splitbyx
|
from .utils import get_digits, splitbyx
|
||||||
|
|
||||||
ZERO = (u'אפס',)
|
ZERO = (u'אפס',)
|
||||||
|
|
||||||
ONES = {
|
ONES = {
|
||||||
1: (u'אחד',),
|
1: (u'אחד',),
|
||||||
2: (u'שנים',),
|
2: (u'שנים',),
|
||||||
3: (u'שלש',),
|
3: (u'שלש',),
|
||||||
4: (u'ארבע',),
|
4: (u'ארבע',),
|
||||||
5: (u'חמש',),
|
5: (u'חמש',),
|
||||||
6: (u'שש',),
|
6: (u'שש',),
|
||||||
7: (u'שבע',),
|
7: (u'שבע',),
|
||||||
8: (u'שמנה',),
|
8: (u'שמנה',),
|
||||||
9: (u'תשע',),
|
9: (u'תשע',),
|
||||||
}
|
}
|
||||||
|
|
||||||
TENS = {
|
TENS = {
|
||||||
0: (u'עשר',),
|
0: (u'עשר',),
|
||||||
1: (u'אחד עשרה',),
|
1: (u'אחד עשרה',),
|
||||||
2: (u'שנים עשרה',),
|
2: (u'שנים עשרה',),
|
||||||
3: (u'שלש עשרה',),
|
3: (u'שלש עשרה',),
|
||||||
4: (u'ארבע עשרה',),
|
4: (u'ארבע עשרה',),
|
||||||
5: (u'חמש עשרה',),
|
5: (u'חמש עשרה',),
|
||||||
6: (u'שש עשרה',),
|
6: (u'שש עשרה',),
|
||||||
7: (u'שבע עשרה',),
|
7: (u'שבע עשרה',),
|
||||||
8: (u'שמנה עשרה',),
|
8: (u'שמנה עשרה',),
|
||||||
9: (u'תשע עשרה',),
|
9: (u'תשע עשרה',),
|
||||||
}
|
}
|
||||||
|
|
||||||
TWENTIES = {
|
TWENTIES = {
|
||||||
2: (u'עשרים',),
|
2: (u'עשרים',),
|
||||||
3: (u'שלשים',),
|
3: (u'שלשים',),
|
||||||
4: (u'ארבעים',),
|
4: (u'ארבעים',),
|
||||||
5: (u'חמישים',),
|
5: (u'חמישים',),
|
||||||
6: (u'ששים',),
|
6: (u'ששים',),
|
||||||
7: (u'שבעים',),
|
7: (u'שבעים',),
|
||||||
8: (u'שמנים',),
|
8: (u'שמנים',),
|
||||||
9: (u'תשעים',),
|
9: (u'תשעים',),
|
||||||
}
|
}
|
||||||
|
|
||||||
HUNDRED = {
|
HUNDRED = {
|
||||||
1: (u'מאה',),
|
1: (u'מאה',),
|
||||||
2: (u'מאתיים',),
|
2: (u'מאתיים',),
|
||||||
3: (u'מאות',)
|
3: (u'מאות',)
|
||||||
}
|
}
|
||||||
|
|
||||||
THOUSANDS = {
|
THOUSANDS = {
|
||||||
1: (u'אלף',),
|
1: (u'אלף',),
|
||||||
2: (u'אלפיים',),
|
2: (u'אלפיים',),
|
||||||
}
|
}
|
||||||
|
|
||||||
AND = u'ו'
|
AND = u'ו'
|
||||||
|
|
||||||
|
|
||||||
def pluralize(n, forms):
|
def pluralize(n, forms):
|
||||||
# gettext implementation:
|
# gettext implementation:
|
||||||
# (n%10==1 && n%100!=11 ? 0 : n != 0 ? 1 : 2)
|
# (n%10==1 && n%100!=11 ? 0 : n != 0 ? 1 : 2)
|
||||||
|
|
||||||
form = 0 if (n % 10 == 1 and n % 100 != 11) else 1 if n != 0 else 2
|
form = 0 if (n % 10 == 1 and n % 100 != 11) else 1 if n != 0 else 2
|
||||||
|
|
||||||
return forms[form]
|
return forms[form]
|
||||||
|
|
||||||
|
|
||||||
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:
|
||||||
return ZERO[0]
|
return ZERO[0]
|
||||||
|
|
||||||
words = []
|
words = []
|
||||||
|
|
||||||
chunks = list(splitbyx(str(n), 3))
|
chunks = list(splitbyx(str(n), 3))
|
||||||
i = len(chunks)
|
i = len(chunks)
|
||||||
for x in chunks:
|
for x in chunks:
|
||||||
i -= 1
|
i -= 1
|
||||||
|
|
||||||
if x == 0:
|
if x == 0:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
n1, n2, n3 = get_digits(x)
|
n1, n2, n3 = get_digits(x)
|
||||||
|
|
||||||
if n3 > 0:
|
if n3 > 0:
|
||||||
if n3 <= 2:
|
if n3 <= 2:
|
||||||
words.append(HUNDRED[n3][0])
|
words.append(HUNDRED[n3][0])
|
||||||
else:
|
else:
|
||||||
words.append(ONES[n3][0])
|
words.append(ONES[n3][0])
|
||||||
words.append(HUNDRED[3][0])
|
words.append(HUNDRED[3][0])
|
||||||
|
|
||||||
if n2 > 1:
|
if n2 > 1:
|
||||||
words.append(TWENTIES[n2][0])
|
words.append(TWENTIES[n2][0])
|
||||||
|
|
||||||
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):
|
||||||
words.append(ONES[n1][0])
|
words.append(ONES[n1][0])
|
||||||
|
|
||||||
if i > 0:
|
if i > 0:
|
||||||
if i <= 2:
|
if i <= 2:
|
||||||
words.append(THOUSANDS[i][0])
|
words.append(THOUSANDS[i][0])
|
||||||
else:
|
else:
|
||||||
words.append(ONES[i][0])
|
words.append(ONES[i][0])
|
||||||
words.append(THOUSANDS[1][0])
|
words.append(THOUSANDS[1][0])
|
||||||
|
|
||||||
if len(words) > 1:
|
if len(words) > 1:
|
||||||
words[-1] = AND + words[-1]
|
words[-1] = AND + words[-1]
|
||||||
return ' '.join(words)
|
return ' '.join(words)
|
||||||
|
|
||||||
|
|
||||||
def n2w(n):
|
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=','):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
|
||||||
class Num2Word_HE(object):
|
class Num2Word_HE(object):
|
||||||
def to_cardinal(self, number):
|
def to_cardinal(self, number):
|
||||||
return n2w(number)
|
return n2w(number)
|
||||||
|
|
||||||
def to_ordinal(self, number):
|
def to_ordinal(self, number):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
yo = Num2Word_HE()
|
yo = Num2Word_HE()
|
||||||
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))
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
#
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
# This library is free software; you can redistribute it and/or
|
# This library is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU Lesser General Public
|
# modify it under the terms of the GNU Lesser General Public
|
||||||
# License as published by the Free Software Foundation; either
|
# License as published by the Free Software Foundation; either
|
||||||
|
|||||||
@@ -1,179 +1,179 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
# This library is free software; you can redistribute it and/or
|
# This library is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU Lesser General Public
|
# modify it under the terms of the GNU Lesser General Public
|
||||||
# License as published by the Free Software Foundation; either
|
# License as published by the Free Software Foundation; either
|
||||||
# version 2.1 of the License, or (at your option) any later version.
|
# version 2.1 of the License, or (at your option) any later version.
|
||||||
# This library is distributed in the hope that it will be useful,
|
# This library is distributed in the hope that it will be useful,
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
# Lesser General Public License for more details.
|
# Lesser General Public License for more details.
|
||||||
# You should have received a copy of the GNU Lesser General Public
|
# You should have received a copy of the GNU Lesser General Public
|
||||||
# License along with this library; if not, write to the Free Software
|
# License along with this library; if not, write to the Free Software
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
# MA 02110-1301 USA
|
# MA 02110-1301 USA
|
||||||
# TODO: replace WINDOWS line endings to UNIX?
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from .base import Num2Word_Base
|
from .base import Num2Word_Base
|
||||||
from .utils import get_digits, splitbyx
|
from .utils import get_digits, splitbyx
|
||||||
|
|
||||||
ZERO = ('nulis',)
|
ZERO = ('nulis',)
|
||||||
|
|
||||||
ONES_FEMININE = {
|
ONES_FEMININE = {
|
||||||
1: ('viena',),
|
1: ('viena',),
|
||||||
2: ('dvi',),
|
2: ('dvi',),
|
||||||
3: ('trys',),
|
3: ('trys',),
|
||||||
4: ('keturios',),
|
4: ('keturios',),
|
||||||
5: ('penkios',),
|
5: ('penkios',),
|
||||||
6: ('šešios',),
|
6: ('šešios',),
|
||||||
7: ('septynios',),
|
7: ('septynios',),
|
||||||
8: ('aštuonios',),
|
8: ('aštuonios',),
|
||||||
9: ('devynios',),
|
9: ('devynios',),
|
||||||
}
|
}
|
||||||
|
|
||||||
ONES = {
|
ONES = {
|
||||||
1: ('vienas',),
|
1: ('vienas',),
|
||||||
2: ('du',),
|
2: ('du',),
|
||||||
3: ('trys',),
|
3: ('trys',),
|
||||||
4: ('keturi',),
|
4: ('keturi',),
|
||||||
5: ('penki',),
|
5: ('penki',),
|
||||||
6: ('šeši',),
|
6: ('šeši',),
|
||||||
7: ('septyni',),
|
7: ('septyni',),
|
||||||
8: ('aštuoni',),
|
8: ('aštuoni',),
|
||||||
9: ('devyni',),
|
9: ('devyni',),
|
||||||
}
|
}
|
||||||
|
|
||||||
TENS = {
|
TENS = {
|
||||||
0: ('dešimt',),
|
0: ('dešimt',),
|
||||||
1: ('vienuolika',),
|
1: ('vienuolika',),
|
||||||
2: ('dvylika',),
|
2: ('dvylika',),
|
||||||
3: ('trylika',),
|
3: ('trylika',),
|
||||||
4: ('keturiolika',),
|
4: ('keturiolika',),
|
||||||
5: ('penkiolika',),
|
5: ('penkiolika',),
|
||||||
6: ('šešiolika',),
|
6: ('šešiolika',),
|
||||||
7: ('septyniolika',),
|
7: ('septyniolika',),
|
||||||
8: ('aštuoniolika',),
|
8: ('aštuoniolika',),
|
||||||
9: ('devyniolika',),
|
9: ('devyniolika',),
|
||||||
}
|
}
|
||||||
|
|
||||||
TWENTIES = {
|
TWENTIES = {
|
||||||
2: ('dvidešimt',),
|
2: ('dvidešimt',),
|
||||||
3: ('trisdešimt',),
|
3: ('trisdešimt',),
|
||||||
4: ('keturiasdešimt',),
|
4: ('keturiasdešimt',),
|
||||||
5: ('penkiasdešimt',),
|
5: ('penkiasdešimt',),
|
||||||
6: ('šešiasdešimt',),
|
6: ('šešiasdešimt',),
|
||||||
7: ('septyniasdešimt',),
|
7: ('septyniasdešimt',),
|
||||||
8: ('aštuoniasdešimt',),
|
8: ('aštuoniasdešimt',),
|
||||||
9: ('devyniasdešimt',),
|
9: ('devyniasdešimt',),
|
||||||
}
|
}
|
||||||
|
|
||||||
HUNDRED = ('šimtas', 'šimtai')
|
HUNDRED = ('šimtas', 'šimtai')
|
||||||
|
|
||||||
THOUSANDS = {
|
THOUSANDS = {
|
||||||
1: ('tūkstantis', 'tūkstančiai', 'tūkstančių'),
|
1: ('tūkstantis', 'tūkstančiai', 'tūkstančių'),
|
||||||
2: ('milijonas', 'milijonai', 'milijonų'),
|
2: ('milijonas', 'milijonai', 'milijonų'),
|
||||||
3: ('milijardas', 'milijardai', 'milijardų'),
|
3: ('milijardas', 'milijardai', 'milijardų'),
|
||||||
4: ('trilijonas', 'trilijonai', 'trilijonų'),
|
4: ('trilijonas', 'trilijonai', 'trilijonų'),
|
||||||
5: ('kvadrilijonas', 'kvadrilijonai', 'kvadrilijonų'),
|
5: ('kvadrilijonas', 'kvadrilijonai', 'kvadrilijonų'),
|
||||||
6: ('kvintilijonas', 'kvintilijonai', 'kvintilijonų'),
|
6: ('kvintilijonas', 'kvintilijonai', 'kvintilijonų'),
|
||||||
7: ('sikstilijonas', 'sikstilijonai', 'sikstilijonų'),
|
7: ('sikstilijonas', 'sikstilijonai', 'sikstilijonų'),
|
||||||
8: ('septilijonas', 'septilijonai', 'septilijonų'),
|
8: ('septilijonas', 'septilijonai', 'septilijonų'),
|
||||||
9: ('oktilijonas', 'oktilijonai', 'oktilijonų'),
|
9: ('oktilijonas', 'oktilijonai', 'oktilijonų'),
|
||||||
10: ('naintilijonas', 'naintilijonai', 'naintilijonų'),
|
10: ('naintilijonas', 'naintilijonai', 'naintilijonų'),
|
||||||
}
|
}
|
||||||
|
|
||||||
GENERIC_CENTS = ('centas', 'centai', 'centų')
|
GENERIC_CENTS = ('centas', 'centai', 'centų')
|
||||||
|
|
||||||
|
|
||||||
class Num2Word_LT(Num2Word_Base):
|
class Num2Word_LT(Num2Word_Base):
|
||||||
CURRENCY_FORMS = {
|
CURRENCY_FORMS = {
|
||||||
'LTL': (('litas', 'litai', 'litų'), GENERIC_CENTS),
|
'LTL': (('litas', 'litai', 'litų'), GENERIC_CENTS),
|
||||||
'EUR': (('euras', 'eurai', 'eurų'), GENERIC_CENTS),
|
'EUR': (('euras', 'eurai', 'eurų'), GENERIC_CENTS),
|
||||||
'USD': (('doleris', 'doleriai', 'dolerių'), GENERIC_CENTS),
|
'USD': (('doleris', 'doleriai', 'dolerių'), GENERIC_CENTS),
|
||||||
'GBP': (
|
'GBP': (
|
||||||
('svaras sterlingų', 'svarai sterlingų', 'svarų sterlingų'),
|
('svaras sterlingų', 'svarai sterlingų', 'svarų sterlingų'),
|
||||||
('pensas', 'pensai', 'pensų')
|
('pensas', 'pensai', 'pensų')
|
||||||
),
|
),
|
||||||
'PLN': (
|
'PLN': (
|
||||||
('zlotas', 'zlotai', 'zlotų'),
|
('zlotas', 'zlotai', 'zlotų'),
|
||||||
('grašis', 'grašiai', 'grašių')),
|
('grašis', 'grašiai', 'grašių')),
|
||||||
'RUB': (
|
'RUB': (
|
||||||
('rublis', 'rubliai', 'rublių'),
|
('rublis', 'rubliai', 'rublių'),
|
||||||
('kapeika', 'kapeikos', 'kapeikų')
|
('kapeika', 'kapeikos', 'kapeikų')
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
def setup(self):
|
def setup(self):
|
||||||
self.negword = "minus"
|
self.negword = "minus"
|
||||||
self.pointword = "kablelis"
|
self.pointword = "kablelis"
|
||||||
|
|
||||||
def pluralize(self, n, forms):
|
def pluralize(self, 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:
|
||||||
return forms[2]
|
return forms[2]
|
||||||
elif n1 == 1:
|
elif n1 == 1:
|
||||||
return forms[0]
|
return forms[0]
|
||||||
else:
|
else:
|
||||||
return forms[1]
|
return forms[1]
|
||||||
|
|
||||||
def to_cardinal(self, number):
|
def to_cardinal(self, number):
|
||||||
n = str(number).replace(',', '.')
|
n = str(number).replace(',', '.')
|
||||||
base_str, n = self.parse_minus(n)
|
base_str, n = self.parse_minus(n)
|
||||||
if '.' in n:
|
if '.' in n:
|
||||||
left, right = n.split('.')
|
left, right = n.split('.')
|
||||||
return '%s%s %s %s' % (
|
return '%s%s %s %s' % (
|
||||||
base_str,
|
base_str,
|
||||||
self._int2word(int(left)),
|
self._int2word(int(left)),
|
||||||
self.pointword,
|
self.pointword,
|
||||||
self._int2word(int(right))
|
self._int2word(int(right))
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
return "%s%s" % (base_str, self._int2word(int(n)))
|
return "%s%s" % (base_str, self._int2word(int(n)))
|
||||||
|
|
||||||
def to_ordinal(self, number):
|
def to_ordinal(self, number):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
def _cents_verbose(self, number, currency):
|
def _cents_verbose(self, number, currency):
|
||||||
return self._int2word(number, currency == 'RUB')
|
return self._int2word(number, currency == 'RUB')
|
||||||
|
|
||||||
def _int2word(self, n, feminine=False):
|
def _int2word(self, n, feminine=False):
|
||||||
if n == 0:
|
if n == 0:
|
||||||
return ZERO[0]
|
return ZERO[0]
|
||||||
|
|
||||||
words = []
|
words = []
|
||||||
chunks = list(splitbyx(str(n), 3))
|
chunks = list(splitbyx(str(n), 3))
|
||||||
i = len(chunks)
|
i = len(chunks)
|
||||||
|
|
||||||
for x in chunks:
|
for x in chunks:
|
||||||
i -= 1
|
i -= 1
|
||||||
|
|
||||||
if x == 0:
|
if x == 0:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
n1, n2, n3 = get_digits(x)
|
n1, n2, n3 = get_digits(x)
|
||||||
|
|
||||||
if n3 > 0:
|
if n3 > 0:
|
||||||
words.append(ONES[n3][0])
|
words.append(ONES[n3][0])
|
||||||
if n3 > 1:
|
if n3 > 1:
|
||||||
words.append(HUNDRED[1])
|
words.append(HUNDRED[1])
|
||||||
else:
|
else:
|
||||||
words.append(HUNDRED[0])
|
words.append(HUNDRED[0])
|
||||||
|
|
||||||
if n2 > 1:
|
if n2 > 1:
|
||||||
words.append(TWENTIES[n2][0])
|
words.append(TWENTIES[n2][0])
|
||||||
|
|
||||||
if n2 == 1:
|
if n2 == 1:
|
||||||
words.append(TENS[n1][0])
|
words.append(TENS[n1][0])
|
||||||
elif n1 > 0:
|
elif n1 > 0:
|
||||||
if (i == 1 or feminine and i == 0) and n < 1000:
|
if (i == 1 or feminine and i == 0) and n < 1000:
|
||||||
words.append(ONES_FEMININE[n1][0])
|
words.append(ONES_FEMININE[n1][0])
|
||||||
else:
|
else:
|
||||||
words.append(ONES[n1][0])
|
words.append(ONES[n1][0])
|
||||||
|
|
||||||
if i > 0:
|
if i > 0:
|
||||||
words.append(self.pluralize(x, THOUSANDS[i]))
|
words.append(self.pluralize(x, THOUSANDS[i]))
|
||||||
|
|
||||||
return ' '.join(words)
|
return ' '.join(words)
|
||||||
|
|||||||
@@ -1,186 +1,186 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
# This library is free software; you can redistribute it and/or
|
# This library is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU Lesser General Public
|
# modify it under the terms of the GNU Lesser General Public
|
||||||
# License as published by the Free Software Foundation; either
|
# License as published by the Free Software Foundation; either
|
||||||
# version 2.1 of the License, or (at your option) any later version.
|
# version 2.1 of the License, or (at your option) any later version.
|
||||||
# This library is distributed in the hope that it will be useful,
|
# This library is distributed in the hope that it will be useful,
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
# Lesser General Public License for more details.
|
# Lesser General Public License for more details.
|
||||||
# You should have received a copy of the GNU Lesser General Public
|
# You should have received a copy of the GNU Lesser General Public
|
||||||
# License along with this library; if not, write to the Free Software
|
# License along with this library; if not, write to the Free Software
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
# MA 02110-1301 USA
|
# MA 02110-1301 USA
|
||||||
# TODO: replace WINDOWS line endings to UNIX?
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from .base import Num2Word_Base
|
from .base import Num2Word_Base
|
||||||
from .utils import get_digits, splitbyx
|
from .utils import get_digits, splitbyx
|
||||||
|
|
||||||
ZERO = ('nulle',)
|
ZERO = ('nulle',)
|
||||||
|
|
||||||
ONES = {
|
ONES = {
|
||||||
1: ('viens',),
|
1: ('viens',),
|
||||||
2: ('divi',),
|
2: ('divi',),
|
||||||
3: ('trīs',),
|
3: ('trīs',),
|
||||||
4: ('četri',),
|
4: ('četri',),
|
||||||
5: ('pieci',),
|
5: ('pieci',),
|
||||||
6: ('seši',),
|
6: ('seši',),
|
||||||
7: ('septiņi',),
|
7: ('septiņi',),
|
||||||
8: ('astoņi',),
|
8: ('astoņi',),
|
||||||
9: ('deviņi',),
|
9: ('deviņi',),
|
||||||
}
|
}
|
||||||
|
|
||||||
TENS = {
|
TENS = {
|
||||||
0: ('desmit',),
|
0: ('desmit',),
|
||||||
1: ('vienpadsmit',),
|
1: ('vienpadsmit',),
|
||||||
2: ('divpadsmit',),
|
2: ('divpadsmit',),
|
||||||
3: ('trīspadsmit',),
|
3: ('trīspadsmit',),
|
||||||
4: ('četrpadsmit',),
|
4: ('četrpadsmit',),
|
||||||
5: ('piecpadsmit',),
|
5: ('piecpadsmit',),
|
||||||
6: ('sešpadsmit',),
|
6: ('sešpadsmit',),
|
||||||
7: ('septiņpadsmit',),
|
7: ('septiņpadsmit',),
|
||||||
8: ('astoņpadsmit',),
|
8: ('astoņpadsmit',),
|
||||||
9: ('deviņpadsmit',),
|
9: ('deviņpadsmit',),
|
||||||
}
|
}
|
||||||
|
|
||||||
TWENTIES = {
|
TWENTIES = {
|
||||||
2: ('divdesmit',),
|
2: ('divdesmit',),
|
||||||
3: ('trīsdesmit',),
|
3: ('trīsdesmit',),
|
||||||
4: ('četrdesmit',),
|
4: ('četrdesmit',),
|
||||||
5: ('piecdesmit',),
|
5: ('piecdesmit',),
|
||||||
6: ('sešdesmit',),
|
6: ('sešdesmit',),
|
||||||
7: ('septiņdesmit',),
|
7: ('septiņdesmit',),
|
||||||
8: ('astoņdesmit',),
|
8: ('astoņdesmit',),
|
||||||
9: ('deviņdesmit',),
|
9: ('deviņdesmit',),
|
||||||
}
|
}
|
||||||
|
|
||||||
HUNDRED = ('simts', 'simti', 'simtu')
|
HUNDRED = ('simts', 'simti', 'simtu')
|
||||||
|
|
||||||
THOUSANDS = {
|
THOUSANDS = {
|
||||||
1: ('tūkstotis', 'tūkstoši', 'tūkstošu'),
|
1: ('tūkstotis', 'tūkstoši', 'tūkstošu'),
|
||||||
2: ('miljons', 'miljoni', 'miljonu'),
|
2: ('miljons', 'miljoni', 'miljonu'),
|
||||||
3: ('miljards', 'miljardi', 'miljardu'),
|
3: ('miljards', 'miljardi', 'miljardu'),
|
||||||
4: ('triljons', 'triljoni', 'triljonu'),
|
4: ('triljons', 'triljoni', 'triljonu'),
|
||||||
5: ('kvadriljons', 'kvadriljoni', 'kvadriljonu'),
|
5: ('kvadriljons', 'kvadriljoni', 'kvadriljonu'),
|
||||||
6: ('kvintiljons', 'kvintiljoni', 'kvintiljonu'),
|
6: ('kvintiljons', 'kvintiljoni', 'kvintiljonu'),
|
||||||
7: ('sikstiljons', 'sikstiljoni', 'sikstiljonu'),
|
7: ('sikstiljons', 'sikstiljoni', 'sikstiljonu'),
|
||||||
8: ('septiljons', 'septiljoni', 'septiljonu'),
|
8: ('septiljons', 'septiljoni', 'septiljonu'),
|
||||||
9: ('oktiljons', 'oktiljoni', 'oktiljonu'),
|
9: ('oktiljons', 'oktiljoni', 'oktiljonu'),
|
||||||
10: ('nontiljons', 'nontiljoni', 'nontiljonu'),
|
10: ('nontiljons', 'nontiljoni', 'nontiljonu'),
|
||||||
}
|
}
|
||||||
|
|
||||||
GENERIC_DOLLARS = ('dolārs', 'dolāri', 'dolāru')
|
GENERIC_DOLLARS = ('dolārs', 'dolāri', 'dolāru')
|
||||||
GENERIC_CENTS = ('cents', 'centi', 'centu')
|
GENERIC_CENTS = ('cents', 'centi', 'centu')
|
||||||
|
|
||||||
GENERIC_KRONA = ('krona', 'kronas', 'kronu')
|
GENERIC_KRONA = ('krona', 'kronas', 'kronu')
|
||||||
GENERIC_ERA = ('ēre', 'ēras', 'ēru')
|
GENERIC_ERA = ('ēre', 'ēras', 'ēru')
|
||||||
|
|
||||||
|
|
||||||
class Num2Word_LV(Num2Word_Base):
|
class Num2Word_LV(Num2Word_Base):
|
||||||
"""
|
"""
|
||||||
Sadly we have a legal form (used in legal and finance documents):
|
Sadly we have a legal form (used in legal and finance documents):
|
||||||
http://www.eiro.lv/files/upload/files/Eiro_rakstiba-1.pdf
|
http://www.eiro.lv/files/upload/files/Eiro_rakstiba-1.pdf
|
||||||
https://likumi.lv/doc.php?id=254741
|
https://likumi.lv/doc.php?id=254741
|
||||||
http://eur-lex.europa.eu/legal-content/LV/TXT/HTML/?uri=CELEX:31998R0974&from=LV
|
http://eur-lex.europa.eu/legal-content/LV/TXT/HTML/?uri=CELEX:31998R0974&from=LV
|
||||||
|
|
||||||
Source: http://publications.europa.eu/code/lv/lv-5000500.htm
|
Source: http://publications.europa.eu/code/lv/lv-5000500.htm
|
||||||
"""
|
"""
|
||||||
CURRENCY_FORMS = {
|
CURRENCY_FORMS = {
|
||||||
'AUD': (GENERIC_DOLLARS, GENERIC_CENTS),
|
'AUD': (GENERIC_DOLLARS, GENERIC_CENTS),
|
||||||
'CAD': (GENERIC_DOLLARS, GENERIC_CENTS),
|
'CAD': (GENERIC_DOLLARS, GENERIC_CENTS),
|
||||||
# repalced by EUR
|
# repalced by EUR
|
||||||
'EEK': (GENERIC_KRONA, GENERIC_CENTS),
|
'EEK': (GENERIC_KRONA, GENERIC_CENTS),
|
||||||
'EUR': (('eiro', 'eiro', 'eiro'), GENERIC_CENTS),
|
'EUR': (('eiro', 'eiro', 'eiro'), GENERIC_CENTS),
|
||||||
'EUR_LEGAL': (('euro', 'euro', 'euro'), GENERIC_CENTS),
|
'EUR_LEGAL': (('euro', 'euro', 'euro'), GENERIC_CENTS),
|
||||||
'GBP': (
|
'GBP': (
|
||||||
('sterliņu mārciņa', 'sterliņu mārciņas', 'sterliņu mārciņu'),
|
('sterliņu mārciņa', 'sterliņu mārciņas', 'sterliņu mārciņu'),
|
||||||
('penss', 'pensi', 'pensu')),
|
('penss', 'pensi', 'pensu')),
|
||||||
# replaced by EUR
|
# replaced by EUR
|
||||||
'LTL': (('lits', 'liti', 'litu'), GENERIC_CENTS),
|
'LTL': (('lits', 'liti', 'litu'), GENERIC_CENTS),
|
||||||
# replaced by EUR
|
# replaced by EUR
|
||||||
'LVL': (('lats', 'lati', 'latu'),
|
'LVL': (('lats', 'lati', 'latu'),
|
||||||
('santīms', 'santīmi', 'santīmu')),
|
('santīms', 'santīmi', 'santīmu')),
|
||||||
'USD': (GENERIC_DOLLARS, GENERIC_CENTS),
|
'USD': (GENERIC_DOLLARS, GENERIC_CENTS),
|
||||||
'RUB': (('rublis', 'rubļi', 'rubļu'),
|
'RUB': (('rublis', 'rubļi', 'rubļu'),
|
||||||
('kapeika', 'kapeikas', 'kapeiku')),
|
('kapeika', 'kapeikas', 'kapeiku')),
|
||||||
'SEK': (GENERIC_KRONA, GENERIC_ERA),
|
'SEK': (GENERIC_KRONA, GENERIC_ERA),
|
||||||
'NOK': (GENERIC_KRONA, GENERIC_ERA),
|
'NOK': (GENERIC_KRONA, GENERIC_ERA),
|
||||||
'PLN': (('zlots', 'zloti', 'zlotu'),
|
'PLN': (('zlots', 'zloti', 'zlotu'),
|
||||||
('grasis', 'graši', 'grašu')),
|
('grasis', 'graši', 'grašu')),
|
||||||
}
|
}
|
||||||
|
|
||||||
CURRENCY_ADJECTIVES = {
|
CURRENCY_ADJECTIVES = {
|
||||||
'AUD': 'Austrālijas',
|
'AUD': 'Austrālijas',
|
||||||
'CAD': 'Kanādas',
|
'CAD': 'Kanādas',
|
||||||
'EEK': 'Igaunijas',
|
'EEK': 'Igaunijas',
|
||||||
'USD': 'ASV',
|
'USD': 'ASV',
|
||||||
'RUB': 'Kreivijas',
|
'RUB': 'Kreivijas',
|
||||||
'SEK': 'Zviedrijas',
|
'SEK': 'Zviedrijas',
|
||||||
'NOK': 'Norvēģijas',
|
'NOK': 'Norvēģijas',
|
||||||
}
|
}
|
||||||
|
|
||||||
def setup(self):
|
def setup(self):
|
||||||
self.negword = "mīnus"
|
self.negword = "mīnus"
|
||||||
self.pointword = "komats"
|
self.pointword = "komats"
|
||||||
|
|
||||||
def to_cardinal(self, number):
|
def to_cardinal(self, number):
|
||||||
n = str(number).replace(',', '.')
|
n = str(number).replace(',', '.')
|
||||||
base_str, n = self.parse_minus(n)
|
base_str, n = self.parse_minus(n)
|
||||||
if '.' in n:
|
if '.' in n:
|
||||||
left, right = n.split('.')
|
left, right = n.split('.')
|
||||||
return '%s%s %s %s' % (
|
return '%s%s %s %s' % (
|
||||||
base_str,
|
base_str,
|
||||||
self._int2word(int(left)),
|
self._int2word(int(left)),
|
||||||
self.pointword,
|
self.pointword,
|
||||||
self._int2word(int(right))
|
self._int2word(int(right))
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
return "%s%s" % (base_str, self._int2word(int(n)))
|
return "%s%s" % (base_str, self._int2word(int(n)))
|
||||||
|
|
||||||
def pluralize(self, n, forms):
|
def pluralize(self, n, forms):
|
||||||
form = 0 if (n % 10 == 1 and n % 100 != 11) else 1 if n != 0 else 2
|
form = 0 if (n % 10 == 1 and n % 100 != 11) else 1 if n != 0 else 2
|
||||||
return forms[form]
|
return forms[form]
|
||||||
|
|
||||||
def to_ordinal(self, number):
|
def to_ordinal(self, number):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
def _int2word(self, n):
|
def _int2word(self, n):
|
||||||
if n == 0:
|
if n == 0:
|
||||||
return ZERO[0]
|
return ZERO[0]
|
||||||
|
|
||||||
words = []
|
words = []
|
||||||
chunks = list(splitbyx(str(n), 3))
|
chunks = list(splitbyx(str(n), 3))
|
||||||
i = len(chunks)
|
i = len(chunks)
|
||||||
for x in chunks:
|
for x in chunks:
|
||||||
i -= 1
|
i -= 1
|
||||||
|
|
||||||
if x == 0:
|
if x == 0:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
n1, n2, n3 = get_digits(x)
|
n1, n2, n3 = get_digits(x)
|
||||||
|
|
||||||
if n3 > 0:
|
if n3 > 0:
|
||||||
if n3 == 1 and n2 == 0 and n1 > 0:
|
if n3 == 1 and n2 == 0 and n1 > 0:
|
||||||
words.append(HUNDRED[2])
|
words.append(HUNDRED[2])
|
||||||
elif n3 > 1:
|
elif n3 > 1:
|
||||||
words.append(ONES[n3][0])
|
words.append(ONES[n3][0])
|
||||||
words.append(HUNDRED[1])
|
words.append(HUNDRED[1])
|
||||||
else:
|
else:
|
||||||
words.append(HUNDRED[0])
|
words.append(HUNDRED[0])
|
||||||
|
|
||||||
if n2 > 1:
|
if n2 > 1:
|
||||||
words.append(TWENTIES[n2][0])
|
words.append(TWENTIES[n2][0])
|
||||||
|
|
||||||
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):
|
||||||
words.append(ONES[n1][0])
|
words.append(ONES[n1][0])
|
||||||
|
|
||||||
if i > 0:
|
if i > 0:
|
||||||
words.append(self.pluralize(x, THOUSANDS[i]))
|
words.append(self.pluralize(x, THOUSANDS[i]))
|
||||||
|
|
||||||
return ' '.join(words)
|
return ' '.join(words)
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
|
|||||||
@@ -1,164 +1,165 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
# This library is free software; you can redistribute it and/or
|
# This library is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU Lesser General Public
|
# modify it under the terms of the GNU Lesser General Public
|
||||||
# License as published by the Free Software Foundation; either
|
# License as published by the Free Software Foundation; either
|
||||||
# version 2.1 of the License, or (at your option) any later version.
|
# version 2.1 of the License, or (at your option) any later version.
|
||||||
# This library is distributed in the hope that it will be useful,
|
# This library is distributed in the hope that it will be useful,
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
# Lesser General Public License for more details.
|
# Lesser General Public License for more details.
|
||||||
# You should have received a copy of the GNU Lesser General Public
|
# You should have received a copy of the GNU Lesser General Public
|
||||||
# License along with this library; if not, write to the Free Software
|
# License along with this library; if not, write to the Free Software
|
||||||
# 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
|
||||||
from .base import Num2Word_Base
|
|
||||||
from .utils import get_digits, splitbyx
|
from .base import Num2Word_Base
|
||||||
|
from .utils import get_digits, splitbyx
|
||||||
ZERO = ('zero',)
|
|
||||||
|
ZERO = ('zero',)
|
||||||
ONES = {
|
|
||||||
1: ('jeden',),
|
ONES = {
|
||||||
2: ('dwa',),
|
1: ('jeden',),
|
||||||
3: ('trzy',),
|
2: ('dwa',),
|
||||||
4: ('cztery',),
|
3: ('trzy',),
|
||||||
5: ('pięć',),
|
4: ('cztery',),
|
||||||
6: ('sześć',),
|
5: ('pięć',),
|
||||||
7: ('siedem',),
|
6: ('sześć',),
|
||||||
8: ('osiem',),
|
7: ('siedem',),
|
||||||
9: ('dziewięć',),
|
8: ('osiem',),
|
||||||
}
|
9: ('dziewięć',),
|
||||||
|
}
|
||||||
TENS = {
|
|
||||||
0: ('dziesięć',),
|
TENS = {
|
||||||
1: ('jedenaście',),
|
0: ('dziesięć',),
|
||||||
2: ('dwanaście',),
|
1: ('jedenaście',),
|
||||||
3: ('trzynaście',),
|
2: ('dwanaście',),
|
||||||
4: ('czternaście',),
|
3: ('trzynaście',),
|
||||||
5: ('piętnaście',),
|
4: ('czternaście',),
|
||||||
6: ('szesnaście',),
|
5: ('piętnaście',),
|
||||||
7: ('siedemnaście',),
|
6: ('szesnaście',),
|
||||||
8: ('osiemnaście',),
|
7: ('siedemnaście',),
|
||||||
9: ('dziewiętnaście',),
|
8: ('osiemnaście',),
|
||||||
}
|
9: ('dziewiętnaście',),
|
||||||
|
}
|
||||||
TWENTIES = {
|
|
||||||
2: ('dwadzieścia',),
|
TWENTIES = {
|
||||||
3: ('trzydzieści',),
|
2: ('dwadzieścia',),
|
||||||
4: ('czterdzieści',),
|
3: ('trzydzieści',),
|
||||||
5: ('pięćdziesiąt',),
|
4: ('czterdzieści',),
|
||||||
6: ('sześćdziesiąt',),
|
5: ('pięćdziesiąt',),
|
||||||
7: ('siedemdziesiąt',),
|
6: ('sześćdziesiąt',),
|
||||||
8: ('osiemdziesiąt',),
|
7: ('siedemdziesiąt',),
|
||||||
9: ('dziewięćdzisiąt',),
|
8: ('osiemdziesiąt',),
|
||||||
}
|
9: ('dziewięćdzisiąt',),
|
||||||
|
}
|
||||||
HUNDREDS = {
|
|
||||||
1: ('sto',),
|
HUNDREDS = {
|
||||||
2: ('dwieście',),
|
1: ('sto',),
|
||||||
3: ('trzysta',),
|
2: ('dwieście',),
|
||||||
4: ('czterysta',),
|
3: ('trzysta',),
|
||||||
5: ('pięćset',),
|
4: ('czterysta',),
|
||||||
6: ('sześćset',),
|
5: ('pięćset',),
|
||||||
7: ('siedemset',),
|
6: ('sześćset',),
|
||||||
8: ('osiemset',),
|
7: ('siedemset',),
|
||||||
9: ('dziewięćset',),
|
8: ('osiemset',),
|
||||||
}
|
9: ('dziewięćset',),
|
||||||
|
}
|
||||||
THOUSANDS = {
|
|
||||||
1: ('tysiąc', 'tysiące', 'tysięcy'), # 10^3
|
THOUSANDS = {
|
||||||
2: ('milion', 'miliony', 'milionów'), # 10^6
|
1: ('tysiąc', 'tysiące', 'tysięcy'), # 10^3
|
||||||
3: ('miliard', 'miliardy', 'miliardów'), # 10^9
|
2: ('milion', 'miliony', 'milionów'), # 10^6
|
||||||
4: ('bilion', 'biliony', 'bilionów'), # 10^12
|
3: ('miliard', 'miliardy', 'miliardów'), # 10^9
|
||||||
5: ('biliard', 'biliardy', 'biliardów'), # 10^15
|
4: ('bilion', 'biliony', 'bilionów'), # 10^12
|
||||||
6: ('trylion', 'tryliony', 'trylionów'), # 10^18
|
5: ('biliard', 'biliardy', 'biliardów'), # 10^15
|
||||||
7: ('tryliard', 'tryliardy', 'tryliardów'), # 10^21
|
6: ('trylion', 'tryliony', 'trylionów'), # 10^18
|
||||||
8: ('kwadrylion', 'kwadryliony', 'kwadrylionów'), # 10^24
|
7: ('tryliard', 'tryliardy', 'tryliardów'), # 10^21
|
||||||
9: ('kwadryliard', 'kwadryliardy', 'kwadryliardów'), # 10^27
|
8: ('kwadrylion', 'kwadryliony', 'kwadrylionów'), # 10^24
|
||||||
10: ('kwintylion', 'kwintyliony', 'kwintylionów'), # 10^30
|
9: ('kwadryliard', 'kwadryliardy', 'kwadryliardów'), # 10^27
|
||||||
11: ('kwintyliard', 'kwintyliardy', 'kwintyliardów'), # 10^33
|
10: ('kwintylion', 'kwintyliony', 'kwintylionów'), # 10^30
|
||||||
12: ('sekstylion', 'sekstyliony', 'sekstylionów'), # 10^36
|
11: ('kwintyliard', 'kwintyliardy', 'kwintyliardów'), # 10^33
|
||||||
13: ('sekstyliard', 'sekstyliardy', 'sekstyliardów'), # 10^39
|
12: ('sekstylion', 'sekstyliony', 'sekstylionów'), # 10^36
|
||||||
14: ('septylion', 'septyliony', 'septylionów'), # 10^42
|
13: ('sekstyliard', 'sekstyliardy', 'sekstyliardów'), # 10^39
|
||||||
15: ('septyliard', 'septyliardy', 'septyliardów'), # 10^45
|
14: ('septylion', 'septyliony', 'septylionów'), # 10^42
|
||||||
16: ('oktylion', 'oktyliony', 'oktylionów'), # 10^48
|
15: ('septyliard', 'septyliardy', 'septyliardów'), # 10^45
|
||||||
17: ('oktyliard', 'oktyliardy', 'oktyliardów'), # 10^51
|
16: ('oktylion', 'oktyliony', 'oktylionów'), # 10^48
|
||||||
18: ('nonylion', 'nonyliony', 'nonylionów'), # 10^54
|
17: ('oktyliard', 'oktyliardy', 'oktyliardów'), # 10^51
|
||||||
19: ('nonyliard', 'nonyliardy', 'nonyliardów'), # 10^57
|
18: ('nonylion', 'nonyliony', 'nonylionów'), # 10^54
|
||||||
20: ('decylion', 'decyliony', 'decylionów'), # 10^60
|
19: ('nonyliard', 'nonyliardy', 'nonyliardów'), # 10^57
|
||||||
21: ('decyliard', 'decyliardy', 'decyliardów'), # 10^63
|
20: ('decylion', 'decyliony', 'decylionów'), # 10^60
|
||||||
}
|
21: ('decyliard', 'decyliardy', 'decyliardów'), # 10^63
|
||||||
|
}
|
||||||
|
|
||||||
class Num2Word_PL(Num2Word_Base):
|
|
||||||
CURRENCY_FORMS = {
|
class Num2Word_PL(Num2Word_Base):
|
||||||
'PLN': (
|
CURRENCY_FORMS = {
|
||||||
('złoty', 'złote', 'złotych'), ('grosz', 'grosze', 'groszy')
|
'PLN': (
|
||||||
),
|
('złoty', 'złote', 'złotych'), ('grosz', 'grosze', 'groszy')
|
||||||
'EUR': (
|
),
|
||||||
('euro', 'euro', 'euro'), ('cent', 'centy', 'centów')
|
'EUR': (
|
||||||
),
|
('euro', 'euro', 'euro'), ('cent', 'centy', 'centów')
|
||||||
}
|
),
|
||||||
|
}
|
||||||
def setup(self):
|
|
||||||
self.negword = "minus"
|
def setup(self):
|
||||||
self.pointword = "przecinek"
|
self.negword = "minus"
|
||||||
|
self.pointword = "przecinek"
|
||||||
def to_cardinal(self, number):
|
|
||||||
n = str(number).replace(',', '.')
|
def to_cardinal(self, number):
|
||||||
if '.' in n:
|
n = str(number).replace(',', '.')
|
||||||
left, right = n.split('.')
|
if '.' in n:
|
||||||
return u'%s %s %s' % (
|
left, right = n.split('.')
|
||||||
self._int2word(int(left)),
|
return u'%s %s %s' % (
|
||||||
self.pointword,
|
self._int2word(int(left)),
|
||||||
self._int2word(int(right))
|
self.pointword,
|
||||||
)
|
self._int2word(int(right))
|
||||||
else:
|
)
|
||||||
return self._int2word(int(n))
|
else:
|
||||||
|
return self._int2word(int(n))
|
||||||
def pluralize(self, n, forms):
|
|
||||||
if n == 1:
|
def pluralize(self, n, forms):
|
||||||
form = 0
|
if n == 1:
|
||||||
elif 5 > n % 10 > 1 and (n % 100 < 10 or n % 100 > 20):
|
form = 0
|
||||||
form = 1
|
elif 5 > n % 10 > 1 and (n % 100 < 10 or n % 100 > 20):
|
||||||
else:
|
form = 1
|
||||||
form = 2
|
else:
|
||||||
return forms[form]
|
form = 2
|
||||||
|
return forms[form]
|
||||||
def to_ordinal(self, number):
|
|
||||||
raise NotImplementedError()
|
def to_ordinal(self, number):
|
||||||
|
raise NotImplementedError()
|
||||||
def _int2word(self, n):
|
|
||||||
if n == 0:
|
def _int2word(self, n):
|
||||||
return ZERO[0]
|
if n == 0:
|
||||||
|
return ZERO[0]
|
||||||
words = []
|
|
||||||
chunks = list(splitbyx(str(n), 3))
|
words = []
|
||||||
i = len(chunks)
|
chunks = list(splitbyx(str(n), 3))
|
||||||
for x in chunks:
|
i = len(chunks)
|
||||||
i -= 1
|
for x in chunks:
|
||||||
|
i -= 1
|
||||||
if x == 0:
|
|
||||||
continue
|
if x == 0:
|
||||||
|
continue
|
||||||
n1, n2, n3 = get_digits(x)
|
|
||||||
|
n1, n2, n3 = get_digits(x)
|
||||||
if n3 > 0:
|
|
||||||
words.append(HUNDREDS[n3][0])
|
if n3 > 0:
|
||||||
|
words.append(HUNDREDS[n3][0])
|
||||||
if n2 > 1:
|
|
||||||
words.append(TWENTIES[n2][0])
|
if n2 > 1:
|
||||||
|
words.append(TWENTIES[n2][0])
|
||||||
if n2 == 1:
|
|
||||||
words.append(TENS[n1][0])
|
if n2 == 1:
|
||||||
elif n1 > 0 and not (i > 0 and x == 1):
|
words.append(TENS[n1][0])
|
||||||
words.append(ONES[n1][0])
|
elif n1 > 0 and not (i > 0 and x == 1):
|
||||||
|
words.append(ONES[n1][0])
|
||||||
if i > 0:
|
|
||||||
words.append(self.pluralize(x, THOUSANDS[i]))
|
if i > 0:
|
||||||
|
words.append(self.pluralize(x, THOUSANDS[i]))
|
||||||
return ' '.join(words)
|
|
||||||
|
return ' '.join(words)
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
@@ -15,7 +14,6 @@
|
|||||||
# License along with this library; if not, write to the Free Software
|
# License along with this library; if not, write to the Free Software
|
||||||
# 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 division, unicode_literals
|
from __future__ import division, unicode_literals
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
|
|||||||
@@ -1,233 +1,234 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
# This library is free software; you can redistribute it and/or
|
# This library is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU Lesser General Public
|
# modify it under the terms of the GNU Lesser General Public
|
||||||
# License as published by the Free Software Foundation; either
|
# License as published by the Free Software Foundation; either
|
||||||
# version 2.1 of the License, or (at your option) any later version.
|
# version 2.1 of the License, or (at your option) any later version.
|
||||||
# This library is distributed in the hope that it will be useful,
|
# This library is distributed in the hope that it will be useful,
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
# Lesser General Public License for more details.
|
# Lesser General Public License for more details.
|
||||||
# You should have received a copy of the GNU Lesser General Public
|
# You should have received a copy of the GNU Lesser General Public
|
||||||
# License along with this library; if not, write to the Free Software
|
# License along with this library; if not, write to the Free Software
|
||||||
# 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
|
||||||
from .base import Num2Word_Base
|
|
||||||
from .utils import get_digits, splitbyx
|
from .base import Num2Word_Base
|
||||||
|
from .utils import get_digits, splitbyx
|
||||||
ZERO = ('ноль',)
|
|
||||||
|
ZERO = ('ноль',)
|
||||||
ONES_FEMININE = {
|
|
||||||
1: ('одна',),
|
ONES_FEMININE = {
|
||||||
2: ('две',),
|
1: ('одна',),
|
||||||
3: ('три',),
|
2: ('две',),
|
||||||
4: ('четыре',),
|
3: ('три',),
|
||||||
5: ('пять',),
|
4: ('четыре',),
|
||||||
6: ('шесть',),
|
5: ('пять',),
|
||||||
7: ('семь',),
|
6: ('шесть',),
|
||||||
8: ('восемь',),
|
7: ('семь',),
|
||||||
9: ('девять',),
|
8: ('восемь',),
|
||||||
}
|
9: ('девять',),
|
||||||
|
}
|
||||||
ONES = {
|
|
||||||
1: ('один',),
|
ONES = {
|
||||||
2: ('два',),
|
1: ('один',),
|
||||||
3: ('три',),
|
2: ('два',),
|
||||||
4: ('четыре',),
|
3: ('три',),
|
||||||
5: ('пять',),
|
4: ('четыре',),
|
||||||
6: ('шесть',),
|
5: ('пять',),
|
||||||
7: ('семь',),
|
6: ('шесть',),
|
||||||
8: ('восемь',),
|
7: ('семь',),
|
||||||
9: ('девять',),
|
8: ('восемь',),
|
||||||
}
|
9: ('девять',),
|
||||||
|
}
|
||||||
TENS = {
|
|
||||||
0: ('десять',),
|
TENS = {
|
||||||
1: ('одиннадцать',),
|
0: ('десять',),
|
||||||
2: ('двенадцать',),
|
1: ('одиннадцать',),
|
||||||
3: ('тринадцать',),
|
2: ('двенадцать',),
|
||||||
4: ('четырнадцать',),
|
3: ('тринадцать',),
|
||||||
5: ('пятнадцать',),
|
4: ('четырнадцать',),
|
||||||
6: ('шестнадцать',),
|
5: ('пятнадцать',),
|
||||||
7: ('семнадцать',),
|
6: ('шестнадцать',),
|
||||||
8: ('восемнадцать',),
|
7: ('семнадцать',),
|
||||||
9: ('девятнадцать',),
|
8: ('восемнадцать',),
|
||||||
}
|
9: ('девятнадцать',),
|
||||||
|
}
|
||||||
TWENTIES = {
|
|
||||||
2: ('двадцать',),
|
TWENTIES = {
|
||||||
3: ('тридцать',),
|
2: ('двадцать',),
|
||||||
4: ('сорок',),
|
3: ('тридцать',),
|
||||||
5: ('пятьдесят',),
|
4: ('сорок',),
|
||||||
6: ('шестьдесят',),
|
5: ('пятьдесят',),
|
||||||
7: ('семьдесят',),
|
6: ('шестьдесят',),
|
||||||
8: ('восемьдесят',),
|
7: ('семьдесят',),
|
||||||
9: ('девяносто',),
|
8: ('восемьдесят',),
|
||||||
}
|
9: ('девяносто',),
|
||||||
|
}
|
||||||
HUNDREDS = {
|
|
||||||
1: ('сто',),
|
HUNDREDS = {
|
||||||
2: ('двести',),
|
1: ('сто',),
|
||||||
3: ('триста',),
|
2: ('двести',),
|
||||||
4: ('четыреста',),
|
3: ('триста',),
|
||||||
5: ('пятьсот',),
|
4: ('четыреста',),
|
||||||
6: ('шестьсот',),
|
5: ('пятьсот',),
|
||||||
7: ('семьсот',),
|
6: ('шестьсот',),
|
||||||
8: ('восемьсот',),
|
7: ('семьсот',),
|
||||||
9: ('девятьсот',),
|
8: ('восемьсот',),
|
||||||
}
|
9: ('девятьсот',),
|
||||||
|
}
|
||||||
THOUSANDS = {
|
|
||||||
1: ('тысяча', 'тысячи', 'тысяч'), # 10^3
|
THOUSANDS = {
|
||||||
2: ('миллион', 'миллиона', 'миллионов'), # 10^6
|
1: ('тысяча', 'тысячи', 'тысяч'), # 10^3
|
||||||
3: ('миллиард', 'миллиарда', 'миллиардов'), # 10^9
|
2: ('миллион', 'миллиона', 'миллионов'), # 10^6
|
||||||
4: ('триллион', 'триллиона', 'триллионов'), # 10^12
|
3: ('миллиард', 'миллиарда', 'миллиардов'), # 10^9
|
||||||
5: ('квадриллион', 'квадриллиона', 'квадриллионов'), # 10^15
|
4: ('триллион', 'триллиона', 'триллионов'), # 10^12
|
||||||
6: ('квинтиллион', 'квинтиллиона', 'квинтиллионов'), # 10^18
|
5: ('квадриллион', 'квадриллиона', 'квадриллионов'), # 10^15
|
||||||
7: ('секстиллион', 'секстиллиона', 'секстиллионов'), # 10^21
|
6: ('квинтиллион', 'квинтиллиона', 'квинтиллионов'), # 10^18
|
||||||
8: ('септиллион', 'септиллиона', 'септиллионов'), # 10^24
|
7: ('секстиллион', 'секстиллиона', 'секстиллионов'), # 10^21
|
||||||
9: ('октиллион', 'октиллиона', 'октиллионов'), # 10^27
|
8: ('септиллион', 'септиллиона', 'септиллионов'), # 10^24
|
||||||
10: ('нониллион', 'нониллиона', 'нониллионов'), # 10^30
|
9: ('октиллион', 'октиллиона', 'октиллионов'), # 10^27
|
||||||
}
|
10: ('нониллион', 'нониллиона', 'нониллионов'), # 10^30
|
||||||
|
}
|
||||||
|
|
||||||
class Num2Word_RU(Num2Word_Base):
|
|
||||||
CURRENCY_FORMS = {
|
class Num2Word_RU(Num2Word_Base):
|
||||||
'RUB': (
|
CURRENCY_FORMS = {
|
||||||
('рубль', 'рубля', 'рублей'), ('копейка', 'копейки', 'копеек')
|
'RUB': (
|
||||||
),
|
('рубль', 'рубля', 'рублей'), ('копейка', 'копейки', 'копеек')
|
||||||
'EUR': (
|
),
|
||||||
('евро', 'евро', 'евро'), ('цент', 'цента', 'центов')
|
'EUR': (
|
||||||
),
|
('евро', 'евро', 'евро'), ('цент', 'цента', 'центов')
|
||||||
'USD': (
|
),
|
||||||
('доллар', 'доллара', 'долларов'), ('цент', 'цента', 'центов')
|
'USD': (
|
||||||
),
|
('доллар', 'доллара', 'долларов'), ('цент', 'цента', 'центов')
|
||||||
}
|
),
|
||||||
|
}
|
||||||
def setup(self):
|
|
||||||
self.negword = "минус"
|
def setup(self):
|
||||||
self.pointword = "запятая"
|
self.negword = "минус"
|
||||||
self.ords = {"ноль": "нулевой",
|
self.pointword = "запятая"
|
||||||
"один": "первый",
|
self.ords = {"ноль": "нулевой",
|
||||||
"два": "второй",
|
"один": "первый",
|
||||||
"три": "третий",
|
"два": "второй",
|
||||||
"четыре": "четвертый",
|
"три": "третий",
|
||||||
"пять": "пятый",
|
"четыре": "четвертый",
|
||||||
"шесть": "шестой",
|
"пять": "пятый",
|
||||||
"семь": "седьмой",
|
"шесть": "шестой",
|
||||||
"восемь": "восьмой",
|
"семь": "седьмой",
|
||||||
"девять": "девятый",
|
"восемь": "восьмой",
|
||||||
"сто": "сотый"}
|
"девять": "девятый",
|
||||||
self.ords_feminine = {"один": "",
|
"сто": "сотый"}
|
||||||
"одна": "",
|
self.ords_feminine = {"один": "",
|
||||||
"две": "двух",
|
"одна": "",
|
||||||
"три": "трёх",
|
"две": "двух",
|
||||||
"четыре": "четырёх",
|
"три": "трёх",
|
||||||
"пять": "пяти",
|
"четыре": "четырёх",
|
||||||
"шесть": "шести",
|
"пять": "пяти",
|
||||||
"семь": "семи",
|
"шесть": "шести",
|
||||||
"восемь": "восьми",
|
"семь": "семи",
|
||||||
"девять": "девяти"}
|
"восемь": "восьми",
|
||||||
|
"девять": "девяти"}
|
||||||
def to_cardinal(self, number):
|
|
||||||
n = str(number).replace(',', '.')
|
def to_cardinal(self, number):
|
||||||
if '.' in n:
|
n = str(number).replace(',', '.')
|
||||||
left, right = n.split('.')
|
if '.' in n:
|
||||||
return u'%s %s %s' % (
|
left, right = n.split('.')
|
||||||
self._int2word(int(left)),
|
return u'%s %s %s' % (
|
||||||
self.pointword,
|
self._int2word(int(left)),
|
||||||
self._int2word(int(right))
|
self.pointword,
|
||||||
)
|
self._int2word(int(right))
|
||||||
else:
|
)
|
||||||
return self._int2word(int(n))
|
else:
|
||||||
|
return self._int2word(int(n))
|
||||||
def pluralize(self, n, forms):
|
|
||||||
if n % 100 < 10 or n % 100 > 20:
|
def pluralize(self, n, forms):
|
||||||
if n % 10 == 1:
|
if n % 100 < 10 or n % 100 > 20:
|
||||||
form = 0
|
if n % 10 == 1:
|
||||||
elif 5 > n % 10 > 1:
|
form = 0
|
||||||
form = 1
|
elif 5 > n % 10 > 1:
|
||||||
else:
|
form = 1
|
||||||
form = 2
|
else:
|
||||||
else:
|
form = 2
|
||||||
form = 2
|
else:
|
||||||
return forms[form]
|
form = 2
|
||||||
|
return forms[form]
|
||||||
def to_ordinal(self, number):
|
|
||||||
self.verify_ordinal(number)
|
def to_ordinal(self, number):
|
||||||
outwords = self.to_cardinal(number).split(" ")
|
self.verify_ordinal(number)
|
||||||
lastword = outwords[-1].lower()
|
outwords = self.to_cardinal(number).split(" ")
|
||||||
try:
|
lastword = outwords[-1].lower()
|
||||||
if len(outwords) > 1:
|
try:
|
||||||
if outwords[-2] in self.ords_feminine:
|
if len(outwords) > 1:
|
||||||
outwords[-2] = self.ords_feminine.get(
|
if outwords[-2] in self.ords_feminine:
|
||||||
outwords[-2], outwords[-2])
|
outwords[-2] = self.ords_feminine.get(
|
||||||
elif outwords[-2] == 'десять':
|
outwords[-2], outwords[-2])
|
||||||
outwords[-2] = outwords[-2][:-1] + 'и'
|
elif outwords[-2] == 'десять':
|
||||||
if len(outwords) == 3:
|
outwords[-2] = outwords[-2][:-1] + 'и'
|
||||||
if outwords[-3] in ['один', 'одна']:
|
if len(outwords) == 3:
|
||||||
outwords[-3] = ''
|
if outwords[-3] in ['один', 'одна']:
|
||||||
lastword = self.ords[lastword]
|
outwords[-3] = ''
|
||||||
except KeyError:
|
lastword = self.ords[lastword]
|
||||||
if lastword[:-3] in self.ords_feminine:
|
except KeyError:
|
||||||
lastword = self.ords_feminine.get(
|
if lastword[:-3] in self.ords_feminine:
|
||||||
lastword[:-3], lastword) + "сотый"
|
lastword = self.ords_feminine.get(
|
||||||
elif lastword[-1] == "ь" or lastword[-2] == "т":
|
lastword[:-3], lastword) + "сотый"
|
||||||
lastword = lastword[:-1] + "ый"
|
elif lastword[-1] == "ь" or lastword[-2] == "т":
|
||||||
elif lastword[-1] == "к":
|
lastword = lastword[:-1] + "ый"
|
||||||
lastword = lastword + "овой"
|
elif lastword[-1] == "к":
|
||||||
elif lastword[-5:] == "десят":
|
lastword = lastword + "овой"
|
||||||
lastword = lastword.replace('ь', 'и') + 'ый'
|
elif lastword[-5:] == "десят":
|
||||||
elif lastword[-2] == "ч" or lastword[-1] == "ч":
|
lastword = lastword.replace('ь', 'и') + 'ый'
|
||||||
if lastword[-2] == "ч":
|
elif lastword[-2] == "ч" or lastword[-1] == "ч":
|
||||||
lastword = lastword[:-1] + "ный"
|
if lastword[-2] == "ч":
|
||||||
if lastword[-1] == "ч":
|
lastword = lastword[:-1] + "ный"
|
||||||
lastword = lastword + "ный"
|
if lastword[-1] == "ч":
|
||||||
elif lastword[-1] == "н" or lastword[-2] == "н":
|
lastword = lastword + "ный"
|
||||||
lastword = lastword[:lastword.rfind('н') + 1] + "ный"
|
elif lastword[-1] == "н" or lastword[-2] == "н":
|
||||||
elif lastword[-1] == "д" or lastword[-2] == "д":
|
lastword = lastword[:lastword.rfind('н') + 1] + "ный"
|
||||||
lastword = lastword[:lastword.rfind('д') + 1] + "ный"
|
elif lastword[-1] == "д" or lastword[-2] == "д":
|
||||||
outwords[-1] = self.title(lastword)
|
lastword = lastword[:lastword.rfind('д') + 1] + "ный"
|
||||||
return " ".join(outwords).strip()
|
outwords[-1] = self.title(lastword)
|
||||||
|
return " ".join(outwords).strip()
|
||||||
def _cents_verbose(self, number, currency):
|
|
||||||
return self._int2word(number, currency == 'RUB')
|
def _cents_verbose(self, number, currency):
|
||||||
|
return self._int2word(number, currency == 'RUB')
|
||||||
def _int2word(self, n, feminine=False):
|
|
||||||
if n < 0:
|
def _int2word(self, n, feminine=False):
|
||||||
return ' '.join([self.negword, self._int2word(abs(n))])
|
if n < 0:
|
||||||
|
return ' '.join([self.negword, self._int2word(abs(n))])
|
||||||
if n == 0:
|
|
||||||
return ZERO[0]
|
if n == 0:
|
||||||
|
return ZERO[0]
|
||||||
words = []
|
|
||||||
chunks = list(splitbyx(str(n), 3))
|
words = []
|
||||||
i = len(chunks)
|
chunks = list(splitbyx(str(n), 3))
|
||||||
for x in chunks:
|
i = len(chunks)
|
||||||
i -= 1
|
for x in chunks:
|
||||||
|
i -= 1
|
||||||
if x == 0:
|
|
||||||
continue
|
if x == 0:
|
||||||
|
continue
|
||||||
n1, n2, n3 = get_digits(x)
|
|
||||||
|
n1, n2, n3 = get_digits(x)
|
||||||
if n3 > 0:
|
|
||||||
words.append(HUNDREDS[n3][0])
|
if n3 > 0:
|
||||||
|
words.append(HUNDREDS[n3][0])
|
||||||
if n2 > 1:
|
|
||||||
words.append(TWENTIES[n2][0])
|
if n2 > 1:
|
||||||
|
words.append(TWENTIES[n2][0])
|
||||||
if n2 == 1:
|
|
||||||
words.append(TENS[n1][0])
|
if n2 == 1:
|
||||||
elif n1 > 0:
|
words.append(TENS[n1][0])
|
||||||
ones = ONES_FEMININE if i == 1 or feminine and i == 0 else ONES
|
elif n1 > 0:
|
||||||
words.append(ones[n1][0])
|
ones = ONES_FEMININE if i == 1 or feminine and i == 0 else ONES
|
||||||
|
words.append(ones[n1][0])
|
||||||
if i > 0:
|
|
||||||
words.append(self.pluralize(x, THOUSANDS[i]))
|
if i > 0:
|
||||||
|
words.append(self.pluralize(x, THOUSANDS[i]))
|
||||||
return ' '.join(words)
|
|
||||||
|
return ' '.join(words)
|
||||||
|
|||||||
@@ -16,8 +16,6 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
# MA 02110-1301 USA
|
# MA 02110-1301 USA
|
||||||
|
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from .lang_EU import Num2Word_EU
|
from .lang_EU import Num2Word_EU
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
@@ -14,6 +14,7 @@
|
|||||||
# License along with this library; if not, write to the Free Software
|
# License along with this library; if not, write to the Free Software
|
||||||
# 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
|
||||||
|
|
||||||
from .base import Num2Word_Base
|
from .base import Num2Word_Base
|
||||||
|
|||||||
@@ -1,184 +1,183 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
|
||||||
|
# This library is free software; you can redistribute it and/or
|
||||||
# This library is free software; you can redistribute it and/or
|
# modify it under the terms of the GNU Lesser General Public
|
||||||
# modify it under the terms of the GNU Lesser General Public
|
# License as published by the Free Software Foundation; either
|
||||||
# License as published by the Free Software Foundation; either
|
# version 2.1 of the License, or (at your option) any later version.
|
||||||
# version 2.1 of the License, or (at your option) any later version.
|
# This library is distributed in the hope that it will be useful,
|
||||||
# This library is distributed in the hope that it will be useful,
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
# Lesser General Public License for more details.
|
||||||
# Lesser General Public License for more details.
|
# You should have received a copy of the GNU Lesser General Public
|
||||||
# You should have received a copy of the GNU Lesser General Public
|
# License along with this library; if not, write to the Free Software
|
||||||
# License along with this library; if not, write to the Free Software
|
# 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
|
|
||||||
|
from num2words.base import Num2Word_Base
|
||||||
from num2words.base import Num2Word_Base
|
from num2words.currency import parse_currency_parts
|
||||||
from num2words.currency import parse_currency_parts
|
from num2words.utils import splitbyx
|
||||||
from num2words.utils import splitbyx
|
|
||||||
|
|
||||||
|
class Num2Word_TH(Num2Word_Base):
|
||||||
class Num2Word_TH(Num2Word_Base):
|
|
||||||
|
def setup(self):
|
||||||
def setup(self):
|
self.negword = 'ติดลบ'
|
||||||
self.negword = 'ติดลบ'
|
self.pointword = 'จุด'
|
||||||
self.pointword = 'จุด'
|
|
||||||
|
self.CURRENCY_FORMS = {
|
||||||
self.CURRENCY_FORMS = {
|
'THB': (('บาท', 'บาท'), ('สตางค์', 'สตางค์')),
|
||||||
'THB': (('บาท', 'บาท'), ('สตางค์', 'สตางค์')),
|
'USD': (('ดอลลาร์', 'ดอลลาร์'), ('เซนต์', 'เซนต์')),
|
||||||
'USD': (('ดอลลาร์', 'ดอลลาร์'), ('เซนต์', 'เซนต์')),
|
'EUR': (('ยูโร', 'ยูโร'), ('เซนต์', 'เซนต์')),
|
||||||
'EUR': (('ยูโร', 'ยูโร'), ('เซนต์', 'เซนต์')),
|
}
|
||||||
}
|
|
||||||
|
self.high_numwords = []
|
||||||
self.high_numwords = []
|
|
||||||
|
self.mid_numwords = ['', 'สิบ', 'ร้อย', 'พัน', 'หมื่น', 'แสน', 'ล้าน']
|
||||||
self.mid_numwords = ['', 'สิบ', 'ร้อย', 'พัน', 'หมื่น', 'แสน', 'ล้าน']
|
|
||||||
|
self.low_numwords = [
|
||||||
self.low_numwords = [
|
'ศูนย์', 'หนึ่ง', 'สอง', 'สาม', 'สี่',
|
||||||
'ศูนย์', 'หนึ่ง', 'สอง', 'สาม', 'สี่',
|
'ห้า', 'หก', 'เจ็ด', 'แปด', 'เก้า'
|
||||||
'ห้า', 'หก', 'เจ็ด', 'แปด', 'เก้า'
|
]
|
||||||
]
|
|
||||||
|
def set_high_numwords(self, high_numwords):
|
||||||
def set_high_numwords(self, high_numwords):
|
pass
|
||||||
pass
|
|
||||||
|
def set_mid_numwords(self, mid_numwords):
|
||||||
def set_mid_numwords(self, mid_numwords):
|
pass
|
||||||
pass
|
|
||||||
|
def splitnum(self, six_num):
|
||||||
def splitnum(self, six_num):
|
length = len(six_num) > 1
|
||||||
length = len(six_num) > 1
|
word_num = ''
|
||||||
word_num = ''
|
|
||||||
|
for index, num in enumerate(map(int, six_num)):
|
||||||
for index, num in enumerate(map(int, six_num)):
|
if num:
|
||||||
if num:
|
if index:
|
||||||
if index:
|
word_num = self.mid_numwords[index] + word_num
|
||||||
word_num = self.mid_numwords[index] + word_num
|
|
||||||
|
if length and num == 1 and index == 0:
|
||||||
if length and num == 1 and index == 0:
|
word_num += 'เอ็ด'
|
||||||
word_num += 'เอ็ด'
|
elif index == 1 and num == 2:
|
||||||
elif index == 1 and num == 2:
|
word_num = 'ยี่' + word_num
|
||||||
word_num = 'ยี่' + word_num
|
elif index != 1 or num != 1:
|
||||||
elif index != 1 or num != 1:
|
word_num = self.low_numwords[num] + word_num
|
||||||
word_num = self.low_numwords[num] + word_num
|
|
||||||
|
elif num == 0 and index == 0 and length == 0:
|
||||||
elif num == 0 and index == 0 and length == 0:
|
word_num = self.low_numwords[0]
|
||||||
word_num = self.low_numwords[0]
|
|
||||||
|
return word_num
|
||||||
return word_num
|
|
||||||
|
def split_six(self, num_txt):
|
||||||
def split_six(self, num_txt):
|
result = splitbyx(num_txt, 6, format_int=False)
|
||||||
result = splitbyx(num_txt, 6, format_int=False)
|
result = list(result)[::-1]
|
||||||
result = list(result)[::-1]
|
number_list = []
|
||||||
number_list = []
|
for i in result:
|
||||||
for i in result:
|
number_list.append(i[::-1])
|
||||||
number_list.append(i[::-1])
|
return number_list
|
||||||
return number_list
|
|
||||||
|
def add_text_million(self, word_num):
|
||||||
def add_text_million(self, word_num):
|
result = ''
|
||||||
result = ''
|
|
||||||
|
for index, t in enumerate(reversed(word_num)):
|
||||||
for index, t in enumerate(reversed(word_num)):
|
if index == 0:
|
||||||
if index == 0:
|
result = t
|
||||||
result = t
|
else:
|
||||||
else:
|
result = result + 'ล้าน' + t
|
||||||
result = result + 'ล้าน' + t
|
|
||||||
|
return result
|
||||||
return result
|
|
||||||
|
def round_2_decimal(self, number):
|
||||||
def round_2_decimal(self, number):
|
integer, cents, negative = parse_currency_parts(
|
||||||
integer, cents, negative = parse_currency_parts(
|
number, is_int_with_cents=False
|
||||||
number, is_int_with_cents=False
|
)
|
||||||
)
|
integer = '{}'.format(integer)
|
||||||
integer = '{}'.format(integer)
|
cents = '{}'.format(cents)
|
||||||
cents = '{}'.format(cents)
|
|
||||||
|
if len(cents) < 2:
|
||||||
if len(cents) < 2:
|
add_zero = 2 - len(cents)
|
||||||
add_zero = 2 - len(cents)
|
cents = ('0' * add_zero) + cents
|
||||||
cents = ('0' * add_zero) + cents
|
|
||||||
|
text_num = integer + '.' + cents
|
||||||
text_num = integer + '.' + cents
|
|
||||||
|
return text_num, negative
|
||||||
return text_num, negative
|
|
||||||
|
def left_num_to_text(self, number):
|
||||||
def left_num_to_text(self, number):
|
|
||||||
|
left_num_list = self.split_six(number)
|
||||||
left_num_list = self.split_six(number)
|
|
||||||
|
left_text_list = []
|
||||||
left_text_list = []
|
for i in left_num_list:
|
||||||
for i in left_num_list:
|
left_text_list.append(self.splitnum(i))
|
||||||
left_text_list.append(self.splitnum(i))
|
|
||||||
|
left_text = self.add_text_million(left_text_list)
|
||||||
left_text = self.add_text_million(left_text_list)
|
return left_text
|
||||||
return left_text
|
|
||||||
|
def to_cardinal(self, number):
|
||||||
def to_cardinal(self, number):
|
negative = number < 0
|
||||||
negative = number < 0
|
|
||||||
|
pre, post = self.float2tuple(number)
|
||||||
pre, post = self.float2tuple(number)
|
precision = self.precision
|
||||||
precision = self.precision
|
pre = '{}'.format(pre)
|
||||||
pre = '{}'.format(pre)
|
post = '{}'.format(post)
|
||||||
post = '{}'.format(post)
|
|
||||||
|
if negative:
|
||||||
if negative:
|
pre = pre.lstrip('-')
|
||||||
pre = pre.lstrip('-')
|
|
||||||
|
if len(post) < precision:
|
||||||
if len(post) < precision:
|
add_zero = precision - len(post)
|
||||||
add_zero = precision - len(post)
|
post = ('0' * add_zero) + post
|
||||||
post = ('0' * add_zero) + post
|
|
||||||
|
result = self.left_num_to_text(pre)
|
||||||
result = self.left_num_to_text(pre)
|
|
||||||
|
right_text = ''
|
||||||
right_text = ''
|
if not post == '0':
|
||||||
if not post == '0':
|
for i in map(int, post):
|
||||||
for i in map(int, post):
|
right_text = right_text + self.low_numwords[i]
|
||||||
right_text = right_text + self.low_numwords[i]
|
result = result + 'จุด' + right_text
|
||||||
result = result + 'จุด' + right_text
|
|
||||||
|
if negative:
|
||||||
if negative:
|
result = 'ติดลบ' + result
|
||||||
result = 'ติดลบ' + result
|
|
||||||
|
return result
|
||||||
return result
|
|
||||||
|
def to_ordinal(self, number):
|
||||||
def to_ordinal(self, number):
|
return self.to_cardinal(number)
|
||||||
return self.to_cardinal(number)
|
|
||||||
|
def to_currency(self, number, currency='THB'):
|
||||||
def to_currency(self, number, currency='THB'):
|
|
||||||
|
number, negative = self.round_2_decimal(number)
|
||||||
number, negative = self.round_2_decimal(number)
|
|
||||||
|
split_num = number.split('.')
|
||||||
split_num = number.split('.')
|
|
||||||
|
left_num = split_num[0]
|
||||||
left_num = split_num[0]
|
left_text = self.left_num_to_text(left_num)
|
||||||
left_text = self.left_num_to_text(left_num)
|
|
||||||
|
right_num = split_num[1]
|
||||||
right_num = split_num[1]
|
right_text = self.splitnum(right_num[::-1].rstrip('0'))
|
||||||
right_text = self.splitnum(right_num[::-1].rstrip('0'))
|
|
||||||
|
try:
|
||||||
try:
|
cr1, cr2 = self.CURRENCY_FORMS[currency]
|
||||||
cr1, cr2 = self.CURRENCY_FORMS[currency]
|
|
||||||
|
except KeyError:
|
||||||
except KeyError:
|
raise NotImplementedError(
|
||||||
raise NotImplementedError(
|
'Currency code "%s" not implemented for "%s"' %
|
||||||
'Currency code "%s" not implemented for "%s"' %
|
(currency, self.__class__.__name__))
|
||||||
(currency, self.__class__.__name__))
|
|
||||||
|
if right_num == '00':
|
||||||
if right_num == '00':
|
if currency == 'THB':
|
||||||
if currency == 'THB':
|
result = left_text + cr1[0] + 'ถ้วน'
|
||||||
result = left_text + cr1[0] + 'ถ้วน'
|
else:
|
||||||
else:
|
result = left_text + cr1[0]
|
||||||
result = left_text + cr1[0]
|
else:
|
||||||
else:
|
if left_num == '0':
|
||||||
if left_num == '0':
|
result = right_text + cr2[0]
|
||||||
result = right_text + cr2[0]
|
else:
|
||||||
else:
|
result = left_text + cr1[0] + right_text + cr2[0]
|
||||||
result = left_text + cr1[0] + right_text + cr2[0]
|
|
||||||
|
if negative:
|
||||||
if negative:
|
result = self.negword + result
|
||||||
result = self.negword + result
|
|
||||||
|
return result
|
||||||
return result
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
# Copyright (c) 2017, Tufan Kaynak, Framras. All Rights Reserved.
|
# Copyright (c) 2017, Tufan Kaynak, Framras. All Rights Reserved.
|
||||||
|
|||||||
@@ -1,178 +1,179 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
# This library is free software; you can redistribute it and/or
|
# This library is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU Lesser General Public
|
# modify it under the terms of the GNU Lesser General Public
|
||||||
# License as published by the Free Software Foundation; either
|
# License as published by the Free Software Foundation; either
|
||||||
# version 2.1 of the License, or (at your option) any later version.
|
# version 2.1 of the License, or (at your option) any later version.
|
||||||
# This library is distributed in the hope that it will be useful,
|
# This library is distributed in the hope that it will be useful,
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
# Lesser General Public License for more details.
|
# Lesser General Public License for more details.
|
||||||
# You should have received a copy of the GNU Lesser General Public
|
# You should have received a copy of the GNU Lesser General Public
|
||||||
# License along with this library; if not, write to the Free Software
|
# License along with this library; if not, write to the Free Software
|
||||||
# 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
|
||||||
from .base import Num2Word_Base
|
|
||||||
from .utils import get_digits, splitbyx
|
from .base import Num2Word_Base
|
||||||
|
from .utils import get_digits, splitbyx
|
||||||
ZERO = ('нуль',)
|
|
||||||
|
ZERO = ('нуль',)
|
||||||
ONES_FEMININE = {
|
|
||||||
1: ('одна',),
|
ONES_FEMININE = {
|
||||||
2: ('двi',),
|
1: ('одна',),
|
||||||
3: ('три',),
|
2: ('двi',),
|
||||||
4: ('чотири',),
|
3: ('три',),
|
||||||
5: ('п\'ять',),
|
4: ('чотири',),
|
||||||
6: ('шiсть',),
|
5: ('п\'ять',),
|
||||||
7: ('сiм',),
|
6: ('шiсть',),
|
||||||
8: ('вiсiм',),
|
7: ('сiм',),
|
||||||
9: ('дев\'ять',),
|
8: ('вiсiм',),
|
||||||
}
|
9: ('дев\'ять',),
|
||||||
|
}
|
||||||
ONES = {
|
|
||||||
1: ('один',),
|
ONES = {
|
||||||
2: ('два',),
|
1: ('один',),
|
||||||
3: ('три',),
|
2: ('два',),
|
||||||
4: ('чотири',),
|
3: ('три',),
|
||||||
5: ('п\'ять',),
|
4: ('чотири',),
|
||||||
6: ('шiсть',),
|
5: ('п\'ять',),
|
||||||
7: ('сiм',),
|
6: ('шiсть',),
|
||||||
8: ('вiсiм',),
|
7: ('сiм',),
|
||||||
9: ('дев\'ять',),
|
8: ('вiсiм',),
|
||||||
}
|
9: ('дев\'ять',),
|
||||||
|
}
|
||||||
TENS = {
|
|
||||||
0: ('десять',),
|
TENS = {
|
||||||
1: ('одинадцять',),
|
0: ('десять',),
|
||||||
2: ('дванадцять',),
|
1: ('одинадцять',),
|
||||||
3: ('тринадцять',),
|
2: ('дванадцять',),
|
||||||
4: ('чотирнадцять',),
|
3: ('тринадцять',),
|
||||||
5: ('п\'ятнадцять',),
|
4: ('чотирнадцять',),
|
||||||
6: ('шiстнадцять',),
|
5: ('п\'ятнадцять',),
|
||||||
7: ('сiмнадцять',),
|
6: ('шiстнадцять',),
|
||||||
8: ('вiсiмнадцять',),
|
7: ('сiмнадцять',),
|
||||||
9: ('дев\'ятнадцять',),
|
8: ('вiсiмнадцять',),
|
||||||
}
|
9: ('дев\'ятнадцять',),
|
||||||
|
}
|
||||||
TWENTIES = {
|
|
||||||
2: ('двадцять',),
|
TWENTIES = {
|
||||||
3: ('тридцять',),
|
2: ('двадцять',),
|
||||||
4: ('сорок',),
|
3: ('тридцять',),
|
||||||
5: ('п\'ятдесят',),
|
4: ('сорок',),
|
||||||
6: ('шiстдесят',),
|
5: ('п\'ятдесят',),
|
||||||
7: ('сiмдесят',),
|
6: ('шiстдесят',),
|
||||||
8: ('вiсiмдесят',),
|
7: ('сiмдесят',),
|
||||||
9: ('дев\'яносто',),
|
8: ('вiсiмдесят',),
|
||||||
}
|
9: ('дев\'яносто',),
|
||||||
|
}
|
||||||
HUNDREDS = {
|
|
||||||
1: ('сто',),
|
HUNDREDS = {
|
||||||
2: ('двiстi',),
|
1: ('сто',),
|
||||||
3: ('триста',),
|
2: ('двiстi',),
|
||||||
4: ('чотириста',),
|
3: ('триста',),
|
||||||
5: ('п\'ятсот',),
|
4: ('чотириста',),
|
||||||
6: ('шiстсот',),
|
5: ('п\'ятсот',),
|
||||||
7: ('сiмсот',),
|
6: ('шiстсот',),
|
||||||
8: ('вiсiмсот',),
|
7: ('сiмсот',),
|
||||||
9: ('дев\'ятсот',),
|
8: ('вiсiмсот',),
|
||||||
}
|
9: ('дев\'ятсот',),
|
||||||
|
}
|
||||||
THOUSANDS = {
|
|
||||||
1: ('тисяча', 'тисячi', 'тисяч'), # 10^3
|
THOUSANDS = {
|
||||||
2: ('мiльйон', 'мiльйони', 'мiльйонiв'), # 10^6
|
1: ('тисяча', 'тисячi', 'тисяч'), # 10^3
|
||||||
3: ('мiльярд', 'мiльярди', 'мiльярдiв'), # 10^9
|
2: ('мiльйон', 'мiльйони', 'мiльйонiв'), # 10^6
|
||||||
4: ('трильйон', 'трильйони', 'трильйонiв'), # 10^12
|
3: ('мiльярд', 'мiльярди', 'мiльярдiв'), # 10^9
|
||||||
5: ('квадрильйон', 'квадрильйони', 'квадрильйонiв'), # 10^15
|
4: ('трильйон', 'трильйони', 'трильйонiв'), # 10^12
|
||||||
6: ('квiнтильйон', 'квiнтильйони', 'квiнтильйонiв'), # 10^18
|
5: ('квадрильйон', 'квадрильйони', 'квадрильйонiв'), # 10^15
|
||||||
7: ('секстильйон', 'секстильйони', 'секстильйонiв'), # 10^21
|
6: ('квiнтильйон', 'квiнтильйони', 'квiнтильйонiв'), # 10^18
|
||||||
8: ('септильйон', 'септильйони', 'септильйонiв'), # 10^24
|
7: ('секстильйон', 'секстильйони', 'секстильйонiв'), # 10^21
|
||||||
9: ('октильйон', 'октильйони', 'октильйонiв'), # 10^27
|
8: ('септильйон', 'септильйони', 'септильйонiв'), # 10^24
|
||||||
10: ('нонiльйон', 'нонiльйони', 'нонiльйонiв'), # 10^30
|
9: ('октильйон', 'октильйони', 'октильйонiв'), # 10^27
|
||||||
}
|
10: ('нонiльйон', 'нонiльйони', 'нонiльйонiв'), # 10^30
|
||||||
|
}
|
||||||
|
|
||||||
class Num2Word_UK(Num2Word_Base):
|
|
||||||
CURRENCY_FORMS = {
|
class Num2Word_UK(Num2Word_Base):
|
||||||
'UAH': (
|
CURRENCY_FORMS = {
|
||||||
('гривня', 'гривнi', 'гривень'),
|
'UAH': (
|
||||||
('копiйка', 'копiйки', 'копiйок')
|
('гривня', 'гривнi', 'гривень'),
|
||||||
),
|
('копiйка', 'копiйки', 'копiйок')
|
||||||
'EUR': (
|
),
|
||||||
('євро', 'євро', 'євро'), ('цент', 'центи', 'центiв')
|
'EUR': (
|
||||||
),
|
('євро', 'євро', 'євро'), ('цент', 'центи', 'центiв')
|
||||||
}
|
),
|
||||||
|
}
|
||||||
def setup(self):
|
|
||||||
self.negword = "мiнус"
|
def setup(self):
|
||||||
self.pointword = "кома"
|
self.negword = "мiнус"
|
||||||
|
self.pointword = "кома"
|
||||||
def to_cardinal(self, number):
|
|
||||||
n = str(number).replace(',', '.')
|
def to_cardinal(self, number):
|
||||||
if '.' in n:
|
n = str(number).replace(',', '.')
|
||||||
left, right = n.split('.')
|
if '.' in n:
|
||||||
return '%s %s %s' % (
|
left, right = n.split('.')
|
||||||
self._int2word(int(left)),
|
return '%s %s %s' % (
|
||||||
self.pointword,
|
self._int2word(int(left)),
|
||||||
self._int2word(int(right))
|
self.pointword,
|
||||||
)
|
self._int2word(int(right))
|
||||||
else:
|
)
|
||||||
return self._int2word(int(n))
|
else:
|
||||||
|
return self._int2word(int(n))
|
||||||
def pluralize(self, n, forms):
|
|
||||||
if n % 100 < 10 or n % 100 > 20:
|
def pluralize(self, n, forms):
|
||||||
if n % 10 == 1:
|
if n % 100 < 10 or n % 100 > 20:
|
||||||
form = 0
|
if n % 10 == 1:
|
||||||
elif 5 > n % 10 > 1:
|
form = 0
|
||||||
form = 1
|
elif 5 > n % 10 > 1:
|
||||||
else:
|
form = 1
|
||||||
form = 2
|
else:
|
||||||
else:
|
form = 2
|
||||||
form = 2
|
else:
|
||||||
|
form = 2
|
||||||
return forms[form]
|
|
||||||
|
return forms[form]
|
||||||
def _int2word(self, n, feminine=True):
|
|
||||||
if n < 0:
|
def _int2word(self, n, feminine=True):
|
||||||
return ' '.join([self.negword, self._int2word(abs(n))])
|
if n < 0:
|
||||||
|
return ' '.join([self.negword, self._int2word(abs(n))])
|
||||||
if n == 0:
|
|
||||||
return ZERO[0]
|
if n == 0:
|
||||||
|
return ZERO[0]
|
||||||
words = []
|
|
||||||
chunks = list(splitbyx(str(n), 3))
|
words = []
|
||||||
i = len(chunks)
|
chunks = list(splitbyx(str(n), 3))
|
||||||
for x in chunks:
|
i = len(chunks)
|
||||||
i -= 1
|
for x in chunks:
|
||||||
|
i -= 1
|
||||||
if x == 0:
|
|
||||||
continue
|
if x == 0:
|
||||||
|
continue
|
||||||
n1, n2, n3 = get_digits(x)
|
|
||||||
|
n1, n2, n3 = get_digits(x)
|
||||||
if n3 > 0:
|
|
||||||
words.append(HUNDREDS[n3][0])
|
if n3 > 0:
|
||||||
|
words.append(HUNDREDS[n3][0])
|
||||||
if n2 > 1:
|
|
||||||
words.append(TWENTIES[n2][0])
|
if n2 > 1:
|
||||||
|
words.append(TWENTIES[n2][0])
|
||||||
if n2 == 1:
|
|
||||||
words.append(TENS[n1][0])
|
if n2 == 1:
|
||||||
# elif n1 > 0 and not (i > 0 and x == 1):
|
words.append(TENS[n1][0])
|
||||||
elif n1 > 0:
|
# elif n1 > 0 and not (i > 0 and x == 1):
|
||||||
ones = ONES_FEMININE if i == 1 or feminine and i == 0 else ONES
|
elif n1 > 0:
|
||||||
words.append(ones[n1][0])
|
ones = ONES_FEMININE if i == 1 or feminine and i == 0 else ONES
|
||||||
|
words.append(ones[n1][0])
|
||||||
if i > 0:
|
|
||||||
words.append(self.pluralize(x, THOUSANDS[i]))
|
if i > 0:
|
||||||
|
words.append(self.pluralize(x, THOUSANDS[i]))
|
||||||
return ' '.join(words)
|
|
||||||
|
return ' '.join(words)
|
||||||
def _cents_verbose(self, number, currency):
|
|
||||||
return self._int2word(number, currency == 'UAH')
|
def _cents_verbose(self, number, currency):
|
||||||
|
return self._int2word(number, currency == 'UAH')
|
||||||
def to_ordinal(self, number):
|
|
||||||
raise NotImplementedError()
|
def to_ordinal(self, number):
|
||||||
|
raise NotImplementedError()
|
||||||
|
|||||||
@@ -1,17 +1,35 @@
|
|||||||
def splitbyx(n, x, format_int=True):
|
# -*- coding: utf-8 -*-
|
||||||
length = len(n)
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
if length > x:
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
start = length % x
|
|
||||||
if start > 0:
|
# This library is free software; you can redistribute it and/or
|
||||||
result = n[:start]
|
# modify it under the terms of the GNU Lesser General Public
|
||||||
yield int(result) if format_int else result
|
# License as published by the Free Software Foundation; either
|
||||||
for i in range(start, length, x):
|
# version 2.1 of the License, or (at your option) any later version.
|
||||||
result = n[i:i+x]
|
# This library is distributed in the hope that it will be useful,
|
||||||
yield int(result) if format_int else result
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
else:
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
yield int(n) if format_int else n
|
# Lesser General Public License for more details.
|
||||||
|
# You should have received a copy of the GNU Lesser General Public
|
||||||
|
# License along with this library; if not, write to the Free Software
|
||||||
def get_digits(n):
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
a = [int(x) for x in reversed(list(('%03d' % n)[-3:]))]
|
# MA 02110-1301 USA
|
||||||
return a
|
|
||||||
|
|
||||||
|
def splitbyx(n, x, format_int=True):
|
||||||
|
length = len(n)
|
||||||
|
if length > x:
|
||||||
|
start = length % x
|
||||||
|
if start > 0:
|
||||||
|
result = n[:start]
|
||||||
|
yield int(result) if format_int else result
|
||||||
|
for i in range(start, length, x):
|
||||||
|
result = n[i:i+x]
|
||||||
|
yield int(result) if format_int else result
|
||||||
|
else:
|
||||||
|
yield int(n) if format_int else n
|
||||||
|
|
||||||
|
|
||||||
|
def get_digits(n):
|
||||||
|
a = [int(x) for x in reversed(list(('%03d' % n)[-3:]))]
|
||||||
|
return a
|
||||||
|
|||||||
24
setup.py
24
setup.py
@@ -1,4 +1,22 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
|
# This library is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU Lesser General Public
|
||||||
|
# License as published by the Free Software Foundation; either
|
||||||
|
# version 2.1 of the License, or (at your option) any later version.
|
||||||
|
# This library is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
# Lesser General Public License for more details.
|
||||||
|
# You should have received a copy of the GNU Lesser General Public
|
||||||
|
# License along with this library; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
# MA 02110-1301 USA
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
from io import open
|
||||||
|
|
||||||
from setuptools import find_packages, setup
|
from setuptools import find_packages, setup
|
||||||
|
|
||||||
@@ -17,8 +35,8 @@ CLASSIFIERS = [
|
|||||||
'Topic :: Text Processing :: Linguistic',
|
'Topic :: Text Processing :: Linguistic',
|
||||||
]
|
]
|
||||||
|
|
||||||
LONG_DESC = open('README.rst', 'rt').read() + '\n\n' + \
|
LONG_DESC = open('README.rst', 'rt', encoding="utf-8").read() + '\n\n' + \
|
||||||
open('CHANGES.rst', 'rt').read()
|
open('CHANGES.rst', 'rt', encoding="utf-8").read()
|
||||||
|
|
||||||
|
|
||||||
def find_version(fname):
|
def find_version(fname):
|
||||||
@@ -26,7 +44,7 @@ def find_version(fname):
|
|||||||
Returns str or raises RuntimeError
|
Returns str or raises RuntimeError
|
||||||
"""
|
"""
|
||||||
version = ''
|
version = ''
|
||||||
with open(fname, 'r') as fp:
|
with open(fname, 'r', encoding="utf-8") as fp:
|
||||||
reg = re.compile(r'__version__ = [\'"]([^\'"]*)[\'"]')
|
reg = re.compile(r'__version__ = [\'"]([^\'"]*)[\'"]')
|
||||||
for line in fp:
|
for line in fp:
|
||||||
m = reg.match(line)
|
m = reg.match(line)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
# This library is free software; you can redistribute it and/or
|
# This library is free software; you can redistribute it and/or
|
||||||
@@ -13,7 +14,6 @@
|
|||||||
# License along with this library; if not, write to the Free Software
|
# License along with this library; if not, write to the Free Software
|
||||||
# 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 unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,20 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
|
# This library is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU Lesser General Public
|
||||||
|
# License as published by the Free Software Foundation; either
|
||||||
|
# version 2.1 of the License, or (at your option) any later version.
|
||||||
|
# This library is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
# Lesser General Public License for more details.
|
||||||
|
# You should have received a copy of the GNU Lesser General Public
|
||||||
|
# License along with this library; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
# MA 02110-1301 USA
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
|||||||
@@ -1,5 +1,20 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
|
# This library is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU Lesser General Public
|
||||||
|
# License as published by the Free Software Foundation; either
|
||||||
|
# version 2.1 of the License, or (at your option) any later version.
|
||||||
|
# This library is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
# Lesser General Public License for more details.
|
||||||
|
# You should have received a copy of the GNU Lesser General Public
|
||||||
|
# License along with this library; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
# MA 02110-1301 USA
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,20 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
|
# This library is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU Lesser General Public
|
||||||
|
# License as published by the Free Software Foundation; either
|
||||||
|
# version 2.1 of the License, or (at your option) any later version.
|
||||||
|
# This library is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
# Lesser General Public License for more details.
|
||||||
|
# You should have received a copy of the GNU Lesser General Public
|
||||||
|
# License along with this library; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
# MA 02110-1301 USA
|
||||||
|
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2015, Savoir-faire Linux inc. All Rights Reserved.
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
# This library is free software; you can redistribute it and/or
|
# This library is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU Lesser General Public
|
# modify it under the terms of the GNU Lesser General Public
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2015, Savoir-faire Linux inc. All Rights Reserved.
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
# This library is free software; you can redistribute it and/or
|
# This library is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU Lesser General Public
|
# modify it under the terms of the GNU Lesser General Public
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
# This library is free software; you can redistribute it and/or
|
# This library is free software; you can redistribute it and/or
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
# This library is free software; you can redistribute it and/or
|
# This library is free software; you can redistribute it and/or
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
# encoding: UTF-8
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
# This library is free software; you can redistribute it and/or
|
# This library is free software; you can redistribute it and/or
|
||||||
@@ -13,6 +14,7 @@
|
|||||||
# License along with this library; if not, write to the Free Software
|
# License along with this library; if not, write to the Free Software
|
||||||
# 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
|
||||||
|
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
# encoding: UTF-8
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
# This library is free software; you can redistribute it and/or
|
# This library is free software; you can redistribute it and/or
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
# encoding: UTF-8
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
# This library is free software; you can redistribute it and/or
|
# This library is free software; you can redistribute it and/or
|
||||||
@@ -13,7 +14,6 @@
|
|||||||
# License along with this library; if not, write to the Free Software
|
# License along with this library; if not, write to the Free Software
|
||||||
# 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
|
||||||
|
|
||||||
from num2words import num2words
|
from num2words import num2words
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
# This library is free software; you can redistribute it and/or
|
# This library is free software; you can redistribute it and/or
|
||||||
|
|||||||
@@ -1,19 +1,19 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Copetright (c) 2015, Savoir-faire Linux inc. All Rights Reserved.
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
# This libraret is free software; etou can redistribute it and/or
|
# This library is free software; you can redistribute it and/or
|
||||||
# modifet it under the terms of the GNU Lesser General Public
|
# modify it under the terms of the GNU Lesser General Public
|
||||||
# License as published bet the Free Software Foundation; either
|
# License as published by the Free Software Foundation; either
|
||||||
# version 2.1 of the License, or (at etour option) anet later version.
|
# version 2.1 of the License, or (at your option) any later version.
|
||||||
# This libraret is distributed in the hope that it will be useful,
|
# This library is distributed in the hope that it will be useful,
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warrantet of
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
# Lesser General Public License for more details.
|
# Lesser General Public License for more details.
|
||||||
# You should have received a copet of the GNU Lesser General Public
|
# You should have received a copy of the GNU Lesser General Public
|
||||||
# License along with this libraret; if not, write to the Free Software
|
# License along with this library; if not, write to the Free Software
|
||||||
# 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
|
||||||
|
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2015, Savoir-faire Linux inc. All Rights Reserved.
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
# This library is free software; you can redistribute it and/or
|
# This library is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU Lesser General Public
|
# modify it under the terms of the GNU Lesser General Public
|
||||||
@@ -13,7 +14,6 @@
|
|||||||
# License along with this library; if not, write to the Free Software
|
# License along with this library; if not, write to the Free Software
|
||||||
# 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
|
||||||
|
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2015, Savoir-faire Linux inc. All Rights Reserved.
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
# This library is free software; you can redistribute it and/or
|
# This library is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU Lesser General Public
|
# modify it under the terms of the GNU Lesser General Public
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2015, Savoir-faire Linux inc. All Rights Reserved.
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
# This library is free software; you can redistribute it and/or
|
# This library is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU Lesser General Public
|
# modify it under the terms of the GNU Lesser General Public
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
# This library is free software; you can redistribute it and/or
|
# This library is free software; you can redistribute it and/or
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2015, Savoir-faire Linux inc. All Rights Reserved.
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
# This library is free software; you can redistribute it and/or
|
# This library is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU Lesser General Public
|
# modify it under the terms of the GNU Lesser General Public
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
# This library is free software; you can redistribute it and/or
|
# This library is free software; you can redistribute it and/or
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
# This library is free software; you can redistribute it and/or
|
# This library is free software; you can redistribute it and/or
|
||||||
|
|||||||
@@ -1,4 +1,20 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
|
# This library is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU Lesser General Public
|
||||||
|
# License as published by the Free Software Foundation; either
|
||||||
|
# version 2.1 of the License, or (at your option) any later version.
|
||||||
|
# This library is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
# Lesser General Public License for more details.
|
||||||
|
# You should have received a copy of the GNU Lesser General Public
|
||||||
|
# License along with this library; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
# MA 02110-1301 USA
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|||||||
@@ -1,4 +1,20 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
|
# This library is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU Lesser General Public
|
||||||
|
# License as published by the Free Software Foundation; either
|
||||||
|
# version 2.1 of the License, or (at your option) any later version.
|
||||||
|
# This library is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
# Lesser General Public License for more details.
|
||||||
|
# You should have received a copy of the GNU Lesser General Public
|
||||||
|
# License along with this library; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
# MA 02110-1301 USA
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2015, Savoir-faire Linux inc. All Rights Reserved.
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
# This library is free software; you can redistribute it and/or
|
# This library is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU Lesser General Public
|
# modify it under the terms of the GNU Lesser General Public
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2015, Savoir-faire Linux inc. All Rights Reserved.
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
# This library is free software; you can redistribute it and/or
|
# This library is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU Lesser General Public
|
# modify it under the terms of the GNU Lesser General Public
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2015, Savoir-faire Linux inc. All Rights Reserved.
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
# This library is free software; you can redistribute it and/or
|
# This library is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU Lesser General Public
|
# modify it under the terms of the GNU Lesser General Public
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2015, Savoir-faire Linux inc. All Rights Reserved.
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
# This library is free software; you can redistribute it and/or
|
# This library is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU Lesser General Public
|
# modify it under the terms of the GNU Lesser General Public
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
# This library is free software; you can redistribute it and/or
|
# This library is free software; you can redistribute it and/or
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
# This library is free software; you can redistribute it and/or
|
# This library is free software; you can redistribute it and/or
|
||||||
@@ -13,6 +14,7 @@
|
|||||||
# License along with this library; if not, write to the Free Software
|
# License along with this library; if not, write to the Free Software
|
||||||
# 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
|
||||||
|
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2015, Savoir-faire Linux inc. All Rights Reserved.
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
# This library is free software; you can redistribute it and/or
|
# This library is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU Lesser General Public
|
# modify it under the terms of the GNU Lesser General Public
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
# This library is free software; you can redistribute it and/or
|
# This library is free software; you can redistribute it and/or
|
||||||
@@ -13,6 +14,7 @@
|
|||||||
# License along with this library; if not, write to the Free Software
|
# License along with this library; if not, write to the Free Software
|
||||||
# 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
|
||||||
|
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|||||||
401
tests/test_th.py
401
tests/test_th.py
@@ -1,193 +1,208 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
from __future__ import unicode_literals
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
from unittest import TestCase
|
# This library is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU Lesser General Public
|
||||||
from num2words import num2words
|
# License as published by the Free Software Foundation; either
|
||||||
from num2words.lang_TH import Num2Word_TH
|
# version 2.1 of the License, or (at your option) any later version.
|
||||||
|
# This library is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
class TestNumWord(TestCase):
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
# Lesser General Public License for more details.
|
||||||
def test_0(self):
|
# You should have received a copy of the GNU Lesser General Public
|
||||||
self.assertEqual(num2words(0, lang='th'), "ศูนย์")
|
# License along with this library; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
def test_end_with_1(self):
|
# MA 02110-1301 USA
|
||||||
self.assertEqual(num2words(21, lang='th'), "ยี่สิบเอ็ด")
|
|
||||||
self.assertEqual(num2words(11, lang='th'), "สิบเอ็ด")
|
from __future__ import unicode_literals
|
||||||
self.assertEqual(num2words(101, lang='th'), "หนึ่งร้อยเอ็ด")
|
|
||||||
self.assertEqual(num2words(1201, lang='th'), "หนึ่งพันสองร้อยเอ็ด")
|
from unittest import TestCase
|
||||||
|
|
||||||
def test_start_20(self):
|
from num2words import num2words
|
||||||
self.assertEqual(num2words(22, lang='th'), "ยี่สิบสอง")
|
from num2words.lang_TH import Num2Word_TH
|
||||||
self.assertEqual(num2words(27, lang='th'), "ยี่สิบเจ็ด")
|
|
||||||
|
|
||||||
def test_start_10(self):
|
class TestNumWord(TestCase):
|
||||||
self.assertEqual(num2words(10, lang='th'), "สิบ")
|
|
||||||
self.assertEqual(num2words(18, lang='th'), "สิบแปด")
|
def test_0(self):
|
||||||
|
self.assertEqual(num2words(0, lang='th'), "ศูนย์")
|
||||||
def test_1_to_9(self):
|
|
||||||
self.assertEqual(num2words(1, lang='th'), "หนึ่ง")
|
def test_end_with_1(self):
|
||||||
self.assertEqual(num2words(5, lang='th'), "ห้า")
|
self.assertEqual(num2words(21, lang='th'), "ยี่สิบเอ็ด")
|
||||||
self.assertEqual(num2words(9, lang='th'), "เก้า")
|
self.assertEqual(num2words(11, lang='th'), "สิบเอ็ด")
|
||||||
|
self.assertEqual(num2words(101, lang='th'), "หนึ่งร้อยเอ็ด")
|
||||||
def test_31_to_99(self):
|
self.assertEqual(num2words(1201, lang='th'), "หนึ่งพันสองร้อยเอ็ด")
|
||||||
self.assertEqual(num2words(31, lang='th'), "สามสิบเอ็ด")
|
|
||||||
self.assertEqual(num2words(48, lang='th'), "สี่สิบแปด")
|
def test_start_20(self):
|
||||||
self.assertEqual(num2words(76, lang='th'), "เจ็ดสิบหก")
|
self.assertEqual(num2words(22, lang='th'), "ยี่สิบสอง")
|
||||||
|
self.assertEqual(num2words(27, lang='th'), "ยี่สิบเจ็ด")
|
||||||
def test_100_to_999(self):
|
|
||||||
self.assertEqual(num2words(100, lang='th'), "หนึ่งร้อย")
|
def test_start_10(self):
|
||||||
self.assertEqual(num2words(123, lang='th'), "หนึ่งร้อยยี่สิบสาม")
|
self.assertEqual(num2words(10, lang='th'), "สิบ")
|
||||||
self.assertEqual(num2words(456, lang='th'), "สี่ร้อยห้าสิบหก")
|
self.assertEqual(num2words(18, lang='th'), "สิบแปด")
|
||||||
self.assertEqual(num2words(721, lang='th'), "เจ็ดร้อยยี่สิบเอ็ด")
|
|
||||||
|
def test_1_to_9(self):
|
||||||
def test_1000_to_9999(self):
|
self.assertEqual(num2words(1, lang='th'), "หนึ่ง")
|
||||||
self.assertEqual(num2words(1000, lang='th'), "หนึ่งพัน")
|
self.assertEqual(num2words(5, lang='th'), "ห้า")
|
||||||
self.assertEqual(
|
self.assertEqual(num2words(9, lang='th'), "เก้า")
|
||||||
num2words(2175, lang='th'), "สองพันหนึ่งร้อยเจ็ดสิบห้า"
|
|
||||||
)
|
def test_31_to_99(self):
|
||||||
self.assertEqual(num2words(4582, lang='th'), "สี่พันห้าร้อยแปดสิบสอง")
|
self.assertEqual(num2words(31, lang='th'), "สามสิบเอ็ด")
|
||||||
self.assertEqual(num2words(9346, lang='th'), "เก้าพันสามร้อยสี่สิบหก")
|
self.assertEqual(num2words(48, lang='th'), "สี่สิบแปด")
|
||||||
|
self.assertEqual(num2words(76, lang='th'), "เจ็ดสิบหก")
|
||||||
def test_10000_to_99999(self):
|
|
||||||
self.assertEqual(
|
def test_100_to_999(self):
|
||||||
num2words(11111, lang='th'), "หนึ่งหมื่นหนึ่งพันหนึ่งร้อยสิบเอ็ด"
|
self.assertEqual(num2words(100, lang='th'), "หนึ่งร้อย")
|
||||||
)
|
self.assertEqual(num2words(123, lang='th'), "หนึ่งร้อยยี่สิบสาม")
|
||||||
self.assertEqual(
|
self.assertEqual(num2words(456, lang='th'), "สี่ร้อยห้าสิบหก")
|
||||||
num2words(22222, lang='th'), "สองหมื่นสองพันสองร้อยยี่สิบสอง"
|
self.assertEqual(num2words(721, lang='th'), "เจ็ดร้อยยี่สิบเอ็ด")
|
||||||
)
|
|
||||||
self.assertEqual(
|
def test_1000_to_9999(self):
|
||||||
num2words(84573, lang='th'), "แปดหมื่นสี่พันห้าร้อยเจ็ดสิบสาม"
|
self.assertEqual(num2words(1000, lang='th'), "หนึ่งพัน")
|
||||||
)
|
self.assertEqual(
|
||||||
|
num2words(2175, lang='th'), "สองพันหนึ่งร้อยเจ็ดสิบห้า"
|
||||||
def test_100000_to_999999(self):
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(num2words(4582, lang='th'), "สี่พันห้าร้อยแปดสิบสอง")
|
||||||
num2words(153247, lang='th'),
|
self.assertEqual(num2words(9346, lang='th'), "เก้าพันสามร้อยสี่สิบหก")
|
||||||
"หนึ่งแสนห้าหมื่นสามพันสองร้อยสี่สิบเจ็ด"
|
|
||||||
)
|
def test_10000_to_99999(self):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
num2words(562442, lang='th'),
|
num2words(11111, lang='th'), "หนึ่งหมื่นหนึ่งพันหนึ่งร้อยสิบเอ็ด"
|
||||||
"ห้าแสนหกหมื่นสองพันสี่ร้อยสี่สิบสอง"
|
)
|
||||||
)
|
self.assertEqual(
|
||||||
self.assertEqual(
|
num2words(22222, lang='th'), "สองหมื่นสองพันสองร้อยยี่สิบสอง"
|
||||||
num2words(999999, lang='th'),
|
)
|
||||||
"เก้าแสนเก้าหมื่นเก้าพันเก้าร้อยเก้าสิบเก้า"
|
self.assertEqual(
|
||||||
)
|
num2words(84573, lang='th'), "แปดหมื่นสี่พันห้าร้อยเจ็ดสิบสาม"
|
||||||
|
)
|
||||||
def test_more_than_million(self):
|
|
||||||
self.assertEqual(
|
def test_100000_to_999999(self):
|
||||||
num2words(1000000, lang='th'),
|
self.assertEqual(
|
||||||
"หนึ่งล้าน"
|
num2words(153247, lang='th'),
|
||||||
)
|
"หนึ่งแสนห้าหมื่นสามพันสองร้อยสี่สิบเจ็ด"
|
||||||
self.assertEqual(
|
)
|
||||||
num2words(1000001, lang='th'),
|
self.assertEqual(
|
||||||
"หนึ่งล้านเอ็ด"
|
num2words(562442, lang='th'),
|
||||||
)
|
"ห้าแสนหกหมื่นสองพันสี่ร้อยสี่สิบสอง"
|
||||||
self.assertEqual(
|
)
|
||||||
num2words(42478941, lang='th'),
|
self.assertEqual(
|
||||||
"สี่สิบสองล้านสี่แสนเจ็ดหมื่นแปดพันเก้าร้อยสี่สิบเอ็ด"
|
num2words(999999, lang='th'),
|
||||||
)
|
"เก้าแสนเก้าหมื่นเก้าพันเก้าร้อยเก้าสิบเก้า"
|
||||||
self.assertEqual(
|
)
|
||||||
num2words(712696969, lang='th'),
|
|
||||||
"เจ็ดร้อยสิบสองล้านหกแสนเก้าหมื่นหกพันเก้าร้อยหกสิบเก้า"
|
def test_more_than_million(self):
|
||||||
)
|
self.assertEqual(
|
||||||
self.assertEqual(
|
num2words(1000000, lang='th'),
|
||||||
num2words(1000000000000000001, lang='th'),
|
"หนึ่งล้าน"
|
||||||
"หนึ่งล้านล้านล้านเอ็ด"
|
)
|
||||||
)
|
self.assertEqual(
|
||||||
|
num2words(1000001, lang='th'),
|
||||||
def test_decimal(self):
|
"หนึ่งล้านเอ็ด"
|
||||||
self.assertEqual(
|
)
|
||||||
num2words(0.0, lang='th'), "ศูนย์"
|
self.assertEqual(
|
||||||
)
|
num2words(42478941, lang='th'),
|
||||||
self.assertEqual(
|
"สี่สิบสองล้านสี่แสนเจ็ดหมื่นแปดพันเก้าร้อยสี่สิบเอ็ด"
|
||||||
num2words(0.0038, lang='th'), "ศูนย์จุดศูนย์ศูนย์สามแปด"
|
)
|
||||||
)
|
self.assertEqual(
|
||||||
self.assertEqual(
|
num2words(712696969, lang='th'),
|
||||||
num2words(0.01, lang='th'), "ศูนย์จุดศูนย์หนึ่ง"
|
"เจ็ดร้อยสิบสองล้านหกแสนเก้าหมื่นหกพันเก้าร้อยหกสิบเก้า"
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
num2words(1.123, lang='th'), "หนึ่งจุดหนึ่งสองสาม"
|
num2words(1000000000000000001, lang='th'),
|
||||||
)
|
"หนึ่งล้านล้านล้านเอ็ด"
|
||||||
self.assertEqual(
|
)
|
||||||
num2words(35.37, lang='th'), "สามสิบห้าจุดสามเจ็ด"
|
|
||||||
)
|
def test_decimal(self):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
num2words(1000000.01, lang='th'), "หนึ่งล้านจุดศูนย์หนึ่ง"
|
num2words(0.0, lang='th'), "ศูนย์"
|
||||||
)
|
)
|
||||||
|
self.assertEqual(
|
||||||
def test_currency(self):
|
num2words(0.0038, lang='th'), "ศูนย์จุดศูนย์ศูนย์สามแปด"
|
||||||
self.assertEqual(
|
)
|
||||||
num2words(100, lang='th', to='currency', currency='THB'),
|
self.assertEqual(
|
||||||
"หนึ่งร้อยบาทถ้วน"
|
num2words(0.01, lang='th'), "ศูนย์จุดศูนย์หนึ่ง"
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
num2words(100, lang='th', to='currency', currency='USD'),
|
num2words(1.123, lang='th'), "หนึ่งจุดหนึ่งสองสาม"
|
||||||
"หนึ่งร้อยดอลลาร์"
|
)
|
||||||
)
|
self.assertEqual(
|
||||||
self.assertEqual(
|
num2words(35.37, lang='th'), "สามสิบห้าจุดสามเจ็ด"
|
||||||
num2words(100, lang='th', to='currency', currency='EUR'),
|
)
|
||||||
"หนึ่งร้อยยูโร"
|
self.assertEqual(
|
||||||
)
|
num2words(1000000.01, lang='th'), "หนึ่งล้านจุดศูนย์หนึ่ง"
|
||||||
|
)
|
||||||
def test_currency_decimal(self):
|
|
||||||
self.assertEqual(
|
def test_currency(self):
|
||||||
num2words(0.00, lang='th', to='currency'), "ศูนย์บาทถ้วน"
|
self.assertEqual(
|
||||||
)
|
num2words(100, lang='th', to='currency', currency='THB'),
|
||||||
self.assertEqual(
|
"หนึ่งร้อยบาทถ้วน"
|
||||||
num2words(0.05, lang='th', to='currency'), "ห้าสตางค์"
|
)
|
||||||
)
|
self.assertEqual(
|
||||||
self.assertEqual(
|
num2words(100, lang='th', to='currency', currency='USD'),
|
||||||
num2words(0.50, lang='th', to='currency'), "ห้าสิบสตางค์"
|
"หนึ่งร้อยดอลลาร์"
|
||||||
)
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
num2words(0.99, lang='th', to='currency'), "เก้าสิบเก้าสตางค์"
|
num2words(100, lang='th', to='currency', currency='EUR'),
|
||||||
)
|
"หนึ่งร้อยยูโร"
|
||||||
self.assertEqual(
|
)
|
||||||
num2words(100.00, lang='th', to='currency'), "หนึ่งร้อยบาทถ้วน"
|
|
||||||
)
|
def test_currency_decimal(self):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
num2words(100.23, lang='th', to='currency', currency='USD'),
|
num2words(0.00, lang='th', to='currency'), "ศูนย์บาทถ้วน"
|
||||||
"หนึ่งร้อยดอลลาร์ยี่สิบสามเซนต์"
|
)
|
||||||
)
|
self.assertEqual(
|
||||||
self.assertEqual(
|
num2words(0.05, lang='th', to='currency'), "ห้าสตางค์"
|
||||||
num2words(100.24, lang='th', to='currency', currency='EUR'),
|
)
|
||||||
"หนึ่งร้อยยูโรยี่สิบสี่เซนต์"
|
self.assertEqual(
|
||||||
)
|
num2words(0.50, lang='th', to='currency'), "ห้าสิบสตางค์"
|
||||||
|
)
|
||||||
def test_negative(self):
|
self.assertEqual(
|
||||||
self.assertEqual(num2words(-10, lang='th'), "ติดลบสิบ")
|
num2words(0.99, lang='th', to='currency'), "เก้าสิบเก้าสตางค์"
|
||||||
self.assertEqual(num2words(-10.50, lang='th'), "ติดลบสิบจุดห้า")
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
num2words(-100.00, lang='th', to='currency'),
|
num2words(100.00, lang='th', to='currency'), "หนึ่งร้อยบาทถ้วน"
|
||||||
"ติดลบหนึ่งร้อยบาทถ้วน"
|
)
|
||||||
)
|
self.assertEqual(
|
||||||
|
num2words(100.23, lang='th', to='currency', currency='USD'),
|
||||||
def test_round_2_decimal(self):
|
"หนึ่งร้อยดอลลาร์ยี่สิบสามเซนต์"
|
||||||
n2wTH = Num2Word_TH()
|
)
|
||||||
self.assertEqual(n2wTH.round_2_decimal(0.004), ('0.00', False))
|
self.assertEqual(
|
||||||
self.assertEqual(n2wTH.round_2_decimal(0.005), ('0.01', False))
|
num2words(100.24, lang='th', to='currency', currency='EUR'),
|
||||||
self.assertEqual(n2wTH.round_2_decimal(0.006), ('0.01', False))
|
"หนึ่งร้อยยูโรยี่สิบสี่เซนต์"
|
||||||
self.assertEqual(n2wTH.round_2_decimal(0.0005),
|
)
|
||||||
('0.00', False))
|
|
||||||
self.assertEqual(n2wTH.round_2_decimal(0.984), ('0.98', False))
|
def test_negative(self):
|
||||||
self.assertEqual(n2wTH.round_2_decimal(0.989), ('0.99', False))
|
self.assertEqual(num2words(-10, lang='th'), "ติดลบสิบ")
|
||||||
self.assertEqual(n2wTH.round_2_decimal(0.994), ('0.99', False))
|
self.assertEqual(num2words(-10.50, lang='th'), "ติดลบสิบจุดห้า")
|
||||||
self.assertEqual(n2wTH.round_2_decimal(0.999), ('1.00', False))
|
self.assertEqual(
|
||||||
self.assertEqual(n2wTH.round_2_decimal(-0.994), ('0.99', True))
|
num2words(-100.00, lang='th', to='currency'),
|
||||||
self.assertEqual(n2wTH.round_2_decimal(-0.999), ('1.00', True))
|
"ติดลบหนึ่งร้อยบาทถ้วน"
|
||||||
# self.assertEqual(n2wTH.round_2_decimal(0.985), ('0.99', False))
|
)
|
||||||
# Expect 0.99 get 0.98
|
|
||||||
# self.assertEqual(n2wTH.round_2_decimal(0.995), ('1.00', False))
|
def test_round_2_decimal(self):
|
||||||
# Expect 1.00 get 0.99
|
n2wTH = Num2Word_TH()
|
||||||
|
self.assertEqual(n2wTH.round_2_decimal(0.004), ('0.00', False))
|
||||||
def test_split_six(self):
|
self.assertEqual(n2wTH.round_2_decimal(0.005), ('0.01', False))
|
||||||
n2wTH = Num2Word_TH()
|
self.assertEqual(n2wTH.round_2_decimal(0.006), ('0.01', False))
|
||||||
self.assertEqual(n2wTH.split_six(str(123456789)),
|
self.assertEqual(n2wTH.round_2_decimal(0.0005),
|
||||||
['987654', '321'])
|
('0.00', False))
|
||||||
self.assertEqual(n2wTH.split_six(str(12345)),
|
self.assertEqual(n2wTH.round_2_decimal(0.984), ('0.98', False))
|
||||||
['54321'])
|
self.assertEqual(n2wTH.round_2_decimal(0.989), ('0.99', False))
|
||||||
self.assertEqual(n2wTH.split_six(str(1234567)),
|
self.assertEqual(n2wTH.round_2_decimal(0.994), ('0.99', False))
|
||||||
['765432', '1'])
|
self.assertEqual(n2wTH.round_2_decimal(0.999), ('1.00', False))
|
||||||
|
self.assertEqual(n2wTH.round_2_decimal(-0.994), ('0.99', True))
|
||||||
|
self.assertEqual(n2wTH.round_2_decimal(-0.999), ('1.00', True))
|
||||||
|
# self.assertEqual(n2wTH.round_2_decimal(0.985), ('0.99', False))
|
||||||
|
# Expect 0.99 get 0.98
|
||||||
|
# self.assertEqual(n2wTH.round_2_decimal(0.995), ('1.00', False))
|
||||||
|
# Expect 1.00 get 0.99
|
||||||
|
|
||||||
|
def test_split_six(self):
|
||||||
|
n2wTH = Num2Word_TH()
|
||||||
|
self.assertEqual(n2wTH.split_six(str(123456789)),
|
||||||
|
['987654', '321'])
|
||||||
|
self.assertEqual(n2wTH.split_six(str(12345)),
|
||||||
|
['54321'])
|
||||||
|
self.assertEqual(n2wTH.split_six(str(1234567)),
|
||||||
|
['765432', '1'])
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
# Copyright (c) 2017, Tufan Kaynak, Framras. All Rights Reserved.
|
|
||||||
|
|
||||||
# This library is free software; you can redistribute it and/or
|
# This library is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU Lesser General Public
|
# modify it under the terms of the GNU Lesser General Public
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
# This library is free software; you can redistribute it and/or
|
# This library is free software; you can redistribute it and/or
|
||||||
@@ -13,6 +14,7 @@
|
|||||||
# License along with this library; if not, write to the Free Software
|
# License along with this library; if not, write to the Free Software
|
||||||
# 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
|
||||||
|
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|||||||
@@ -1,24 +1,41 @@
|
|||||||
from unittest import TestCase
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
from num2words.utils import splitbyx
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
|
# This library is free software; you can redistribute it and/or
|
||||||
class TestUtils(TestCase):
|
# modify it under the terms of the GNU Lesser General Public
|
||||||
def test_splitbyx(self):
|
# License as published by the Free Software Foundation; either
|
||||||
self.assertEqual(list(splitbyx(str(12), 3)), [12])
|
# version 2.1 of the License, or (at your option) any later version.
|
||||||
self.assertEqual(list(splitbyx(str(1234), 3)), [1, 234])
|
# This library is distributed in the hope that it will be useful,
|
||||||
self.assertEqual(list(splitbyx(str(12345678900), 3)),
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
[12, 345, 678, 900]
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
)
|
# Lesser General Public License for more details.
|
||||||
self.assertEqual(list(splitbyx(str(1000000), 6)), [1, 0])
|
# You should have received a copy of the GNU Lesser General Public
|
||||||
|
# License along with this library; if not, write to the Free Software
|
||||||
self.assertEqual(list(splitbyx(str(12), 3, format_int=False)), ['12'])
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
self.assertEqual(list(splitbyx(str(1234), 3, format_int=False)),
|
# MA 02110-1301 USA
|
||||||
['1', '234']
|
|
||||||
)
|
from unittest import TestCase
|
||||||
self.assertEqual(list(splitbyx(str(12345678900), 3, format_int=False)),
|
|
||||||
['12', '345', '678', '900']
|
from num2words.utils import splitbyx
|
||||||
)
|
|
||||||
self.assertEqual(list(splitbyx(str(1000000), 6, format_int=False)),
|
|
||||||
['1', '000000']
|
class TestUtils(TestCase):
|
||||||
)
|
def test_splitbyx(self):
|
||||||
|
self.assertEqual(list(splitbyx(str(12), 3)), [12])
|
||||||
|
self.assertEqual(list(splitbyx(str(1234), 3)), [1, 234])
|
||||||
|
self.assertEqual(list(splitbyx(str(12345678900), 3)),
|
||||||
|
[12, 345, 678, 900]
|
||||||
|
)
|
||||||
|
self.assertEqual(list(splitbyx(str(1000000), 6)), [1, 0])
|
||||||
|
|
||||||
|
self.assertEqual(list(splitbyx(str(12), 3, format_int=False)), ['12'])
|
||||||
|
self.assertEqual(list(splitbyx(str(1234), 3, format_int=False)),
|
||||||
|
['1', '234']
|
||||||
|
)
|
||||||
|
self.assertEqual(list(splitbyx(str(12345678900), 3, format_int=False)),
|
||||||
|
['12', '345', '678', '900']
|
||||||
|
)
|
||||||
|
self.assertEqual(list(splitbyx(str(1000000), 6, format_int=False)),
|
||||||
|
['1', '000000']
|
||||||
|
)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
# -*- encoding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (c) 2015, Savoir-faire Linux inc. All Rights Reserved.
|
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||||
|
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||||
|
|
||||||
# This library is free software; you can redistribute it and/or
|
# This library is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU Lesser General Public
|
# modify it under the terms of the GNU Lesser General Public
|
||||||
|
|||||||
Reference in New Issue
Block a user