Skip to content

Commit

Permalink
Updated code to work in Python2 and 3 while passing unit tests (#11)
Browse files Browse the repository at this point in the history
* Working in 2.7

* Working in Python 2.7 and 3.6

* Updated versions in Travis CI config, forced Django version to allow tests for Python27
  • Loading branch information
maludwig authored and tehmaze committed Nov 26, 2017
1 parent 7d62ab0 commit d7a1fc9
Show file tree
Hide file tree
Showing 11 changed files with 344 additions and 328 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
language: python
python:
- "2.6"
- "2.7"
- "3.6"
- "nightly"
# command to install build dependencies
before_install:
- pip install -r requirements_development.txt
Expand Down
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ ALL_MO := $(shell ls -1 locale/*.po | while read po; do basename "$$po" | sed -e
test: test-nosetests test-pep8

test-nosetests:
PYTHONPATH=$(shell pwd) \
NOSE_WITH_DOCTEST=1 \
nosetests -w natural/ -v
@nosetests -w natural/ -v --with-doctest

test-pep8:
@pep8 --ignore=E128,E221,E241 natural/
Expand Down
272 changes: 136 additions & 136 deletions natural/constant.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-

from __future__ import unicode_literals
import re
import six
from natural.language import _
Expand Down Expand Up @@ -202,59 +202,59 @@

# natural.number
ORDINAL_SUFFIX = (
_(u'th'),
_(u'st'),
_(u'nd'),
_(u'rd'),
_(u'th'),
_(u'th'),
_(u'th'),
_(u'th'),
_(u'th'),
_(u'th'),
_('th'),
_('st'),
_('nd'),
_('rd'),
_('th'),
_('th'),
_('th'),
_('th'),
_('th'),
_('th'),
)
LARGE_NUMBER_SUFFIX = (
_(u'thousand'),
_(u'million'),
_(u'billion'),
_(u'trillion'),
_(u'quadrillion'),
_(u'quintillion'),
_(u'sextillion'),
_(u'septillion'),
_(u'octillion'),
_(u'nonillion'),
_(u'decillion'),
_(u'undecillion'),
_(u'duodecillion'),
_(u'tredecillion'),
_(u'quattuordecillion'),
_(u'quindecillion'),
_(u'sexdecillion'),
_(u'septendecillion'),
_(u'octodec'),
_(u'novemdecillion'),
_(u'vigintillion'),
_(u'unvigintillion'),
_(u'duovigintil'),
_(u'tresvigintillion'),
_(u'quattuorvigintillion'),
_(u'quinquavigintillion'),
_(u'sesvigintillion'),
_(u'septemvigintillion'),
_(u'octovigintillion'),
_(u'novemvigintillion'),
_(u'trigintillion'),
_(u'untrigintillion'),
_(u'duotrigintillion'),
_(u'trestrigintillion'),
_(u'quattuortrigintillion'),
_(u'quinquatrigintillion'),
_(u'sestrigintillion'),
_(u'septentrigintillion'),
_(u'octotrigintillion'),
_(u'novemtrigintillion'),
_(u'quadragintillion'),
_('thousand'),
_('million'),
_('billion'),
_('trillion'),
_('quadrillion'),
_('quintillion'),
_('sextillion'),
_('septillion'),
_('octillion'),
_('nonillion'),
_('decillion'),
_('undecillion'),
_('duodecillion'),
_('tredecillion'),
_('quattuordecillion'),
_('quindecillion'),
_('sexdecillion'),
_('septendecillion'),
_('octodec'),
_('novemdecillion'),
_('vigintillion'),
_('unvigintillion'),
_('duovigintil'),
_('tresvigintillion'),
_('quattuorvigintillion'),
_('quinquavigintillion'),
_('sesvigintillion'),
_('septemvigintillion'),
_('octovigintillion'),
_('novemvigintillion'),
_('trigintillion'),
_('untrigintillion'),
_('duotrigintillion'),
_('trestrigintillion'),
_('quattuortrigintillion'),
_('quinquatrigintillion'),
_('sestrigintillion'),
_('septentrigintillion'),
_('octotrigintillion'),
_('novemtrigintillion'),
_('quadragintillion'),
)

# natural.file
Expand All @@ -266,22 +266,22 @@

# natural.data
PRINTABLE = list(map(lambda c: chr(c), six.moves.xrange(0x20, 0x7f)))
SPARKCHAR = u'\u2581\u2582\u2583\u2584\u2585\u2586\u2587\u2588'
SPARKCHAR = '\u2581\u2582\u2583\u2584\u2585\u2586\u2587\u2588'

# natural.phone
PHONE_E161_ALPHABET = {
u'0': u'0',
u'1': u'1',
u'2abc': u'2',
u'3def': u'3',
u'4ghi': u'4',
u'5jkl': u'5',
u'6mno': u'6',
u'7prqs': u'7',
u'8tuv': u'8',
u'9xyz': u'9',
u'*': u'*',
u'#': u'#',
'0': '0',
'1': '1',
'2abc': '2',
'3def': '3',
'4ghi': '4',
'5jkl': '5',
'6mno': '6',
'7prqs': '7',
'8tuv': '8',
'9xyz': '9',
'*': '*',
'#': '#',
}
PHONE_PREFIX = list(filter(None, re.split(r'[\n\s]*', '''
1 20 21 211 212 213 216 218 220 221 222 223 224 225 226 227 228 229 230 231
Expand All @@ -300,36 +300,36 @@

# natural.spelling
SPELL_ALPHABET = {
u'a': _(u'Amsterdam'),
u'ä': _(u'ä'), # There is no en_US entry for this
u'b': _(u'Baltimore'),
u'c': _(u'Casablanca'),
u'd': _(u'Danmark'),
u'e': _(u'Edison'),
u'f': _(u'Florida'),
u'g': _(u'Gallipoli'),
u'h': _(u'Havanna'),
u'i': _(u'Italia'),
u'j': _(u'Jerusalem'),
u'k': _(u'Kilogramme'),
u'l': _(u'Liverpool'),
u'm': _(u'Madagaskar'),
u'n': _(u'New York'),
u'ñ': _(u'ñ'), # There is no en_US entry for this
u'o': _(u'Oslo'),
u'ö': _(u'ö'), # There is no en_US entry for this
u'p': _(u'Paris'),
u'q': _(u'Québec'),
u'r': _(u'Roma'),
u's': _(u'Santiago'),
u't': _(u'Tripoli'),
u'u': _(u'Uppsala'),
u'ü': _(u'ü'), # There is no en_US entry for this
u'v': _(u'Valencia'),
u'w': _(u'Washington'),
u'x': _(u'Xantippe'),
u'y': _(u'Yokohama'),
u'z': _(u'Zürich'),
'a': _('Amsterdam'),
'ä': _('ä'), # There is no en_US entry for this
'b': _('Baltimore'),
'c': _('Casablanca'),
'd': _('Danmark'),
'e': _('Edison'),
'f': _('Florida'),
'g': _('Gallipoli'),
'h': _('Havanna'),
'i': _('Italia'),
'j': _('Jerusalem'),
'k': _('Kilogramme'),
'l': _('Liverpool'),
'm': _('Madagaskar'),
'n': _('New York'),
'ñ': _('ñ'), # There is no en_US entry for this
'o': _('Oslo'),
'ö': _('ö'), # There is no en_US entry for this
'p': _('Paris'),
'q': _('Québec'),
'r': _('Roma'),
's': _('Santiago'),
't': _('Tripoli'),
'u': _('Uppsala'),
'ü': _('ü'), # There is no en_US entry for this
'v': _('Valencia'),
'w': _('Washington'),
'x': _('Xantippe'),
'y': _('Yokohama'),
'z': _('Zürich'),
}
NATO_ALPHABET = {
'0': 'zero',
Expand Down Expand Up @@ -411,7 +411,7 @@
'y': 'yang-key',
'z': 'zoo-loo',
}
CODE_ALPHABET_ARMY = (u' ', {
CODE_ALPHABET_ARMY = (' ', {
'0': 'ZE roo',
'1': 'OO nah wun',
'2': 'BEES soh too',
Expand Down Expand Up @@ -490,7 +490,7 @@
'y': 'YANGKEY',
'z': 'ZOOLOO',
})
CODE_ALPHABET_ICAO = (u' ', {
CODE_ALPHABET_ICAO = (' ', {
'0': 'ZE RO',
'1': 'OO NAH WUN',
'2': 'TOO',
Expand Down Expand Up @@ -529,7 +529,7 @@
'y': 'YANG KEY',
'z': 'ZOO LOO',
})
CODE_ALPHABET_MORSE = (u' ', {
CODE_ALPHABET_MORSE = (' ', {
'=': '-...-',
' ': '/',
'_': '..--.-',
Expand Down Expand Up @@ -586,7 +586,7 @@
'y': '-.--',
'z': '--..',
})
CODE_ALPHABET_WORD = (u' ', {
CODE_ALPHABET_WORD = (' ', {
'0': 'zero',
'1': 'one',
'2': 'two',
Expand Down Expand Up @@ -627,41 +627,41 @@
'z': 'zulu',
})
CODE_PRONOUNCIATION = {
'0': _(u'ˈzɛroʊ'),
'1': _(u'ˈwʌn'),
'2': _(u'ˈtuː'),
'3': _(u'ˈtriː'),
'4': _(u'ˈfoʊ.ər'),
'5': _(u'ˈfaɪf'),
'6': _(u'ˈsɪks'),
'7': _(u'ˈsɛvɛn'),
'8': _(u'ˈeɪt'),
'9': _(u'ˈnaɪnər'),
'a': _(u'ælfɑ'),
'b': _(u'ˈbrɑːˈvo'),
'c': _(u'ˈtʃɑːli'),
'd': _(u'ˈdeltɑ '),
'e': _(u'ˈeko'),
'f': _(u'ˈfɔkstrɔt'),
'g': _(u'ɡʌlf'),
'h': _(u'hoːˈtel'),
'i': _(u'ˈindiˑɑ'),
'j': _(u'ˈdʒuːliˑˈet'),
'k': _(u'ˈkiːlo'),
'l': _(u'ˈliːmɑ'),
'm': _(u'mɑik'),
'n': _(u'noˈvembə'),
'o': _(u'ˈɔskɑ'),
'p': _(u'pəˈpɑ'),
'q': _(u'keˈbek'),
'r': _(u'ˈroːmiˑo'),
's': _(u'siˈerɑ'),
't': _(u'ˈtænɡo'),
'.': _(u'ˈstɒp'),
'u': _(u'ˈjuːnifɔːm'),
'v': _(u'ˈviktɑ'),
'w': _(u'ˈwiski'),
'x': _(u'ˈeksˈrei'),
'y': _(u'ˈjænki'),
'z': _(u'ˈzuːluː'),
'0': _('ˈzɛroʊ'),
'1': _('ˈwʌn'),
'2': _('ˈtuː'),
'3': _('ˈtriː'),
'4': _('ˈfoʊ.ər'),
'5': _('ˈfaɪf'),
'6': _('ˈsɪks'),
'7': _('ˈsɛvɛn'),
'8': _('ˈeɪt'),
'9': _('ˈnaɪnər'),
'a': _('ælfɑ'),
'b': _('ˈbrɑːˈvo'),
'c': _('ˈtʃɑːli'),
'd': _('ˈdeltɑ '),
'e': _('ˈeko'),
'f': _('ˈfɔkstrɔt'),
'g': _('ɡʌlf'),
'h': _('hoːˈtel'),
'i': _('ˈindiˑɑ'),
'j': _('ˈdʒuːliˑˈet'),
'k': _('ˈkiːlo'),
'l': _('ˈliːmɑ'),
'm': _('mɑik'),
'n': _('noˈvembə'),
'o': _('ˈɔskɑ'),
'p': _('pəˈpɑ'),
'q': _('keˈbek'),
'r': _('ˈroːmiˑo'),
's': _('siˈerɑ'),
't': _('ˈtænɡo'),
'.': _('ˈstɒp'),
'u': _('ˈjuːnifɔːm'),
'v': _('ˈviktɑ'),
'w': _('ˈwiski'),
'x': _('ˈeksˈrei'),
'y': _('ˈjænki'),
'z': _('ˈzuːluː'),
}

0 comments on commit d7a1fc9

Please sign in to comment.