From 1893a5f63f1b6ca0dc7c9a868700e35dce6fbd95 Mon Sep 17 00:00:00 2001 From: Gunther Cox Date: Fri, 2 Dec 2016 21:45:48 -0500 Subject: [PATCH] Simplify comparison and response selection imports --- chatterbot/{conversation => }/comparisons.py | 0 chatterbot/logic/approximate_sentence_match.py | 4 ++-- chatterbot/logic/closest_match.py | 2 +- chatterbot/logic/closest_meaning.py | 4 ++-- chatterbot/logic/logic_adapter.py | 4 ++-- chatterbot/logic/sentiment_adapter.py | 4 ++-- .../{conversation => }/response_selection.py | 0 docs/chatterbot.rst | 4 ++-- docs/conversations.rst | 4 ++-- docs/logic/index.rst | 4 ++-- docs/logic/response_selection.rst | 4 ++-- tests/benchmarks.py | 16 ++++++++-------- .../test_levenshtein_distance.py | 2 +- .../test_sentiment_comparison.py | 2 +- .../test_synset_distance.py | 2 +- tests/logic_adapter_tests/test_best_match.py | 2 +- tests/logic_adapter_tests/test_logic_adapter.py | 8 ++++---- 17 files changed, 33 insertions(+), 33 deletions(-) rename chatterbot/{conversation => }/comparisons.py (100%) rename chatterbot/{conversation => }/response_selection.py (100%) diff --git a/chatterbot/conversation/comparisons.py b/chatterbot/comparisons.py similarity index 100% rename from chatterbot/conversation/comparisons.py rename to chatterbot/comparisons.py diff --git a/chatterbot/logic/approximate_sentence_match.py b/chatterbot/logic/approximate_sentence_match.py index 89878f74e..94fccef61 100644 --- a/chatterbot/logic/approximate_sentence_match.py +++ b/chatterbot/logic/approximate_sentence_match.py @@ -6,7 +6,7 @@ class ApproximateSentenceMatchAdapter(BestMatch): def __init__(self, **kwargs): super(ApproximateSentenceMatchAdapter, self).__init__(**kwargs) - from chatterbot.conversation.comparisons import jaccard_similarity + from chatterbot.comparisons import jaccard_similarity self.compare_statements = kwargs.get( 'statement_comparison_function', @@ -15,6 +15,6 @@ def __init__(self, **kwargs): warnings.warn( 'The ApproximateSentenceMatchAdapter is deprecated. ' + - 'Use "chatterbot.logic.BestMatch" response_selection_method="chatterbot.conversation.comparisons.jaccard_similarity" instead.', + 'Use "chatterbot.logic.BestMatch" response_selection_method="chatterbot.comparisons.jaccard_similarity" instead.', DeprecationWarning ) diff --git a/chatterbot/logic/closest_match.py b/chatterbot/logic/closest_match.py index d7503949d..1d39eddeb 100644 --- a/chatterbot/logic/closest_match.py +++ b/chatterbot/logic/closest_match.py @@ -12,7 +12,7 @@ class ClosestMatchAdapter(BestMatch): def __init__(self, **kwargs): super(ClosestMatchAdapter, self).__init__(**kwargs) - from chatterbot.conversation.comparisons import levenshtein_distance + from chatterbot.comparisons import levenshtein_distance self.compare_statements = kwargs.get( 'statement_comparison_function', diff --git a/chatterbot/logic/closest_meaning.py b/chatterbot/logic/closest_meaning.py index 0715095f1..8beaaf62c 100644 --- a/chatterbot/logic/closest_meaning.py +++ b/chatterbot/logic/closest_meaning.py @@ -14,7 +14,7 @@ class ClosestMeaningAdapter(BestMatch): def __init__(self, **kwargs): super(ClosestMeaningAdapter, self).__init__(**kwargs) - from chatterbot.conversation.comparisons import synset_distance + from chatterbot.comparisons import synset_distance self.compare_statements = kwargs.get( 'statement_comparison_function', @@ -23,6 +23,6 @@ def __init__(self, **kwargs): warnings.warn( 'The ClosestMeaningAdapter is deprecated. ' + - 'Use "chatterbot.logic.BestMatch" with response_selection_method="chatterbot.conversation.comparisons.synset_distance" instead.', + 'Use "chatterbot.logic.BestMatch" with response_selection_method="chatterbot.comparisons.synset_distance" instead.', DeprecationWarning ) diff --git a/chatterbot/logic/logic_adapter.py b/chatterbot/logic/logic_adapter.py index 362692b47..210b2c91d 100644 --- a/chatterbot/logic/logic_adapter.py +++ b/chatterbot/logic/logic_adapter.py @@ -11,8 +11,8 @@ class LogicAdapter(Adapter): def __init__(self, **kwargs): super(LogicAdapter, self).__init__(**kwargs) - from chatterbot.conversation.comparisons import levenshtein_distance - from chatterbot.conversation.response_selection import get_first_response + from chatterbot.comparisons import levenshtein_distance + from chatterbot.response_selection import get_first_response if 'tie_breaking_method' in kwargs: raise DeprecationWarning( diff --git a/chatterbot/logic/sentiment_adapter.py b/chatterbot/logic/sentiment_adapter.py index 08472ed05..6d5b2deaa 100644 --- a/chatterbot/logic/sentiment_adapter.py +++ b/chatterbot/logic/sentiment_adapter.py @@ -10,7 +10,7 @@ class SentimentAdapter(BestMatch): def __init__(self, **kwargs): super(SentimentAdapter, self).__init__(**kwargs) - from chatterbot.conversation.comparisons import sentiment_comparison + from chatterbot.comparisons import sentiment_comparison self.compare_statements = kwargs.get( 'statement_comparison_function', @@ -19,6 +19,6 @@ def __init__(self, **kwargs): warnings.warn( 'The SentimentAdapter is deprecated. ' + - 'Use "chatterbot.logic.BestMatch" response_selection_method="chatterbot.conversation.comparisons.sentiment_comparison" instead.', + 'Use "chatterbot.logic.BestMatch" response_selection_method="chatterbot.comparisons.sentiment_comparison" instead.', DeprecationWarning ) diff --git a/chatterbot/conversation/response_selection.py b/chatterbot/response_selection.py similarity index 100% rename from chatterbot/conversation/response_selection.py rename to chatterbot/response_selection.py diff --git a/docs/chatterbot.rst b/docs/chatterbot.rst index 02e798aeb..45678d346 100644 --- a/docs/chatterbot.rst +++ b/docs/chatterbot.rst @@ -76,8 +76,8 @@ which specifies the import path to the adapter class. logic_adapters=[ { 'import_path': 'my.logic.AdapterClass1', - 'statement_comparison_function': 'chatterbot.conversation.comparisons.levenshtein_distance' - 'response_selection_method': 'chatterbot.conversation.response_selection.get_first_response' + 'statement_comparison_function': 'chatterbot.comparisons.levenshtein_distance' + 'response_selection_method': 'chatterbot.response_selection.get_first_response' }, { 'import_path': 'my.logic.AdapterClass2', diff --git a/docs/conversations.rst b/docs/conversations.rst index e59cab705..61f884980 100644 --- a/docs/conversations.rst +++ b/docs/conversations.rst @@ -52,7 +52,7 @@ selects a response is based on it's ability to compare two statements to each other. There is a number of ways to do this, and ChatterBot comes with a handfull of method built in for you to use. -.. automodule:: chatterbot.conversation.comparisons +.. automodule:: chatterbot.comparisons :members: Use your own comparison function @@ -82,7 +82,7 @@ is shown bellow. .. code-block:: python from chatterbot import ChatBot - from chatterbot.conversation.comparisons import levenshtein_distance + from chatterbot.comparisons import levenshtein_distance chatbot = ChatBot( # ... diff --git a/docs/logic/index.rst b/docs/logic/index.rst index 3b7c80070..f313f408b 100644 --- a/docs/logic/index.rst +++ b/docs/logic/index.rst @@ -54,8 +54,8 @@ Setting parameters logic_adapters=[ { "import_path": "chatterbot.logic.BestMatch", - "response_selection_method": "chatterbot.conversation.comparisons.levenshtein_distance", - "statement_comparison_function": "chatterbot.conversation.response_selection.get_first_response" + "response_selection_method": "chatterbot.comparisons.levenshtein_distance", + "statement_comparison_function": "chatterbot.response_selection.get_first_response" } ] ) diff --git a/docs/logic/response_selection.rst b/docs/logic/response_selection.rst index 77d61bfae..2a4f16f2b 100644 --- a/docs/logic/response_selection.rst +++ b/docs/logic/response_selection.rst @@ -20,7 +20,7 @@ available options. Response selection methods ========================== -.. automodule:: chatterbot.conversation.response_selection +.. automodule:: chatterbot.response_selection :members: Use your own response selection method @@ -48,7 +48,7 @@ is shown bellow. .. code-block:: python from chatterbot import ChatBot - from chatterbot.conversation.response_selection import get_most_frequent_response + from chatterbot.response_selection import get_most_frequent_response chatbot = ChatBot( # ... diff --git a/tests/benchmarks.py b/tests/benchmarks.py index e08f9ca92..973b9244a 100644 --- a/tests/benchmarks.py +++ b/tests/benchmarks.py @@ -21,8 +21,8 @@ 'logic_adapters': [ { 'import_path': 'chatterbot.logic.BaseMatchAdapter', - 'statement_comparison_function': 'chatterbot.conversation.comparisons.levenshtein_distance', - 'response_selection_method': 'chatterbot.conversation.response_selection.get_first_response' + 'statement_comparison_function': 'chatterbot.comparisons.levenshtein_distance', + 'response_selection_method': 'chatterbot.response_selection.get_first_response' } ], 'storage_adapter': { @@ -35,8 +35,8 @@ 'logic_adapters': [ { 'import_path': 'chatterbot.logic.BaseMatchAdapter', - 'statement_comparison_function': 'chatterbot.conversation.comparisons.synset_distance', - 'response_selection_method': 'chatterbot.conversation.response_selection.get_first_response' + 'statement_comparison_function': 'chatterbot.comparisons.synset_distance', + 'response_selection_method': 'chatterbot.response_selection.get_first_response' } ], 'storage_adapter': { @@ -59,8 +59,8 @@ 'logic_adapters': [ { 'import_path': 'chatterbot.logic.BaseMatchAdapter', - 'statement_comparison_function': 'chatterbot.conversation.comparisons.levenshtein_distance', - 'response_selection_method': 'chatterbot.conversation.response_selection.get_first_response' + 'statement_comparison_function': 'chatterbot.comparisons.levenshtein_distance', + 'response_selection_method': 'chatterbot.response_selection.get_first_response' } ], 'storage_adapter': 'chatterbot.storage.MongoDatabaseAdapter' @@ -70,8 +70,8 @@ 'logic_adapters': [ { 'import_path': 'chatterbot.logic.BaseMatchAdapter', - 'statement_comparison_function': 'chatterbot.conversation.comparisons.synset_distance', - 'response_selection_method': 'chatterbot.conversation.response_selection.get_first_response' + 'statement_comparison_function': 'chatterbot.comparisons.synset_distance', + 'response_selection_method': 'chatterbot.response_selection.get_first_response' } ], 'storage_adapter': 'chatterbot.storage.MongoDatabaseAdapter' diff --git a/tests/logic_adapter_tests/best_match_integration_tests/test_levenshtein_distance.py b/tests/logic_adapter_tests/best_match_integration_tests/test_levenshtein_distance.py index bdd77a65d..be15e0635 100644 --- a/tests/logic_adapter_tests/best_match_integration_tests/test_levenshtein_distance.py +++ b/tests/logic_adapter_tests/best_match_integration_tests/test_levenshtein_distance.py @@ -12,7 +12,7 @@ class BestMatchLevenshteinDistanceTestCase(TestCase): """ def setUp(self): - from chatterbot.conversation.comparisons import levenshtein_distance + from chatterbot.comparisons import levenshtein_distance self.adapter = BestMatch( statement_comparison_function=levenshtein_distance diff --git a/tests/logic_adapter_tests/best_match_integration_tests/test_sentiment_comparison.py b/tests/logic_adapter_tests/best_match_integration_tests/test_sentiment_comparison.py index a4c10fe93..12671d826 100644 --- a/tests/logic_adapter_tests/best_match_integration_tests/test_sentiment_comparison.py +++ b/tests/logic_adapter_tests/best_match_integration_tests/test_sentiment_comparison.py @@ -12,7 +12,7 @@ class BestMatchSentimentComparisonTestCase(ChatBotTestCase): def setUp(self): super(BestMatchSentimentComparisonTestCase, self).setUp() from chatterbot.trainers import ListTrainer - from chatterbot.conversation.comparisons import sentiment_comparison + from chatterbot.comparisons import sentiment_comparison self.chatbot.set_trainer(ListTrainer) self.adapter = BestMatch( diff --git a/tests/logic_adapter_tests/best_match_integration_tests/test_synset_distance.py b/tests/logic_adapter_tests/best_match_integration_tests/test_synset_distance.py index 3ae4c8a0d..63a59af49 100644 --- a/tests/logic_adapter_tests/best_match_integration_tests/test_synset_distance.py +++ b/tests/logic_adapter_tests/best_match_integration_tests/test_synset_distance.py @@ -13,7 +13,7 @@ class BestMatchSynsetDistanceTestCase(TestCase): def setUp(self): from chatterbot.utils import nltk_download_corpus - from chatterbot.conversation.comparisons import synset_distance + from chatterbot.comparisons import synset_distance nltk_download_corpus('stopwords') nltk_download_corpus('wordnet') diff --git a/tests/logic_adapter_tests/test_best_match.py b/tests/logic_adapter_tests/test_best_match.py index 98fbc59cf..5c1c6a57a 100644 --- a/tests/logic_adapter_tests/test_best_match.py +++ b/tests/logic_adapter_tests/test_best_match.py @@ -11,7 +11,7 @@ class BestMatchTestCase(TestCase): """ def setUp(self): - from chatterbot.conversation.comparisons import levenshtein_distance + from chatterbot.comparisons import levenshtein_distance self.adapter = BestMatch() diff --git a/tests/logic_adapter_tests/test_logic_adapter.py b/tests/logic_adapter_tests/test_logic_adapter.py index aaa13b4f0..c8592b9e1 100644 --- a/tests/logic_adapter_tests/test_logic_adapter.py +++ b/tests/logic_adapter_tests/test_logic_adapter.py @@ -26,12 +26,12 @@ def test_process(self): def test_set_statement_comparison_function_string(self): adapter = LogicAdapter( - statement_comparison_function='chatterbot.conversation.comparisons.levenshtein_distance' + statement_comparison_function='chatterbot.comparisons.levenshtein_distance' ) self.assertTrue(callable(adapter.compare_statements)) def test_set_statement_comparison_function_callable(self): - from chatterbot.conversation.comparisons import levenshtein_distance + from chatterbot.comparisons import levenshtein_distance adapter = LogicAdapter( statement_comparison_function=levenshtein_distance ) @@ -39,12 +39,12 @@ def test_set_statement_comparison_function_callable(self): def test_set_response_selection_method_string(self): adapter = LogicAdapter( - response_selection_method='chatterbot.conversation.response_selection.get_first_response' + response_selection_method='chatterbot.response_selection.get_first_response' ) self.assertTrue(callable(adapter.select_response)) def test_set_response_selection_method_callable(self): - from chatterbot.conversation.response_selection import get_first_response + from chatterbot.response_selection import get_first_response adapter = LogicAdapter( response_selection_method=get_first_response )