Skip to content

Commit

Permalink
Additional code clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkmatterVale committed Dec 1, 2015
1 parent f3ce77b commit 1fef0ca
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions chatterbot/adapters/plugins/evaluate_mathematically.py
Expand Up @@ -45,7 +45,7 @@ def simplify_chunks(self, input_text):

string = ''

for chunk in input_text.split( ' ' ):
for chunk in input_text.split():

is_chunk_integer = self.is_integer( chunk )

Expand All @@ -55,9 +55,7 @@ def simplify_chunks(self, input_text):
if is_chunk_float is False:
is_chunk_operator = self.is_operator( chunk )

if is_chunk_operator is False:
continue
else:
if not is_chunk_operator is False:
string += str( is_chunk_operator ) + ' '
else:
string += str( is_chunk_float ) + ' '
Expand Down Expand Up @@ -112,12 +110,16 @@ def normalize(self, string):
and improper calculations.
"""

# If the string is empty, just return it
if len( string ) is 0:
return string

# Setting all words to lowercase
string = string.lower()

# Removing punctuation
if string.endswith( ('.', '!', '?', ':', ';' ) ):
string = string[ : len(string) - 1 ]
if not string[-1].isalnum():
string = string[ : -1 ]

# Removing words
string = self.substitute_words( string )
Expand All @@ -143,7 +145,7 @@ def substitute_words(self, string):

self.load_data( "english" )

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

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

0 comments on commit 1fef0ca

Please sign in to comment.