[Python] Missing text attribute "python language, chatterbot library"

Discussão em 'Python' iniciado por Stack, Janeiro 23, 2025.

  1. Stack

    Stack Membro Participativo

    I'm working on a mathematic chatbot, and I have this python code:

    #this is the code that I wrote

    from chatterbot import ChatBot


    bot = ChatBot('Math', logic_adapters=[{'import_path':'chatterbot.logic.MathematicalEvaluation'}])


    while True:
    user_in = input()
    print("chatbot: ", bot.get_response(user_in))


    Which produces this error in the console:


    AttributeError: 'NoneType' object has no attribute 'text
    ​

    in reference to this line later in the code

    text=result.text


    here is full code:

    class ResultOption:
    def __init__(self, statement, count=1):
    self.statement = statement
    self.count = count


    # If multiple adapters agree on the same statement,
    # then that statement is more likely to be the correct response
    if len(results) >= 3:
    result_options = {}

    for result_option in results:
    result_string = result_option.text + ':' + (result_option.in_response_to or '')

    if result_string in result_options:
    result_options[result_string].count += 1
    if result_options[result_string].statement.confidence < result_option.confidence:
    result_options[result_string].statement = result_option
    else:
    result_options[result_string] = ResultOption(result_option)

    most_common = list(result_options.values())[0]

    for result_option in result_options.values():
    if result_option.count > most_common.count:
    most_common = result_option

    if most_common.count > 1:
    result = most_common.statement

    # Always the console says this
    response = Statement(
    # error is here !!
    text=result.text,
    in_response_to=input_statement.text,
    conversation=input_statement.conversation,
    persona='bot:' + self.name
    )

    response.confidence = result.confidence

    return response


    How can I fix this?

    Continue reading...

Compartilhe esta Página