Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def Analyze(Text):
- notvocab = []
- words = {}
- invocab = 0
- for i in Text:
- if i not in words.keys():
- words[i] = 1
- else:
- words[i] += 1
- print("Unique words: {}".format(len(words.keys())))
- print("All words: {}".format(sum(words.values())))
- for i in words.keys():
- if i in vocab.keys():
- invocab += 1
- else:
- notvocab.append(i)
- print("Words in vocab: {}".format(invocab))
- print("Words not in vocab: {}\n".format(len(notvocab)))
- return notvocab
- #start
- task = open("brain262.txt").read().lower()
- signs = ['!', '?', ',', ';', '.', ':', '«', '(', ')', '»']
- for i in signs:
- task = task.replace(i, '')
- task = open("brain309.txt").read().lower()
- dicty = open("dict1.txt").read().strip().split("\n")
- vocab = {}
- for i in diction:
- temp = i.split()
- key = temp[0]
- value = int(temp[1])
- vocab[key] = value
- Signs = ['!', '?', ',', ';', '.', ':', '«', '(', ')', '»']
- for i in Signs:
- task = task.replace(i, '')
- task = task.split()
- print("Analyze before correcting: \n")
- NewDictionary = Calculation(task) #analyze for 2 task
- CorrectText = [] #our corrected result text
- print("Searching mistakes...\n")
- for i in NewDictionary:
- PossibleErrors = []
- ReplacementsFromDictionary = []
- for j in vocab.keys():
- PossibleErrors.append((j, RedactorDistance(i, j)))
- PossibleErrors = sorted(PossibleErrors, key=lambda x: x[1])
- ReplacementsFromDictionary.append(PossibleErrors[0][0])
- MinRedactorDistance = PossibleErrors[0][1]
- CorrectText.append((i, ReplacementsFromDictionary[0],
- MinRedactorDistance))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement