Site icon Learn C++

AI Techs :: Minimum Edit Distance Method in Unicode Strings in C++

In the Artificial Intelligence Technology, mostly in the field of Natural Language Processing (NLP), Computer Linguistics and in other fields of Computer Science,  The Edit Distance Method is a way of quantifying how dissimilar two text far from each other in char comparison by counting the minimum number of operations required to transform one string into the other. Edit distances find applications in NLP where automatic spelling corrections can be determined. Determines candidate corrections for a misspelled word by selecting words from a dictionary that have a low distance to the word in question This method also used in In bioinformatics to quantify the similarity of DNA sequences, which can be viewed as strings of the letters A, C, G and T.

As described in Wikipedia, different types of edit distance methods allow different sets of string operations. For instance:

In The minimum edit distance method, for example between ‘intention’ word and ‘execution’ word can be visualized using their alignment and this alignment is a correspondence between substrings of the two sequences. In this method each operation has cost of 1 and in Levenshtein Distance method substitutions cost 2.

Mostly examples in C++ about minimum edit distance are written for char arrays, ASCII strings. This example is good to understand Minimum Edit Distance method.

In this post we modified this Minimum Edit Distance method to Unicode Strings for the C++ Builder.

Basically, we use two unicode strings (source and dest) in this method, and for these two string inputs,
• We define T[i][j] as the edit distance matrix between source[i] and dest[j] chars
• Here we compare all characters of source string and all characters of dest string
• The edit distance between source and dest is

[crayon-6622e98d7187e797189895/]

that we retun as an output of this function.

Here is the full Example of Minimum Edit Distance method,

[crayon-6622e98d71889986526515/]

We can use this function as given below,

[crayon-6622e98d7188c926280866/]

This distance will give us how far both words, if they match distance is equal to 0.

Get started building powerful apps with C++Builder!

Exit mobile version