Skip to content

Commit

Permalink
Simplify comparison and response selection imports
Browse files Browse the repository at this point in the history
  • Loading branch information
gunthercox committed Dec 3, 2016
1 parent e182fb9 commit 1893a5f
Show file tree
Hide file tree
Showing 17 changed files with 33 additions and 33 deletions.
File renamed without changes.
4 changes: 2 additions & 2 deletions chatterbot/logic/approximate_sentence_match.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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
)
2 changes: 1 addition & 1 deletion chatterbot/logic/closest_match.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions chatterbot/logic/closest_meaning.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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
)
4 changes: 2 additions & 2 deletions chatterbot/logic/logic_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions chatterbot/logic/sentiment_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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
)
File renamed without changes.
4 changes: 2 additions & 2 deletions docs/chatterbot.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions docs/conversations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
# ...
Expand Down
4 changes: 2 additions & 2 deletions docs/logic/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
)
Expand Down
4 changes: 2 additions & 2 deletions docs/logic/response_selection.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
# ...
Expand Down
16 changes: 8 additions & 8 deletions tests/benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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': {
Expand All @@ -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': {
Expand All @@ -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'
Expand All @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion tests/logic_adapter_tests/test_best_match.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
8 changes: 4 additions & 4 deletions tests/logic_adapter_tests/test_logic_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,25 @@ 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
)
self.assertTrue(callable(adapter.compare_statements))

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
)
Expand Down

0 comments on commit 1893a5f

Please sign in to comment.