forked from RohanMannem/ChatbotSteve
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
75 lines (63 loc) · 3.25 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import reader
import SteveControls
import spellCheck
if __name__ == "__main__":
"""Sample Inputs"""
# find a pig and five cats, kill two cows, and then walk and crouch, and finally feed a cow
# find forty-five cows and kill ninety-nine pigs and find forty cows
# kill three-million cats and one billion cows
# walk 5 and turn 2 and crouch then jump 6
while True:
commands = reader.Reader().getDict()
print(commands)
# read = dict(reader.Reader().getDict())
# if not bool(read):
# break
# print(read)
# Spell Checker Evaluation
def loopSpellChecker(listOfTypos, trueCommand):
spellChecker = spellCheck.spellCheck()
counter = 0
total = 0
for typoCommand in listOfTypos:
spellCheckedCommand = ""
commandSpellCheck = typoCommand.split(" ")
for i in range(0, len(commandSpellCheck) - 1):
if type(commandSpellCheck[i]) != int:
spellCheckedCommand += spellChecker.correction(commandSpellCheck[i]) + " "
if (commandSpellCheck[len(commandSpellCheck) - 1]):
spellCheckedCommand += spellChecker.correction(commandSpellCheck[len(commandSpellCheck) - 1])
if spellCheckedCommand == trueCommand:
counter += 1
total += 1
return (counter, total)
trueCommand = input("enter your command WITHOUT TYPOS: ")
trueCommand = trueCommand.lower()
command = trueCommand
letters = "abcdefghijklmnopqrstuvwxyz"
singleTypos = []
doubleTypos = []
for letter in letters:
for i in range(len(command)):
if command[i] != " " and command[i].isdigit() != True:
command = command[:i] + letter + command[i + 1:]
singleTypos.append(command)
command = trueCommand
for letter in letters:
for i in range(len(command)):
for j in range(len(command)):
if i != j and j > i:
if command[i] != " " and command[j] != " " and not command[j].isdigit() and not command[i].isdigit():
command = command[:i] + letter + command[i + 1:j] + letter + command[j + 1:]
doubleTypos.append(command)
command = trueCommand
if i != j and i > j:
if command[i] != " " and command[j] != " " and not command[j].isdigit() and not command[i].isdigit():
command = command[:j] + letter + command[j + 1:i] + letter + command[i + 1:]
doubleTypos.append(command)
command = trueCommand
singleAccuracy = loopSpellChecker(singleTypos, trueCommand)
print("One typo:", singleAccuracy, "=", singleAccuracy[0]/singleAccuracy[1])
doubleAccuracy = loopSpellChecker(doubleTypos, trueCommand)
print("Two typos:", doubleAccuracy, "=", doubleAccuracy[0]/doubleAccuracy[1])
print("Total accuracy:", (singleAccuracy[0] + doubleAccuracy[0])/(singleAccuracy[1] + doubleAccuracy[1]))