import math


def compute_log_likelihood(document, expected_letter_distribution):
	"""
	Computes the log-likelihood of a document

	Inputs
	------
	document : a string, of which, we compute the likelihood

	expected_letter_distribution : a dictionary of Distribution objects (inherited from dict - see util) where each 
									key is a letter, and each key of each Distribution object is also a letter; the
									value is the probablity of transitioning between letters, 
									i.e. d[first_letter][second_letter] = Probability of first_letter -> second_letter

	Returns
	-------
	a double which is the log-likelihood of the document	
	"""
	s = 0

	for i in range(1, len(document)):
		first_letter = document[i-1].lower() if document[i-1].isalpha() else " "
		second_letter = document[i].lower() if document[i].isalpha() else " "
		s += math.log(expected_letter_distribution[first_letter][second_letter])

	return s