Calculating the probability of a string