Skip to content

Commit

Permalink
Remove unicode logging strings and specify unicode literals.
Browse files Browse the repository at this point in the history
  • Loading branch information
gunthercox committed Nov 19, 2016
1 parent ea4bd43 commit 9bb32c4
Show file tree
Hide file tree
Showing 43 changed files with 109 additions and 70 deletions.
10 changes: 5 additions & 5 deletions chatterbot/adapters/input/gitter.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import unicode_literals
from chatterbot.adapters.input import InputAdapter
from chatterbot.conversation import Statement
from time import sleep
Expand Down Expand Up @@ -47,7 +48,7 @@ def join_room(self, room_name):
headers=self.headers,
json={'uri': room_name}
)
self.logger.info(u'{} joining room {}'.format(
self.logger.info('{} joining room {}'.format(
response.status_code, endpoint
))
self._validate_status_code(response)
Expand All @@ -59,7 +60,7 @@ def get_user_data(self):
endpoint,
headers=self.headers
)
self.logger.info(u'{} retrieving user data {}'.format(
self.logger.info('{} retrieving user data {}'.format(
response.status_code, endpoint
))
self._validate_status_code(response)
Expand All @@ -72,7 +73,7 @@ def mark_messages_as_read(self, message_ids):
headers=self.headers,
json={'chat': message_ids}
)
self.logger.info(u'{} marking messages as read {}'.format(
self.logger.info('{} marking messages as read {}'.format(
response.status_code, endpoint
))
self._validate_status_code(response)
Expand All @@ -84,7 +85,7 @@ def get_most_recent_message(self):
endpoint,
headers=self.headers
)
self.logger.info(u'{} getting most recent message'.format(
self.logger.info('{} getting most recent message'.format(
response.status_code
))
self._validate_status_code(response)
Expand Down Expand Up @@ -131,7 +132,6 @@ def process_input(self, statement):
if self.should_respond(data):
self.mark_messages_as_read([data['id']])
new_message = True
self.logger.info(u'')
sleep(self.sleep_time)

text = self.remove_mentions(data['text'])
Expand Down
3 changes: 2 additions & 1 deletion chatterbot/adapters/input/hipchat.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import unicode_literals
from chatterbot.adapters.input import InputAdapter
from chatterbot.conversation import Statement
from time import sleep
Expand Down Expand Up @@ -48,7 +49,7 @@ def view_recent_room_history(self, room_id_or_name, max_results=1):
https://www.hipchat.com/docs/apiv2/method/view_recent_room_history
"""

recent_histroy_url = "{}/v2/room/{}/history?max-results={}".format(
recent_histroy_url = '{}/v2/room/{}/history?max-results={}'.format(
self.hipchat_host,
room_id_or_name,
max_results
Expand Down
9 changes: 5 additions & 4 deletions chatterbot/adapters/input/input_adapter.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import unicode_literals
from chatterbot.adapters import Adapter


Expand All @@ -18,14 +19,14 @@ def process_input_statement(self, *args, **kwargs):
Return an existing statement object (if one exists).
"""
input_statement = self.process_input(*args, **kwargs)
self.logger.info(u'Recieved input statement: {}'.format(input_statement.text))
self.logger.info('Recieved input statement: {}'.format(input_statement.text))

existing_statement = self.context.storage.find(input_statement.text)

if existing_statement:
self.logger.info(u'"{}" is a known statement'.format(input_statement.text))
self.logger.info('"{}" is a known statement'.format(input_statement.text))
input_statement = existing_statement
else:
self.logger.info(u'"{}" is not a known statement'.format(input_statement.text))
self.logger.info('"{}" is not a known statement'.format(input_statement.text))

return input_statement
return input_statement
5 changes: 3 additions & 2 deletions chatterbot/adapters/input/mailgun.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import unicode_literals
from chatterbot.adapters.input import InputAdapter
from chatterbot.conversation import Statement
import requests
Expand All @@ -23,7 +24,7 @@ def get_email_stored_events(self):
params={
'begin': yesterday.isoformat(),
'ascending': 'yes',
'limit': 1
'limit': 1
}
)

Expand Down Expand Up @@ -51,4 +52,4 @@ def process_input(self, statement):

text = message.get('stripped-text')

return Statement(text)
return Statement(text)
7 changes: 4 additions & 3 deletions chatterbot/adapters/input/microsoft.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import unicode_literals
from chatterbot.adapters.input import InputAdapter
from chatterbot.conversation import Statement
from time import sleep
Expand Down Expand Up @@ -50,7 +51,7 @@ def start_conversation(self):
headers=self.headers,
verify=False
)
self.logger.info(u'{} starting conversation {}'.format(
self.logger.info('{} starting conversation {}'.format(
response.status_code, endpoint
))
self._validate_status_code(response)
Expand All @@ -67,7 +68,7 @@ def get_most_recent_message(self):
verify=False
)

self.logger.info(u'{} retrieving most recent messages {}'.format(
self.logger.info('{} retrieving most recent messages {}'.format(
response.status_code, endpoint
))

Expand All @@ -93,7 +94,7 @@ def process_input(self, statement):

text = data['text']
statement = Statement(text)
self.logger.info(u'processing user statement {}'.format(statement))
self.logger.info('processing user statement {}'.format(statement))

return statement

Expand Down
1 change: 1 addition & 0 deletions chatterbot/adapters/input/terminal.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import unicode_literals
from chatterbot.adapters.input import InputAdapter
from chatterbot.conversation import Statement
from chatterbot.utils.read_input import input_function
Expand Down
1 change: 1 addition & 0 deletions chatterbot/adapters/input/variable_input_type_adapter.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import unicode_literals
from chatterbot.adapters.input import InputAdapter
from chatterbot.conversation import Statement

Expand Down
3 changes: 1 addition & 2 deletions chatterbot/adapters/logic/approximate_sentence_match.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from .base_match import BaseMatchAdapter


Expand All @@ -11,4 +10,4 @@ def __init__(self, **kwargs):
self.compare_statements = kwargs.get(
'statement_comparison_function',
jaccard_similarity
)
)
14 changes: 7 additions & 7 deletions chatterbot/adapters/logic/base_match.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from .logic_adapter import LogicAdapter


Expand Down Expand Up @@ -26,8 +26,8 @@ def get(self, input_statement):
if self.has_storage_context:
# Use a randomly picked statement
self.logger.info(
u'No statements have known responses. ' +
u'Choosing a random response to return.'
'No statements have known responses. ' +
'Choosing a random response to return.'
)
return 0, self.context.storage.get_random()
else:
Expand Down Expand Up @@ -57,7 +57,7 @@ def process(self, input_statement):

# Select the closest match to the input statement
confidence, closest_match = self.get(input_statement)
self.logger.info(u'Using "{}" as a close match to "{}"'.format(
self.logger.info('Using "{}" as a close match to "{}"'.format(
input_statement.text, closest_match.text
))

Expand All @@ -71,16 +71,16 @@ def process(self, input_statement):

if response_list:
self.logger.info(
u'Selecting response from {} optimal responses.'.format(
'Selecting response from {} optimal responses.'.format(
len(response_list)
)
)
response = self.select_response(input_statement, response_list)
self.logger.info(u'Response selected. Using "{}"'.format(response.text))
self.logger.info('Response selected. Using "{}"'.format(response.text))
else:
response = self.context.storage.get_random()
self.logger.info(
u'No response to "{}" found. Selecting a random response.'.format(
'No response to "{}" found. Selecting a random response.'.format(
closest_match.text
)
)
Expand Down
3 changes: 1 addition & 2 deletions chatterbot/adapters/logic/closest_match.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from .base_match import BaseMatchAdapter


Expand All @@ -17,4 +16,4 @@ def __init__(self, **kwargs):
self.compare_statements = kwargs.get(
'statement_comparison_function',
levenshtein_distance
)
)
3 changes: 1 addition & 2 deletions chatterbot/adapters/logic/closest_meaning.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from .base_match import BaseMatchAdapter


Expand All @@ -19,4 +18,4 @@ def __init__(self, **kwargs):
self.compare_statements = kwargs.get(
'statement_comparison_function',
synset_distance
)
)
3 changes: 2 additions & 1 deletion chatterbot/adapters/logic/logic_adapter.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import unicode_literals
from chatterbot.adapters import Adapter
from chatterbot.utils.module_loading import import_module

Expand Down Expand Up @@ -76,7 +77,7 @@ def process(self, statement):

class EmptyDatasetException(Exception):

def __init__(self, value="An empty set was received when at least one statement was expected."):
def __init__(self, value='An empty set was received when at least one statement was expected.'):
self.value = value

def __str__(self):
Expand Down
2 changes: 1 addition & 1 deletion chatterbot/adapters/logic/low_confidence.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from chatterbot.conversation import Statement
from .base_match import BaseMatchAdapter

Expand Down
1 change: 1 addition & 0 deletions chatterbot/adapters/logic/mathematical_evaluation.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import unicode_literals
from chatterbot.adapters.logic import LogicAdapter
from chatterbot.conversation import Statement
import re
Expand Down
5 changes: 3 additions & 2 deletions chatterbot/adapters/logic/multi_adapter.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import unicode_literals
from .logic_adapter import LogicAdapter
from collections import Counter

Expand Down Expand Up @@ -32,7 +33,7 @@ def process(self, statement):
results.append((confidence, output, ))

self.logger.info(
u'{} selected "{}" as a response with a confidence of {}'.format(
'{} selected "{}" as a response with a confidence of {}'.format(
str(adapter.__class__), output.text, confidence
)
)
Expand All @@ -42,7 +43,7 @@ def process(self, statement):
max_confidence = confidence
else:
self.logger.info(
u'Not processing the statement using {}'.format(
'Not processing the statement using {}'.format(
str(adapter.__class__)
)
)
Expand Down
1 change: 1 addition & 0 deletions chatterbot/adapters/logic/no_knowledge_adapter.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import unicode_literals
from .logic_adapter import LogicAdapter


Expand Down
3 changes: 1 addition & 2 deletions chatterbot/adapters/logic/sentiment_adapter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from .base_match import BaseMatchAdapter


Expand All @@ -15,4 +14,4 @@ def __init__(self, **kwargs):
self.compare_statements = kwargs.get(
'statement_comparison_function',
sentiment_comparison
)
)
1 change: 1 addition & 0 deletions chatterbot/adapters/logic/specific_response.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import unicode_literals
from .logic_adapter import LogicAdapter


Expand Down
19 changes: 10 additions & 9 deletions chatterbot/adapters/logic/time_adapter.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import unicode_literals
from .logic_adapter import LogicAdapter
from chatterbot.conversation import Statement
from textblob.classifiers import NaiveBayesClassifier
Expand All @@ -13,14 +14,14 @@ def __init__(self, **kwargs):
super(TimeLogicAdapter, self).__init__(**kwargs)

training_data = [
("what time is it", 1),
("do you know the time", 1),
("do you know what time it is", 1),
("what is the time", 1),
("it is time to go to sleep", 0),
("what is your favorite color", 0),
("i had a great time", 0),
("what is", 0)
('what time is it', 1),
('do you know the time', 1),
('do you know what time it is', 1),
('what is the time', 1),
('it is time to go to sleep', 0),
('what is your favorite color', 0),
('i had a great time', 0),
('what is', 0)
]

self.classifier = NaiveBayesClassifier(training_data)
Expand All @@ -29,6 +30,6 @@ def process(self, statement):
now = datetime.now()

confidence = self.classifier.classify(statement.text.lower())
response = Statement("The current time is " + now.strftime("%I:%M %p"))
response = Statement('The current time is ' + now.strftime('%I:%M %p'))

return confidence, response
5 changes: 3 additions & 2 deletions chatterbot/adapters/output/gitter.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import unicode_literals
from chatterbot.adapters.output import OutputAdapter
import requests

Expand Down Expand Up @@ -39,7 +40,7 @@ def join_room(self, room_name):
headers=self.headers,
json={'uri': room_name}
)
self.logger.info(u'{} status joining room {}'.format(
self.logger.info('{} status joining room {}'.format(
response.status_code, endpoint
))
self._validate_status_code(response)
Expand All @@ -55,7 +56,7 @@ def send_message(self, text):
headers=self.headers,
json={'text': text}
)
self.logger.info(u'{} sending message to {}'.format(
self.logger.info('{} sending message to {}'.format(
response.status_code, endpoint
))
self._validate_status_code(response)
Expand Down
1 change: 1 addition & 0 deletions chatterbot/adapters/output/hipchat.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import unicode_literals
from chatterbot.adapters.output import OutputAdapter
import requests
import json
Expand Down
Loading

0 comments on commit 9bb32c4

Please sign in to comment.