Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more default value documentation #947

Merged
merged 1 commit into from
Aug 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion chatterbot/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
class Adapter(object):
"""
A superclass for all adapter classes.

:param logger: A python logger.
"""

def __init__(self, **kwargs):
Expand All @@ -13,6 +15,9 @@ def __init__(self, **kwargs):
def set_chatbot(self, chatbot):
"""
Gives the adapter access to an instance of the ChatBot class.

:param chatbot: A chat bot instanse.
:type chatbot: ChatBot
"""
self.chatbot = chatbot

Expand All @@ -36,6 +41,7 @@ def __str__(self):

class InvalidAdapterTypeException(Exception):
"""
An exception to be raised when an adapter of an unexpected class type is recieved.
An exception to be raised when an adapter
of an unexpected class type is received.
"""
pass
6 changes: 6 additions & 0 deletions chatterbot/logic/logic_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ class LogicAdapter(Adapter):
"""
This is an abstract class that represents the interface
that all logic adapters should implement.

:param statement_comparison_function: The dot-notated import path to a statement comparison function.
Defaults to ``levenshtein_distance``.

:param response_selection_method: The a response selection method.
Defaults to ``get_first_response``.
"""

def __init__(self, **kwargs):
Expand Down
52 changes: 18 additions & 34 deletions docs/chatterbot.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
ChatterBot
==========

The main class :code:`ChatBot` is a connecting point between each of
The main class ``ChatBot`` is a connecting point between each of
ChatterBot's :term:`adapters`. In this class, an input statement is returned
from the :term:`input adapter`, processed and stored by the :term:`logic adapter`
and :term:`storage adapter`, and then passed to the output adapter to be returned
Expand All @@ -14,25 +14,29 @@ to the user.
:param name: A name is the only required parameter for the ChatBot class.
:type name: str

:param storage_adapter: The import path to a storage adapter class.
:keyword storage_adapter: The dot-notated import path to a storage adapter class.
Defaults to ``"chatterbot.storage.SQLStorageAdapter"``.
:type storage_adapter: str

:param logic_adapters: A list of string paths to each logic adapter the bot uses.
:param logic_adapters: A list of dot-notated import paths to each logic adapter the bot uses.
Defaults to ``["chatterbot.logic.BestMatch"]``.
:type logic_adapters: list

:param input_adapter: The import path to an input adapter class.
:param input_adapter: The dot-notated import path to an input adapter class.
Defaults to ``"chatterbot.input.VariableInputTypeAdapter"``.
:type input_adapter: str

:param output_adapter: The import path to an output adapter class.
:param output_adapter: The dot-notated import path to an output adapter class.
Defaults to ``"chatterbot.output.OutputAdapter"``.
:type output_adapter: str

:param trainer: The import path to the training class to be used with the chat bot.
:param trainer: The dot-notated import path to the training class to be used with the chat bot.
:type trainer: str

:param filters: A list of import paths to filter classes to be used by the chat bot.
:param filters: A list of dot-notated import paths to filter classes to be used by the chat bot.
:type filters: list

:param logger: A :code:`Logger` object.
:param logger: A ``Logger`` object.
:type logger: logging.Logger

Example chat bot parameters
Expand Down Expand Up @@ -62,7 +66,7 @@ Example expanded chat bot parameters
====================================

It is also possible to pass parameters directly to individual adapters.
To do this, you must use a dictionary that contains a key called :code:`import_path`
To do this, you must use a dictionary that contains a key called ``import_path``
which specifies the import path to the adapter class.

.. code-block:: python
Expand Down Expand Up @@ -112,7 +116,8 @@ logging by setting the logging level in your code.
# ...
)

The logging levels available are :code:`CRITICAL`, :code:`ERROR`, :code:`WARNING`, :code:`INFO`, :code:`DEBUG`, and :code:`NOTSET`.
The logging levels available are
``CRITICAL``, ``ERROR``, ``WARNING``, ``INFO``, ``DEBUG``, and ``NOTSET``.
See the `Python logging documentation`_ for more information.

Using a custom logger
Expand Down Expand Up @@ -150,35 +155,14 @@ Adapters types
Accessing the chatbot instance
-------------------------------

When ChatterBot initializes each adapter, it sets an attribute named :code:`chatbot`.
When ChatterBot initializes each adapter, it sets an attribute named ``chatbot``.
The chatbot variable makes it possible for each adapter to have access to all of the other adapters being used.
Suppose two input and output adapters need to share some information or perhaps you want to give your logic adapter
direct access to the storage adapter. These are just a few cases where this functionality is useful.

Each adapter can be accessed on the chatbot object from within an adapter by referencing `self.chatbot`.
Then, :code:`self.chatbot.storage` refers to the storage adapter, :code:`self.chatbot.input` refers to the input adapter,
:code:`self.chatbot.output` refers to the current output adapter, and :code:`self.chatbot.logic` refers to the logic adapters.

Adapter defaults
----------------

By default, ChatterBot uses the `SQLStorageAdapter` adapter for storage,
the `BestMatch` for logic, the `VariableInputTypeAdapter` for input
and the `OutputAdapter` for output.

Each adapter can be set by passing in the dot-notated import path to the constructor as shown.

.. code-block:: python

bot = ChatBot(
"Elsie",
storage_adapter="chatterbot.storage.SQLStorageAdapter",
input_adapter="chatterbot.input.VariableInputTypeAdapter",
output_adapter="chatterbot.output.OutputAdapter",
logic_adapters=[
"chatterbot.logic.BestMatch"
],
)
Then, ``self.chatbot.storage`` refers to the storage adapter, ``self.chatbot.input`` refers to the input adapter,
``self.chatbot.output`` refers to the current output adapter, and ``self.chatbot.logic`` refers to the logic adapters.

.. _MongoDB: https://docs.mongodb.com/
.. _`Python logging documentation`: https://docs.python.org/3/library/logging.html#logging-levels