-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add number language for digits counting.
- Loading branch information
Showing
3 changed files
with
81 additions
and
3 deletions.
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,56 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import print_function, unicode_literals | ||
from sentence_language import SentenceLanguage | ||
|
||
|
||
class Number(SentenceLanguage): | ||
def __init__(self): | ||
super(Number, self).__init__() | ||
|
||
self.__sentence_template = '{{{user}}} employs {{{total}}} digits{{{counting}}}.'.format( | ||
user=self._USER_TEXT_FIELD_NAME, total=self._TOTAL_FIELD_NAME, counting=self._COUNTING_FIELD_NAME | ||
) | ||
""":type: string""" | ||
self.__character_count_template = ', {{{count}}} {{{char}}}\'s'.format( | ||
count=self._COUNT_FIELD_NAME, char=self._CHARACTER_FIELD_NAME | ||
) | ||
""":type: string""" | ||
|
||
def is_countable_character(self, character): | ||
""" | ||
:type character: string | ||
:rtype: bool | ||
""" | ||
return ('0' <= character <= '9') if character else False | ||
|
||
@property | ||
def special_characters(self): | ||
""" | ||
:rtype: collections.Iterable[string] | ||
""" | ||
return map(str, xrange(10)) | ||
|
||
def translate_number(self, number): | ||
""" | ||
:type number: int|long | ||
:rtype: string | ||
""" | ||
if not isinstance(number, int) and not isinstance(number, long): | ||
raise ValueError('number must be integer') | ||
|
||
return unicode(number) | ||
|
||
@property | ||
def _sentence_template(self): | ||
""" | ||
:rtype: string | ||
""" | ||
return self.__sentence_template | ||
|
||
@property | ||
def _character_count_template(self): | ||
""" | ||
:rtype: string | ||
""" | ||
return self.__character_count_template | ||
|
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