[FilterScript] [FS] Levenshtein distance - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Filterscripts (
https://sampforum.blast.hk/forumdisplay.php?fid=17)
+--- Thread: [FilterScript] [FS] Levenshtein distance (
/showthread.php?tid=66600)
[FS] Levenshtein distance -
[RP]Rav - 23.02.2009
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
Re: [FS] Levenshtein distance -
zyx - 25.02.2009
Very nice! Thanks for posting this.
Re: [FS] Levenshtein distance -
Norn - 25.02.2009
Interesting function.
Re: [FS] Levenshtein distance -
[AoA]RyDeR - 25.02.2009
Nice
Re: [FS] Levenshtein distance -
DMSOrg - 28.06.2009
Ooh, this is interesting! Good job!