Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- def main():
- args = sys.argv[1:]
- if len(args) != 1:
- sys.err.write("Expecting a single argument, got {!r}\n".format(args))
- sys.exit(1)
- input_file = args[0]
- # Read file into a string
- f = open(input_file, 'r')
- contents = open(input_file, 'r').read()
- print(contents)
- # Split file into words
- def word_array(contents):
- words = []
- i = 0
- start_word_index = -1
- while True:
- if i >= len(contents):
- break
- curr_is_space = contents[i] == ' ' and (contents[i-1] != '.') and (contents[i-1] != ',') and (contents[i-1] != '!') and (contents[i-1] != '?')
- curr_is_letter = (contents[i] != ' ') and (contents[i] != '.') and (contents[i] != ',') and (contents[i] != '!') and (contents[i] != '?')
- curr_is_puncuation = (contents[i] == '.') or (contents[i] == ',') or (contents[i] == '!') or (contents[i] == '?')
- if curr_is_letter and start_word_index == -1:
- start_word_index = i
- elif curr_is_space and start_word_index != -1:
- words.append(contents[start_word_index:i])
- start_word_index = -1
- elif curr_is_puncuation and start_word_index != -1:
- words.append(contents[start_word_index:(i)])
- start_word_index = -1
- i = i + 1
- if start_word_index != -1:
- words.append(contents[start_word_index:])
- return words
- # Calculate frequencies
- # Generate new sentences
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement