On this page levenshtein(), I am using the example #1 with following variables:
// input misspelled word
$input = 'htc corporation';
// array of words to check against
$words = array('htc', 'Sprint Nextel', 'Sprint', 'banana', 'orange',
'radish', 'carrot', 'pea', 'bean');
Could someone please tell me why the expected result is carrot rather than htc? Thanks
Because the levenshtein distance from htc corporation
is 12 whereas the distance to carrot is only 11.
The levenshtein function calculates how many characters it has to add or replace to get to a certain word, and because htc corporation
has 12 extra characters than htc
it has to remove 12 to get to just htc
. To get to the word carrot
from htc corporation
it takes 11 changes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With