How to use the chatterbot.logic.LogicAdapter function in ChatterBot

To help you get started, we’ve selected a few ChatterBot examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gunthercox / ChatterBot / tests / logic_adapter_tests / test_multi_adapter.py View on Github external
from tests.base_case import ChatBotTestCase
from chatterbot.conversation import Statement
from chatterbot.logic import LogicAdapter
from chatterbot.logic import MultiLogicAdapter


class TestAdapterA(LogicAdapter):

    def process(self, statement):
        response = Statement('Good morning.')
        response.confidence = 0.2
        return response


class TestAdapterB(LogicAdapter):

    def process(self, statement):
        response = Statement('Good morning.')
        response.confidence = 0.5
        return response


class TestAdapterC(LogicAdapter):
github gunthercox / ChatterBot / tests / logic_adapter_tests / test_multi_adapter.py View on Github external
from tests.base_case import ChatBotTestCase
from chatterbot.conversation import Statement
from chatterbot.logic import LogicAdapter
from chatterbot.logic import MultiLogicAdapter


class TestAdapterA(LogicAdapter):

    def process(self, statement):
        response = Statement('Good morning.')
        response.confidence = 0.2
        return response


class TestAdapterB(LogicAdapter):

    def process(self, statement):
        response = Statement('Good morning.')
        response.confidence = 0.5
        return response


class TestAdapterC(LogicAdapter):

    def process(self, statement):
        response = Statement('Good night.')
        response.confidence = 0.7
        return response


class MultiLogicAdapterTestCase(ChatBotTestCase):
github gunthercox / ChatterBot / tests / test_chatbot.py View on Github external
Statement('Another example.'),
            Statement('Example B for search.'),
            Statement(text='Another statement.'),
        ])

        results = list(self.chatbot.storage.filter(
            search_text=self.chatbot.storage.tagger.get_text_index_string(
                'Example A for search.'
            )
        ))

        self.assertEqual(len(results), 1)
        self.assertEqual('Example A for search.', results[0].text)


class TestAdapterA(LogicAdapter):

    def process(self, statement, additional_response_selection_parameters=None):
        response = Statement(text='Good morning.')
        response.confidence = 0.2
        return response


class TestAdapterB(LogicAdapter):

    def process(self, statement, additional_response_selection_parameters=None):
        response = Statement(text='Good morning.')
        response.confidence = 0.5
        return response


class TestAdapterC(LogicAdapter):
github gunthercox / ChatterBot / tests / logic / test_logic_adapter.py View on Github external
def setUp(self):
        super().setUp()
        self.adapter = LogicAdapter(self.chatbot)
github gunthercox / ChatterBot / tests / test_chatbot.py View on Github external
)
        ))

        self.assertEqual(len(results), 1)
        self.assertEqual('Example A for search.', results[0].text)


class TestAdapterA(LogicAdapter):

    def process(self, statement, additional_response_selection_parameters=None):
        response = Statement(text='Good morning.')
        response.confidence = 0.2
        return response


class TestAdapterB(LogicAdapter):

    def process(self, statement, additional_response_selection_parameters=None):
        response = Statement(text='Good morning.')
        response.confidence = 0.5
        return response


class TestAdapterC(LogicAdapter):

    def process(self, statement, additional_response_selection_parameters=None):
        response = Statement(text='Good night.')
        response.confidence = 0.7
        return response


class ChatBotLogicAdapterTestCase(ChatBotTestCase):
github gunthercox / ChatterBot / chatterbot / logic / low_confidence.py View on Github external
from chatterbot.conversation import Statement
from chatterbot.logic import LogicAdapter


class LowConfidenceAdapter(LogicAdapter):
    """
    Returns a default response with a high confidence
    when a high confidence response is not known.

    :param threshold:
          The low confidence value that triggers this adapter.
          Defaults to 0.65.
    :type threshold: float

    :param default_response:
          The response returned by this logic adaper.
    :type default_response: str or list or tuple

    :param response_selection_method:
          The a response selection method.
          Defaults to ``get_first_response``
github gunthercox / ChatterBot / chatterbot / logic / best_match.py View on Github external
from chatterbot.logic import LogicAdapter
from chatterbot import filters


class BestMatch(LogicAdapter):
    """
    A logic adapter that returns a response based on known responses to
    the closest matches to the input statement.

    :param excluded_words:
        The excluded_words parameter allows a list of words to be set that will
        prevent the logic adapter from returning statements that have text
        containing any of those words. This can be useful for preventing your
        chat bot from saying swears when it is being demonstrated in front of
        an audience.
        Defaults to None
    :type excluded_words: list
    """

    def __init__(self, chatbot, **kwargs):
        super().__init__(chatbot, **kwargs)
github gunthercox / ChatterBot / chatterbot / logic / specific_response.py View on Github external
from chatterbot.logic import LogicAdapter


class SpecificResponseAdapter(LogicAdapter):
    """
    Return a specific response to a specific input.

    :kwargs:
        * *input_text* (``str``) --
          The input text that triggers this logic adapter.
        * *output_text* (``str``) --
          The output text returned by this logic adapter.
    """

    def __init__(self, chatbot, **kwargs):
        super().__init__(chatbot, **kwargs)
        from chatterbot.conversation import Statement

        self.input_text = kwargs.get('input_text')
github gunthercox / ChatterBot / chatterbot / logic / time_adapter.py View on Github external
from datetime import datetime
from chatterbot.logic import LogicAdapter
from chatterbot.conversation import Statement


class TimeLogicAdapter(LogicAdapter):
    """
    The TimeLogicAdapter returns the current time.

    :kwargs:
        * *positive* (``list``) --
          The time-related questions used to identify time questions.
          Defaults to a list of English sentences.
        * *negative* (``list``) --
          The non-time-related questions used to identify time questions.
          Defaults to a list of English sentences.
    """

    def __init__(self, chatbot, **kwargs):
        super().__init__(chatbot, **kwargs)
        from nltk import NaiveBayesClassifier
github gunthercox / ChatterBot / chatterbot / logic / no_knowledge_adapter.py View on Github external
from chatterbot.logic import LogicAdapter


class NoKnowledgeAdapter(LogicAdapter):
    """
    This is a system adapter that is automatically added
    to the list of logic adapters during initialization.
    This adapter is placed at the beginning of the list
    to be given the highest priority.
    """

    def process(self, statement):
        """
        If there are no known responses in the database,
        then a confidence of 1 should be returned with
        the input statement.
        Otherwise, a confidence of 0 should be returned.
        """

        if self.chatbot.storage.count():