Computation of Distances for Regular and Context-Free Probabilistic Languages