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

is it possible to do math like calculations in chatterbot? #1331

Closed
swathy06 opened this issue Jun 19, 2018 · 10 comments
Closed

is it possible to do math like calculations in chatterbot? #1331

swathy06 opened this issue Jun 19, 2018 · 10 comments

Comments

@swathy06
Copy link

The user will input the number,the bot will do according to user and display response?

@gunthercox
Copy link
Owner

Yes, this is possible. You just need to add chatterbot.logic.MathematicalEvaluation to your chatbot's logic adapters.

http://chatterbot.readthedocs.io/en/stable/logic/#mathematical-evaluation-adapter

@swathy06
Copy link
Author

instead of calling mathematical adapter,can it be written in as a custom logic adapter,where the prompt from bot comes to input the number.Then user inputs the number and the calculation happens?

@gunthercox
Copy link
Owner

You are more than welcome to create your own logic adapters. The idea you are proposing definitely sounds like it would be possible to make.

@swathy06
Copy link
Author

I have created my own logic adapter,and integrated with flask. Instead of asking the values to user in python terminal,I want to ask in logic adapter to display through flask.Can you please help with this ?

@vkosuri
Copy link
Collaborator

vkosuri commented Jun 21, 2018

@swathy06 Are you looking this kind of implementation?

# -*- coding: utf-8 -*-
from chatterbot import ChatBot


# Create a new instance of a ChatBot
bot = ChatBot(
    'Exact Response Example Bot',
    storage_adapter='chatterbot.storage.SQLStorageAdapter',
    logic_adapters=[
        {
            'import_path': 'chatterbot.logic.BestMatch'
        },
        {
            'import_path': 'chatterbot.logic.SpecificResponseAdapter',
            'input_text': 'Help me!',
            'output_text': 'Ok, here is a link: http://chatterbot.rtfd.org'
        }
    ],
    trainer='chatterbot.trainers.ListTrainer'
)

# Get a response given the specific input
response = bot.get_response('Help me!')
print(response)

If not could you elaborate your question with an example?

@swathy06
Copy link
Author

swathy06 commented Jun 21, 2018

This is my custom logic adapter,

class MathLogicAdapter1(LogicAdapter):
	def can_process(self, statement):
		words = [ 'ADD']
		if all(x in statement.text.split() for x in words):
			return True
		else:
			return False
		
	def process(self, statement):
		
		from chatterbot.conversation import Statement

		user_input = statement.text.lower()

		if 'ADD' not in user_input:
			return 0, Statement('')
			
		else :
			w = float( input("enter the number"))
			h = float(input("enter the number"))
			m = ( (w )/(h*h))
			confidence = 1
			response_statement = Statement('Your sum is {}'.format(m))
			
			response_statement.confidence = confidence 	
			return response_statement

I want print statement of w and h to be displayed through flask and the value which user gives should be taken to do the calculation.Is it possible to do so?

@vkosuri
Copy link
Collaborator

vkosuri commented Jun 22, 2018

@swathy06 Are you trying to get inputs from flask? You may see this repo https://github.com/chamkank/flask-chatterbot

@swathy06
Copy link
Author

Yes,flask is working properly.
I want the prompt "enter the number" which is in logic adapter,to be shown in flask server.Presently it is displaying in python terminal.So that user can enter the number.Then take the number which the user has typed to do operation. Is it possible to do so?

@gunthercox
Copy link
Owner

@swathy06 Yes, that is possible. I'm going to close this ticket off since it's been a while and a number of changes have been made to ChatterBot. Feel free to open a new ticket if you have any further questions.

@lock
Copy link

lock bot commented Jul 12, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked and limited conversation to collaborators Jul 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants