Hi all, I found the Levenshtein distance calculation and I tried to embed this in an app, but when I use it, I get an error.
But I don't understand where it comes from.
Can anyone take a look at this?
thanks
gert
Professional Software Development Tools
Hi all, I found the Levenshtein distance calculation and I tried to embed this in an app, but when I use it, I get an error.
But I don't understand where it comes from.
Can anyone take a look at this?
thanks
gert
I don't know where did you take this code from or what programming language were going to use but I didn't saw anything like this before, in AMS:
By watching the for loop syntax, it seems to be something like C/C++ (or else, I don't know). Give us the original code and we may help you porting the code in AMS. As actually is your function, I can't understand almost anything..Code:function levenshtein(string1, string2) local str1, str2, distance = {}, {}, {}; str1.len, str2.len = string.len(string1), string.len(string2); string.gsub(string1, "(.)", function(s) table.insert(str1, s); end); string.gsub(string2, "(.)", function(s) table.insert(str2, s); end); for i = 0, str1.len do distance[i][0] = i; end for i = 0, str2.len do distance[0][i] = i; end for i = 1, str1.len do for j = 1, str2.len do local tmpdist = 1; if(str1[i-1] == str2[j-1]) then tmpdist = 0; end distance[i][j] = math.min( distance[i-1][j] + 1, distance[i][j-1]+1, distance[i-1][j-1] + tmpdist); end end return distance[str1.len][str2.len]; end
He, thanks for reacting.
An example of an implementation is on
http://www.miislita.com/searchito/le...-distance.html
Take a look at this to see what the code should do.
There is a lot of examples, code written in different languages on
http://en.wikibooks.org/wiki/Algorit...htein_distance
This code however came from:
http://www.freemedialibrary.com/inde...n_distance#Lua
I hope you can help me.
thanks
gert
The code you've tried to embed is pure lua wich it's not really AMS's programming language, it has been modified a little in AMS.
I'll give a look to other languages and I'll try to recode the function as soon as I can.
EDIT
Hey, there is the JavaScript code.. you can use AMSWaves's Script plugin to execute javascript code:
http://www.indigorose.com/forums/showthread.php?t=25004
Last edited by T3STY; 02-28-2010 at 10:11 AM.
I want this in AMS.
http://www.lua.org/manual/5.1/manual.html#5.9
I tried to install amswscript, but I always get the message attached.
I copied the folder AMSWScript (including the file AMSWScript.lmd)
to C:\Program Files\AutoPlay Media Studio 7.0\Plugins\Actions
For what I want to do, I also think this script-detour will be too slow.
I would appreciate a LUA solution for sure.
thanks
gert
That function was missing some subtable declarations. This works good.
Code:function levenshtein(string1, string2) local str1, str2, distance = {}, {}, {}; str1.len, str2.len = string.len(string1), string.len(string2); string.gsub(string1, "(.)", function(s) table.insert(str1, s); end); string.gsub(string2, "(.)", function(s) table.insert(str2, s); end); for i = 0, str1.len do distance[i] = {} distance[i][0] = i; end distance[0] = {} for i = 0, str2.len do distance[0][i] = i; end for i = 1, str1.len do for j = 1, str2.len do local tmpdist = 1; if(str1[i-1] == str2[j-1]) then tmpdist = 0; end distance[i][j] = math.min( distance[i-1][j] + 1, distance[i][j-1]+1, distance[i-1][j-1] + tmpdist); end end return distance[str1.len][str2.len]; end
Dermot
I am so out of here
Dermot, I don't know how I can thank you!
This is wonderful!
thanks
gert
Hey, why is this working ??!(..)
for i = 0, str2.len do
distance[0][i] = i;
end
(..)
I tried lots of times to make for loops like this and it never worked, also the script editor were telling something like "unknown value (or something) in for... do".