Domanda

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.

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top