-
Notifications
You must be signed in to change notification settings - Fork 506
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add kannada language support #243
Merged
Merged
Changes from 7 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
a21ffa1
add kannada support
akki2825 ea435e2
add Kannada Language support
akki2825 62faf4d
add tests for kannada
akki2825 fa16300
reformatted
akki2825 6b68d4b
change lang param
akki2825 0cfb9d5
fix tests
akki2825 8f55308
Merge https://github.com/savoirfairelinux/num2words
akki2825 8e2677a
add condition
akki2825 3955778
Merge branch 'master' into master
erozqba ee31d19
add modifier
akki2825 8f038a1
add few more test cases
akki2825 a43b5c1
fix test
akki2825 0edef3e
fix test
akki2825 5ffe17a
modify test
akki2825 9cdd54b
fix flake8
akki2825 e422d64
fix isort
akki2825 f3c0036
add more tests
akki2825 1241527
add unicode prefix
akki2825 9d0a4b5
edit tests for float numbers
akki2825 484c759
add more tests
akki2825 eadabc3
add unicode prefix in tests
akki2825 edad794
add Kannada language
akki2825 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
# -*- encoding: 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 .base import Num2Word_Base | ||
|
||
|
||
class Num2Word_KN(Num2Word_Base): | ||
def set_high_numwords(self, high): | ||
for n, word in self.high_numwords: | ||
self.cards[10 ** n] = word | ||
|
||
def setup(self): | ||
self.low_numwords = [ | ||
"ತೊಂಬತ್ತೊಂಬತ್ತು", | ||
"ತೊಂಬತ್ತೆಂಟು", | ||
"ತೊಂಬತ್ತೇಳು", | ||
"ತೊಂಬತ್ತಾರು", | ||
"ತೊಂಬತ್ತೈದು", | ||
"ತೊಂಬತ್ತ ನಾಲ್ಕು", | ||
"ತೊಂಬತ್ತ ಮೂರು", | ||
"ತೊಂಬತ್ತೆರಡು", | ||
"ತೊಂಬತ್ತೊಂದು", | ||
"ತೊಂಬತ್ತು", | ||
"ಎಂಬತ್ತೊಂಬತ್ತು", | ||
"ಎಂಬತ್ತೆಂಟು", | ||
"ಎಂಬತ್ತೇಳು", | ||
"ಎಂಬತ್ತಾರು", | ||
"ಎಂಬತ್ತೈದು", | ||
"ಎಂಬತ್ತ್ ನಾಲ್ಕು", | ||
"ಎಂಬತ್ತ್ ಮೂರು", | ||
"ಎಂಬತ್ತೆರಡು", | ||
"ಎಂಬತ್ತೊಂದು", | ||
"ಎಂಬತ್ತು", | ||
"ಎಪ್ಪತ್ತೊಂಬತ್ತು", | ||
"ಎಪ್ಪತ್ತೆಂಟು", | ||
"ಎಪ್ಪತ್ತೇಳು", | ||
"ಎಪ್ಪತ್ತಾರು", | ||
"ಎಪ್ಪತ್ತೈದು", | ||
"ಎಪ್ಪತ್ತ್ ನಾಲ್ಕು", | ||
"ಎಪ್ಪತ್ತ್ ಮೂರು", | ||
"ಎಪ್ಪತ್ತೆರಡು", | ||
"ಎಪ್ಪತ್ತೊಂದು", | ||
"ಎಪ್ಪತ್ತು", | ||
"ಅರವತ್ತೊಂಬತ್ತು", | ||
"ಅರವತ್ತೆಂಟು", | ||
"ಅರವತ್ತೇಳು", | ||
"ಅರವತ್ತಾರು", | ||
"ಅರವತ್ತೈದು", | ||
"ಅರವತ್ತ್ ನಾಲ್ಕು", | ||
"ಅರವತ್ತ್ ಮೂರು", | ||
"ಅರವತ್ತೆರಡು", | ||
"ಅರವತ್ತೊಂದು", | ||
"ಅರವತ್ತು", | ||
"ಐವತ್ತೊಂಬತ್ತು", | ||
"ಐವತ್ತೆಂಟು", | ||
"ಐವತ್ತೇಳು", | ||
"ಐವತ್ತಾರು", | ||
"ಐವತ್ತೈದು", | ||
"ಐವತ್ತ್ನಾಲ್ಕು", | ||
"ಐವತ್ತಮೂರು", | ||
"ಐವತ್ತೆರಡು", | ||
"ಐವತ್ತೊಂದು", | ||
"ಐವತ್ತು", | ||
"ನಲವತ್ತೊಂಬತ್ತು", | ||
"ನಲವತ್ತೆಂಟು", | ||
"ನಲವತ್ತೇಳು", | ||
"ನಲವತ್ತಾರು", | ||
"ನಲವತ್ತೈದು", | ||
"ನಲವತ್ತ್ ನಾಲ್ಕು", | ||
"ನಲವತ್ತ್ ಮೂರು", | ||
"ನಲವತ್ತ್ ಎರಡು", | ||
"ನಲವತ್ತೊಂದು", | ||
"ನಲವತ್ತು", | ||
"ಮೂವತ್ತ್ ಒಂಬತ್ತು", | ||
"ಮೂವತ್ಎಂಟು", | ||
"ಮೂವತ್ಏಳು", | ||
"ಮೂವತ್ಆರು", | ||
"ಮೂವತ್ತ್ ಐದು", | ||
"ಮೂವತ್ತ್ ನಾಲ್ಕು", | ||
"ಮೂವತ್ತ್ ಮೂರು", | ||
"ಮೂವತ್ತ್ಎರಡು", | ||
"ಮೂವತ್ತ್ಒಂದು", | ||
"ಮೂವತ್ತು", | ||
"ಇಪ್ಪತ್ತ್ಒಂಬತ್ತು", | ||
"ಇಪ್ಪತ್ತ್ಎಂಟು", | ||
"ಇಪ್ಪತ್ತ್ಏಳು", | ||
"ಇಪ್ಪತ್ತ್ಆರು", | ||
"ಇಪ್ಪತ್ತ್ ಐದು", | ||
"ಇಪ್ಪತ್ತ್ ನಾಲ್ಕು", | ||
"ಇಪ್ಪತ್ತ್ ಮೂರು", | ||
"ಇಪ್ಪತ್ತ್ ಎರಡು", | ||
"ಇಪ್ಪತ್ತ್ ಒಂದು", | ||
"ಇಪ್ಪತ್ತು", | ||
"ಹತ್ತೊಂಬತ್ತು", | ||
"ಹದಿನೆಂಟು", | ||
"ಹದಿನೇಳು", | ||
"ಹದಿನಾರು", | ||
"ಹದಿನೈದು", | ||
"ಹದಿನಾಲ್ಕು", | ||
"ಹದಿಮೂರು", | ||
"ಹನ್ನೆರಡು", | ||
"ಹನ್ನೊಂದು", | ||
"ಹತ್ತು", | ||
"ಒಂಬತ್ತು", | ||
"ಎಂಟು", | ||
"ಏಳು", | ||
"ಆರು", | ||
"ಐದು", | ||
"ನಾಲ್ಕು", | ||
"ಮೂರು", | ||
"ಎರಡು", | ||
"ಒಂದು", | ||
"ಸೊನ್ನೆ", | ||
] | ||
|
||
self.mid_numwords = [(100, "ನೂರು")] | ||
|
||
self.high_numwords = [(7, "ಕೋಟಿ"), (5, "ಒಂದು ಲಕ್ಷ"), (3, "ಸಾವಿರ")] | ||
|
||
self.pointword = "ಬಿಂದು" | ||
|
||
self.modifiers = [ | ||
"್", | ||
"ಾ", | ||
"ಿ", | ||
"ೀ", | ||
"ೀ", | ||
"ು", | ||
"ೂ", | ||
"ೃ", | ||
"ೆ", | ||
"ೇ", | ||
"ೈ", | ||
"ೊ", | ||
"ೋ", | ||
"ೌ", | ||
"ೕ", | ||
] | ||
|
||
def merge(self, lpair, rpair): | ||
ltext, lnum = lpair | ||
rtext, rnum = rpair | ||
if lnum == 1 and rnum < 100: | ||
return (rtext, rnum) | ||
elif 100 > lnum > rnum: | ||
return ("%s-%s" % (ltext, rtext), lnum + rnum) | ||
elif lnum >= 100 > rnum: | ||
return ("%s %s" % (ltext, rtext), lnum + rnum) | ||
elif rnum > lnum: | ||
return ("%s %s" % (ltext, rtext), lnum * rnum) | ||
return ("%s %s" % (ltext, rtext), lnum + rnum) | ||
|
||
def to_ordinal_num(self, value): | ||
self.verify_ordinal(value) | ||
return "%s%s" % (value, self.to_ordinal(value)) | ||
|
||
def to_ordinal(self, value): | ||
self.verify_ordinal(value) | ||
outwords = self.to_cardinal(value) | ||
if outwords[-1] in self.modifiers: | ||
outwords = outwords[:-1] | ||
ordinal_num = outwords + "ನೇ" | ||
return ordinal_num |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# -*- 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 unittest import TestCase | ||
|
||
from num2words import num2words | ||
|
||
|
||
class Num2WordsKNTest(TestCase): | ||
def test_numbers(self): | ||
self.assertEqual(num2words(42, lang="kn"), u"ನಲವತ್ತ್ ಎರಡು") | ||
self.assertEqual(num2words(893, lang="kn"), u"ಎಂಟು ನೂರು ತೊಂಬತ್ತ ಮೂರು") | ||
self.assertEqual( | ||
num2words(1729, lang="kn"), u"ಒಂದು ಸಾವಿರ ಏಳು ನೂರು ಇಪ್ಪತ್ತ್ಒಂಬತ್ತು" | ||
) | ||
|
||
def test_ordinals(self): | ||
self.assertEqual(num2words(2, lang="kn", ordinal=True), u"ಎರಡನೇ") | ||
self.assertEqual(num2words(5, lang="kn", ordinal=True), u"ಐದನೇ") | ||
self.assertEqual(num2words(16, lang="kn", ordinal=True), u"ಹದಿನಾರನೇ") |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @akki2825 you are missing this section. With this conditional, the tests pass.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @lepisma