Skip to content

Commit

Permalink
PEP8 fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
gunthercox committed May 10, 2016
1 parent 51c7c33 commit 3365621
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
32 changes: 20 additions & 12 deletions chatterbot/adapters/logic/evaluate_mathematically.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ def simplify_chunks(self, input_text):
"""
Separates the incoming text.
"""

string = ''

for chunk in input_text.split():
Expand Down Expand Up @@ -81,7 +80,6 @@ def is_float(self, string):
the float of the string. Otherwise,
it returns False.
"""

try:
return decimal.Decimal(string)
except decimal.DecimalException:
Expand All @@ -93,7 +91,6 @@ def is_integer(self, string):
the int of the string. Otherwise,
it returns False.
"""

try:
return int(string)
except:
Expand All @@ -102,10 +99,8 @@ def is_integer(self, string):
def is_operator(self, string):
"""
If the string is an operator, returns
said operator. Otherwise, it returns
false.
said operator. Otherwise, it returns false.
"""

if string in "+-/*^()":
return string
else:
Expand Down Expand Up @@ -138,29 +133,42 @@ def load_data(self, language):
"""
Load language-specific data
"""

if language == "english":
with open(os.path.join(os.path.dirname(__file__), 'data', "math_words_EN.json")) as data_file:
data_file = os.path.join(
os.path.dirname(__file__), 'data', 'math_words_EN.json'
)
with open(data_file) as data_file:
data = json.load(data_file)
self.data = data

def substitute_words(self, string):
"""
Substitutes numbers for words.
"""

self.load_data("english")

condensed_string = '_'.join(string.split())

for word in self.data["words"]:
condensed_string = re.sub('_'.join(word.split(' ')), self.data["words"][word], condensed_string)
condensed_string = re.sub(
'_'.join(word.split(' ')),
self.data["words"][word],
condensed_string
)

for number in self.data["numbers"]:
condensed_string = re.sub(number, str(self.data["numbers"][number]), condensed_string)
condensed_string = re.sub(
number,
str(self.data["numbers"][number]),
condensed_string
)

for scale in self.data["scales"]:
condensed_string = re.sub("_" + scale, " " + self.data["scales"][scale], condensed_string)
condensed_string = re.sub(
"_" + scale,
" " + self.data["scales"][scale],
condensed_string
)

condensed_string = condensed_string.split('_')
for chunk_index in range(0, len(condensed_string)):
Expand Down
2 changes: 1 addition & 1 deletion license.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2014, Gunther Cox
Copyright (c) 2016, Gunther Cox
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Expand Down

0 comments on commit 3365621

Please sign in to comment.