Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. def Analyze(Text):
  2. notvocab = []
  3. words = {}
  4. invocab = 0
  5. for i in Text:
  6. if i not in words.keys():
  7. words[i] = 1
  8. else:
  9. words[i] += 1
  10. print("Unique words: {}".format(len(words.keys())))
  11. print("All words: {}".format(sum(words.values())))
  12. for i in words.keys():
  13. if i in vocab.keys():
  14. invocab += 1
  15. else:
  16. notvocab.append(i)
  17. print("Words in vocab: {}".format(invocab))
  18. print("Words not in vocab: {}\n".format(len(notvocab)))
  19. return notvocab
  20.  
  21. #start
  22. task = open("brain262.txt").read().lower()
  23. signs = ['!', '?', ',', ';', '.', ':', '«', '(', ')', '»']
  24. for i in signs:
  25. task = task.replace(i, '')
  26.  
  27.  
  28. task = open("brain309.txt").read().lower()
  29. dicty = open("dict1.txt").read().strip().split("\n")
  30. vocab = {}
  31. for i in diction:
  32. temp = i.split()
  33. key = temp[0]
  34. value = int(temp[1])
  35. vocab[key] = value
  36. Signs = ['!', '?', ',', ';', '.', ':', '«', '(', ')', '»']
  37. for i in Signs:
  38. task = task.replace(i, '')
  39. task = task.split()
  40. print("Analyze before correcting: \n")
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47. NewDictionary = Calculation(task) #analyze for 2 task
  48. CorrectText = [] #our corrected result text
  49. print("Searching mistakes...\n")
  50. for i in NewDictionary:
  51. PossibleErrors = []
  52. ReplacementsFromDictionary = []
  53. for j in vocab.keys():
  54. PossibleErrors.append((j, RedactorDistance(i, j)))
  55. PossibleErrors = sorted(PossibleErrors, key=lambda x: x[1])
  56. ReplacementsFromDictionary.append(PossibleErrors[0][0])
  57. MinRedactorDistance = PossibleErrors[0][1]
  58. CorrectText.append((i, ReplacementsFromDictionary[0],
  59. MinRedactorDistance))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement