[FilterScript] [FS] Levenshtein distance
#1

This is a simple filterscript that allows you to calculate the Levenshtein distance (or edit distance) between two strings.

Quote:
Originally Posted by Wikipedia
In information theory and computer science, the Levenshtein distance is a metric for measuring the amount of difference between two sequences (i.e., the so called edit distance). The Levenshtein distance between two strings is given by the minimum number of operations needed to transform one string into the other, where an operation is an insertion, deletion, or substitution of a single character. A generalization of the Levenshtein distance (Damerau–Levenshtein distance) allows the transposition of two characters as an operation.
1. kitten → sitten (substitution of 's' for 'k')
2. sitten → sittin (substitution of 'i' for 'e')
3. sittin → sitting (insert 'g' at the end).
It's quite easy to use, and the function can be copied & pasted in your main script as well, but ofcourse you're wondering what use it has.. well it can help you support typos in your server, which really is quite useless but I think the main goal is to stop advertisers, you can block certain words such as "server" or "come visit" quite easy, but when people mangle these up (ser-ver) or just use really bad english (serfer, coem visit), the Levenshtein distance may just come in handy; for example:

Код:
public OnPlayerText(playerid, text[])
{
   // ad block, use something to loop through all words in a sentence
   new distance = LevenshteinDistance("server",word);
   if (distance != -1 && distance <= 2) // it takes two or less operations to go to the word server
   {
      SendClientMessage(playerid, COLOUR_RED, "Please do not advertise here");
      return 0;
   }
   return 1;
}
I hope you find it somewhat useful

pastebin
.amx
.pwn
Reply
#2

Very nice! Thanks for posting this.
Reply
#3

Interesting function.
Reply
#4

Nice
Reply
#5

Ooh, this is interesting! Good job!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)