Skip to content

Commit 684bbd7

Browse files
committed
Fix formatting
1 parent 3c761d8 commit 684bbd7

3 files changed

Lines changed: 15 additions & 17 deletions

File tree

‎mathparse/mathparse.py‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: UTF-8 -*-
21
"""
32
Methods for evaluating mathematical equations in strings.
43
"""
@@ -106,7 +105,7 @@ def replace_word_tokens_simplified_chinese(string):
106105
return the string with the words replaced with
107106
an operational equivalent.
108107
"""
109-
words = mathwords.word_groups_for_language('SIMPLIFIED_CHINESE')
108+
words = mathwords.word_groups_for_language('CHI')
110109

111110
# Replace operator words with numeric operators
112111
operators = words['binary_operators'].copy()
@@ -124,7 +123,7 @@ def replace_word_tokens_simplified_chinese(string):
124123

125124
# 九千八百万九千八百——> 98009800
126125
def chinese_string_to_num(str):
127-
if str is '':
126+
if str == '':
128127
return 0
129128

130129
if str in digits:
@@ -525,7 +524,7 @@ def parse(
525524
"""
526525
if language:
527526

528-
if language == 'SIMPLIFIED_CHINESE':
527+
if language == 'CHI':
529528
string = replace_word_tokens_simplified_chinese(string)
530529
else:
531530
string = replace_word_tokens(string, language, stopwords)

‎mathparse/mathwords.py‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import math
2-
31
"""
42
Utility methods for getting math word terms.
53
"""
4+
import math
65

76
BINARY_OPERATORS = {
87
'^', '*', '/', '+', '-'
@@ -642,7 +641,7 @@
642641
'ล้านล้าน': 1000000000000
643642
}
644643
},
645-
'SIMPLIFIED_CHINESE': {
644+
'CHI': {
646645
'unary_operators': {
647646
'平方': '^ 2',
648647
'立方': '^ 3',

‎tests/test_simplified_chinese.py‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,46 +5,46 @@
55
class SimplifiedChineseTestCase(TestCase):
66

77
def test_addition_words(self):
8-
result = mathparse.parse('四加四',language='SIMPLIFIED_CHINESE')
8+
result = mathparse.parse('四加四', language='CHI')
99

1010
self.assertEqual(result, 8)
1111

1212
def test_addition_words_large(self):
13-
result = mathparse.parse('四千两百一加五百', language='SIMPLIFIED_CHINESE')
13+
result = mathparse.parse('四千两百一加五百', language='CHI')
1414

1515
self.assertEqual(result, 4701)
1616

1717
def test_subtraction_words(self):
18-
result = mathparse.parse('三十减二十',language='SIMPLIFIED_CHINESE')
18+
result = mathparse.parse('三十减二十', language='CHI')
1919

2020
self.assertEqual(result, 10)
2121

2222
def test_multiplication_words(self):
23-
result = mathparse.parse('九乘九', language='SIMPLIFIED_CHINESE')
23+
result = mathparse.parse('九乘九', language='CHI')
2424

2525
self.assertEqual(result, 81)
2626

2727
def test_division_words(self):
28-
result = mathparse.parse('十五除以五', language='SIMPLIFIED_CHINESE')
28+
result = mathparse.parse('十五除以五', language='CHI')
2929

3030
self.assertEqual(result, 3)
3131

3232
def test_division_words_large(self):
33-
result = mathparse.parse('一千两百四除以一百', language='SIMPLIFIED_CHINESE')
33+
result = mathparse.parse('一千两百四除以一百', language='CHI')
3434

3535
self.assertEqual(str(result), '12.04')
3636

3737
def test_sqrt(self):
38-
result = mathparse.parse('四开方', language='SIMPLIFIED_CHINESE')
38+
result = mathparse.parse('四开方', language='CHI')
3939

4040
self.assertEqual(result, 2)
4141

4242
def test_squared(self):
43-
result = mathparse.parse('二平方', language='SIMPLIFIED_CHINESE')
43+
result = mathparse.parse('二平方', language='CHI')
4444

4545
self.assertEqual(result, 4)
4646

4747
def test_cubed(self):
48-
result = mathparse.parse('二立方', language='SIMPLIFIED_CHINESE')
48+
result = mathparse.parse('二立方', language='CHI')
4949

50-
self.assertEqual(result, 8)
50+
self.assertEqual(result, 8)

0 commit comments

Comments
 (0)