finished the sentence distance calculate function