How to use the chatterbot.conversation.Response 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 / conversation_tests / test_utils.py View on Github external
def test_get_statements_with_known_responses(self):
        statement_list = [
            Statement("What... is your quest?"),
            Statement("This is a phone."),
            Statement("A what?", in_response_to=[Response("This is a phone.")]),
            Statement("A phone.", in_response_to=[Response("A what?")])
        ]

        responses = get_response_statements(statement_list)

        self.assertEqual(len(responses), 2)
        self.assertIn("This is a phone.", responses)
        self.assertIn("A what?", responses)
github gunthercox / ChatterBot / chatterbot / adapters / storage / twitter_storage.py View on Github external
def get_random(self, number=1):
        """
        Returns a random statement from the api.
        To generate a random tweet, search twitter for recent tweets
        containing the term 'random'. Then randomly select one tweet
        from the current set of tweets. Randomly choose one word from
        the selected random tweet, and make a second search request.
        Return one random tweet selected from the search results.
        """
        statements = []
        tweets = self.api.GetSearch(term="random", count=5)

        tweet = random.choice(tweets)
        base_response = Response(text=tweet.text)

        words = tweet.text.split()
        word = self.choose_word(words)

        # If a valid word is found, make a second search request
        # TODO: What if a word is not found?
        if word:
            tweets = self.api.GetSearch(term=word, count=number)
            if tweets:
                for tweet in tweets:
                    # TODO: Handle non-ascii characters properly
                    cleaned_text = ''.join(
                        [i if ord(i) < 128 else ' ' for i in tweet.text]
                    )
                    statements.append(
                        Statement(cleaned_text, in_response_to=[base_response])
github gunthercox / ChatterBot / chatterbot / storage / jsonfile.py View on Github external
def deserialize_responses(self, response_list):
        """
        Takes the list of response items and returns
        the list converted to Response objects.
        """
        proxy_statement = self.Statement('')

        for response in response_list:
            data = response.copy()
            text = data['text']
            del data['text']

            proxy_statement.add_response(
                Response(text, **data)
            )

        return proxy_statement.in_response_to
github gunthercox / ChatterBot / chatterbot / storage / mongodb.py View on Github external
def deserialize_responses(self, response_list):
        """
        Takes the list of response items and returns
        the list converted to Response objects.
        """
        proxy_statement = self.Statement('')

        for response in response_list:
            text = response['text']
            del response['text']

            proxy_statement.add_response(
                Response(text, **response)
            )

        return proxy_statement.in_response_to
github Surendhar95 / ChatBot / chatbot / chatbot / chatterbot / storage / mongodb.py View on Github external
def deserialize_responses(self, response_list):
        """
        Takes the list of response items and returns
        the list converted to Response objects.
        """
        proxy_statement = self.Statement('')

        for response in response_list:
            text = response['text']
            del response['text']

            proxy_statement.add_response(
                Response(text, **response)
            )

        return proxy_statement.in_response_to
github gunthercox / ChatterBot / chatterbot / adapters / storage / twitter_storage.py View on Github external
statement_text = kwargs.get('text')

        # if not statement_text:
        #    statement_text = kwargs.get('in_response_to__contains')
        # data['in_reply_to_status_id_str']

        # If no text parameter was given get a selection of recent tweets
        if not statement_text:
            statements = self.get_random(number=20)
            return statements

        tweets = self.api.GetSearch(term=statement_text)
        tweet = random.choice(tweets)

        statement = Statement(tweet.text, in_response_to=[
            Response(statement_text)
        ])

        return [statement]
github Surendhar95 / ChatBot / chatbot / chatbot / chatterbot / storage / jsonfile.py View on Github external
def deserialize_responses(self, response_list):
        """
        Takes the list of response items and returns
        the list converted to Response objects.
        """
        proxy_statement = self.Statement('')

        for response in response_list:
            data = response.copy()
            text = data['text']
            del data['text']

            proxy_statement.add_response(
                Response(text, **data)
            )

        return proxy_statement.in_response_to