0

Alright I kind of understand how this is used in theory but how would I actually put it into a program because all the example I look at are not in a code I am not asking for a code writing out just a little hint to put me in the right direction so in the following example

#include<string>
#include< iostream>

using namespace std;

string User = " Hey how are you ";

int main()
{
 if( User == " how are you")
   { 
     cout << " Hello" << endl;
   }
  else
    {
     cout<< " unknown input" << endl;
    }
}

How would I put the Levenshtein distance into this program so where even though "hey" is infront of the rest the program will still read it as the correct input.

  • The wikipedia has code. And, those kitten/sitting, saturday/sunday matrices: you build such matrices using dynamic programming. – keyser May 04 '14 at 22:18
  • yeah it does have that but i mean it not really a good example in my book that can be run and compiled to better understand – Program master May 04 '14 at 22:38

1 Answers1

2

You can use the algorithm to determine the edit distance between the two strings and if that distance is less than a certain threshold you would consider it a match. The trick would be determining the threshold.

I have not played with this much, but one option that comes to mind is if the edit distance is less than a certain percentage of the length of the longest of the two strings, then consider that a match. Not very scientific, but a starting point for further research.

Chris Taylor
  • 52,623
  • 10
  • 78
  • 89
  • Right on. The "distance" is the number of discrete edits; to convert the OPs first string to the next is 5 edits (5 deletions, to be precise). I've played with this for a spell checker, and increasing the maximum allowed distance can result in some funny suggestions, way off target. – Jongware May 04 '14 at 22:33