no python2 nonsense
This commit is contained in:
parent
bb6a336e0e
commit
33307aa76f
@ -58,19 +58,14 @@ class LevenshteinDistance(Comparator):
|
|||||||
:rtype: float
|
:rtype: float
|
||||||
"""
|
"""
|
||||||
|
|
||||||
PYTHON = sys.version_info[0]
|
|
||||||
|
|
||||||
# Return 0 if either statement has a falsy text value
|
# Return 0 if either statement has a falsy text value
|
||||||
if not statement.text or not other_statement.text:
|
if not statement.text or not other_statement.text:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
# Get the lowercase version of both strings
|
# Get the lowercase version of both strings
|
||||||
if PYTHON < 3:
|
|
||||||
statement_text = unicode(statement.text.lower()) # NOQA
|
statement_text = str(statement.text.lower())
|
||||||
other_statement_text = unicode(other_statement.text.lower()) # NOQA
|
other_statement_text = str(other_statement.text.lower())
|
||||||
else:
|
|
||||||
statement_text = str(statement.text.lower())
|
|
||||||
other_statement_text = str(other_statement.text.lower())
|
|
||||||
|
|
||||||
similarity = SequenceMatcher(
|
similarity = SequenceMatcher(
|
||||||
None,
|
None,
|
||||||
|
@ -33,13 +33,6 @@ class Statement(StatementMixin):
|
|||||||
except UnicodeEncodeError:
|
except UnicodeEncodeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Prefer decoded utf8-strings in Python 2.7
|
|
||||||
if sys.version_info[0] < 3:
|
|
||||||
try:
|
|
||||||
text = text.decode('utf-8')
|
|
||||||
except UnicodeEncodeError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
self.text = text
|
self.text = text
|
||||||
self.tags = kwargs.pop('tags', [])
|
self.tags = kwargs.pop('tags', [])
|
||||||
self.in_response_to = kwargs.pop('in_response_to', [])
|
self.in_response_to = kwargs.pop('in_response_to', [])
|
||||||
|
@ -13,9 +13,4 @@ class UnicodeString(TypeDecorator):
|
|||||||
Coerce Python bytestrings to unicode before
|
Coerce Python bytestrings to unicode before
|
||||||
saving them to the database.
|
saving them to the database.
|
||||||
"""
|
"""
|
||||||
import sys
|
|
||||||
|
|
||||||
if sys.version_info[0] < 3:
|
|
||||||
if isinstance(value, str):
|
|
||||||
value = value.decode('utf-8')
|
|
||||||
return value
|
return value
|
||||||
|
@ -14,10 +14,8 @@ class VariableInputTypeAdapter(InputAdapter):
|
|||||||
def detect_type(self, statement):
|
def detect_type(self, statement):
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
if sys.version_info[0] < 3:
|
|
||||||
string_types = basestring # NOQA
|
string_types = str
|
||||||
else:
|
|
||||||
string_types = str
|
|
||||||
|
|
||||||
if hasattr(statement, 'text'):
|
if hasattr(statement, 'text'):
|
||||||
return self.OBJECT
|
return self.OBJECT
|
||||||
|
@ -30,11 +30,7 @@ def unescape_html(chatbot, statement):
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
# Replace HTML escape characters
|
# Replace HTML escape characters
|
||||||
if sys.version_info[0] < 3:
|
import html
|
||||||
from HTMLParser import HTMLParser
|
|
||||||
html = HTMLParser()
|
|
||||||
else:
|
|
||||||
import html
|
|
||||||
|
|
||||||
statement.text = html.unescape(statement.text)
|
statement.text = html.unescape(statement.text)
|
||||||
|
|
||||||
@ -49,9 +45,6 @@ def convert_to_ascii(chatbot, statement):
|
|||||||
import unicodedata
|
import unicodedata
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
# Normalize unicode characters
|
|
||||||
if sys.version_info[0] < 3:
|
|
||||||
statement.text = unicode(statement.text) # NOQA
|
|
||||||
|
|
||||||
text = unicodedata.normalize('NFKD', statement.text)
|
text = unicodedata.normalize('NFKD', statement.text)
|
||||||
text = text.encode('ascii', 'ignore').decode('utf-8')
|
text = text.encode('ascii', 'ignore').decode('utf-8')
|
||||||
|
@ -393,10 +393,10 @@ class UbuntuCorpusTrainer(Trainer):
|
|||||||
|
|
||||||
file_kwargs = {}
|
file_kwargs = {}
|
||||||
|
|
||||||
if sys.version_info[0] > 2:
|
|
||||||
# Specify the encoding in Python versions 3 and up
|
# Specify the encoding in Python versions 3 and up
|
||||||
file_kwargs['encoding'] = 'utf-8'
|
file_kwargs['encoding'] = 'utf-8'
|
||||||
# WARNING: This might fail to read a unicode corpus file in Python 2.x
|
# WARNING: This might fail to read a unicode corpus file in Python 2.x
|
||||||
|
|
||||||
for file in glob.iglob(extracted_corpus_path):
|
for file in glob.iglob(extracted_corpus_path):
|
||||||
self.logger.info('Training from: {}'.format(file))
|
self.logger.info('Training from: {}'.format(file))
|
||||||
|
@ -77,15 +77,8 @@ def input_function():
|
|||||||
"""
|
"""
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
if sys.version_info[0] < 3:
|
|
||||||
user_input = str(raw_input()) # NOQA
|
|
||||||
|
|
||||||
# Avoid problems using format strings with unicode characters
|
user_input = input() # NOQA
|
||||||
if user_input:
|
|
||||||
user_input = user_input.decode('utf-8')
|
|
||||||
|
|
||||||
else:
|
|
||||||
user_input = input() # NOQA
|
|
||||||
|
|
||||||
return user_input
|
return user_input
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user