import os.path
import sys

fh = open('foo.txt')

bigram_ct = {}
word_ct = {}

total = 0
for line in fh:
    line = line.strip()
    words = line.split()
    prev_word = 'Start'
    for word in words:
        total += 1
        bigram = (prev_word, word)
        if word in word_ct:
            word_ct[word] += 1
        else:
            word_ct[word] = 1
        if bigram in bigram_ct:
            bigram_ct[bigram] += 1
        else:
            bigram_ct[bigram] = 1
        prev_word = word

fh.close()

bigram_prob = {}
unigram_prob = {}
f_total = float(total)

for word in word_ct:
    unigram_prob[word] = float(word_ct[word])/f_total
for bigram in bigram_ct:
    bigram_prob[bigram] = float(bigram_ct[bigram])/f_total
    

