Advertisement
Guest User

Untitled

a guest
Feb 28th, 2020
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. import sys
  2.  
  3. def main():
  4. args = sys.argv[1:]
  5. if len(args) != 1:
  6. sys.err.write("Expecting a single argument, got {!r}\n".format(args))
  7. sys.exit(1)
  8.  
  9. input_file = args[0]
  10.  
  11. # Read file into a string
  12. f = open(input_file, 'r')
  13. contents = open(input_file, 'r').read()
  14. print(contents)
  15.  
  16. # Split file into words
  17. def word_array(contents):
  18. words = []
  19. i = 0
  20. start_word_index = -1
  21. while True:
  22. if i >= len(contents):
  23. break
  24. curr_is_space = contents[i] == ' ' and (contents[i-1] != '.') and (contents[i-1] != ',') and (contents[i-1] != '!') and (contents[i-1] != '?')
  25. curr_is_letter = (contents[i] != ' ') and (contents[i] != '.') and (contents[i] != ',') and (contents[i] != '!') and (contents[i] != '?')
  26. curr_is_puncuation = (contents[i] == '.') or (contents[i] == ',') or (contents[i] == '!') or (contents[i] == '?')
  27. if curr_is_letter and start_word_index == -1:
  28. start_word_index = i
  29. elif curr_is_space and start_word_index != -1:
  30. words.append(contents[start_word_index:i])
  31. start_word_index = -1
  32. elif curr_is_puncuation and start_word_index != -1:
  33. words.append(contents[start_word_index:(i)])
  34. start_word_index = -1
  35. i = i + 1
  36.  
  37. if start_word_index != -1:
  38. words.append(contents[start_word_index:])
  39. return words
  40. # Calculate frequencies
  41.  
  42. # Generate new sentences
  43.  
  44. if __name__ == '__main__':
  45. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement