pythonpython-3.xautocorrect

Autocorrect python library throwing error instead of correcting the word


I'm not really sure why this autocorrect isnt working, but every time i try to use the Speller() function i get this error:

TypeError: '>' not supported between instances of 'str' and 'int'

and here is my code:

import time
from autocorrect import Speller

def main(consoleMode):
    if consoleMode:
        # beg fur input :D
        inputVar = input("Console Mode input: ")
        if Speller(inputVar.lower()) == "hi" or Speller(inputVar.lower()) == "hello" or Speller(inputVar.lower()) == "wassup" or Speller(inputVar.lower()) == "sup":
            if name == None:
                name = int(input("Hello!\nI'd like to get to know you.\nWhat's your name?\n> "))
                if ("not" in Speller(name) and "tell" in Speller(name)) or ("not" in Speller(name) and "say" in Speller(name)):
                    print("Alright, I'll just call you Bob for now :)")
                    name = "Bob"
            else:
                print("Hey " + name + "!")
while True:
    main(True)

edit: I also tried doing int(disisastringvariable) but it just doesnt even work as it also throws an error


Solution

  • you might want to check out the documentation for the autocorrect module the speller class inits signature is def __init__(self, threshold=0, lang='en'): So when creating an instance of the class and passing in a single argument it will assume you are passing in a threshold.

    So calling Speller("something") will pass a string in that will be stored as the threshold. then on line 27 of the init method. if threshold > 0 this string will be compared to an int. Hence the error. Since you cannot do > between a string and an int.

    I would suggest first read any documentation for this module. The example from the documenation suggest to use it like

    >>> spell = Speller(lang='en')
    >>> spell("I'm not sleapy and tehre is no place I'm giong to.")
    "I'm not sleepy and there is no place I'm going to."