Lab 1 - Introduction To Python
Lab 1 - Introduction To Python
Date: 15-09-2023
Mahad Mohtashim
379889
BSCS-11-C
Page 1
Task #1
Write down a python program which takes two strings as input and calculate the
Levenshtein/Edit distance between the two strings.
Explanation:-
Insertion
Deletion
Substitution
Mathematically:-
Mathematically Levenshtein/Edit distance between two strings ‘a’ and ‘b’ is defined as:-
For further understanding of the formula you may read this blog as it explains it in great depth
or you may get back to me wherever/whenever you stuck.
https://medium.com/@ethannam/understanding-the-levenshtein-distance-equation-for-beginners-
c4285a5604f0
Page 2
But it does not explain how to count the edit operations while calculating overall Levenshtein
distance.
Task #2
Now modify the above written program in such a way that it takes two text files containing
single- line and lowercase English sentences named as reference.txt and hypothesis.txt, and
outputs the file result.txt containing Levenshtein distance of these two files as below. The
distance should be word level and not character level.
Page 3
**********reference.txt***************
this is some text and we would like to see if it has been identified correctly by speech recognition system
***************************************
**********hypothesis.txt*************
this is a text and we would like to check what has been identified by the speech recognition
***************************************
*********result.txt*******************
Levenshtein distance is 7
Insertions 1
Deletions 3
Substitutions 3
***************************************
Hint:-
Task #3
Now modify the above program so that it ignores 10 common words in such a way:-
Page 4
*********result2.txt*******************
Levenshtein distance is 5
Insertions 0
Deletions 3
Substitutions 2
***************************************
Submission Guidelines:-
Page 5