PDA

View Full Version : help required, small project.


4thstar
05-26-2006, 08:38 AM
hello.
I hope all is well.
I am looking for what may be a simple start to a program.
I would like 1 inputbox where i enter AMS program that creates a typo list from a given word or set of words.

theres a website here: http://web-professor.net/scripts/typo/
that offers a php script but if possible i would like to do the same thing in AMS.

theres also php source code but i havnt yet found this to work on my site.

its probably a simple solution , but i know little about php so converting the logic is beyond me at this time.

if anyone could advise.
Kind regards
carl

Brett
05-26-2006, 09:25 AM
From looking at the PHP code, it would not be hard at all to translate that into AMS60 script. I don't have time to do it right now myself, but I wouldn't be surprised if someone here takes up that challenge.

4thstar
05-26-2006, 09:34 AM
Many thanks.
well i am ok with other issues in AMS but its one of those things where from scratch i cant seem to get my head arround :)

I know nothing of php but do see that someone with a knowhow of AMS and PHP would be able to put the conversion accross with ease :)

I shall see what happens :)

Kind Regards
carl

Brett
05-26-2006, 04:55 PM
OK, I took up the challenge just to show that AMS can handle the same sorts of stuff as PHP. Look at the attached project. The functions are in the Globals. The code that triggers it is in the On Click event.

For those of you who don't want to download: (NOTE: I know the code could be cleaned up a lot - I wanted to do it quickly)

Global functions:


table_keyboard = {}
-- top row
table_keyboard['1'] = {'2', 'q'};
table_keyboard['2'] = {'1', 'q', 'w', '3'};
table_keyboard['3'] = {'2', 'w', 'e', '4'};
table_keyboard['4'] = {'3', 'e', 'r', '5'};
table_keyboard['5'] = {'4', 'r', 't', '6'};
table_keyboard['6'] = {'5', 't', 'y', '7'};
table_keyboard['7'] = {'6', 'y', 'u', '8'};
table_keyboard['8'] = {'7', 'u', 'i', '9'};
table_keyboard['9'] = {'8', 'i', 'o', '0'};
table_keyboard['0'] = {'9', 'o', 'p', '-'};
table_keyboard['-'] = {'0', 'p'};
-- 2nd from top
table_keyboard['q'] = {'1', '2', 'w', 'a'};
table_keyboard['w'] = {'q', 'a', 's', 'e', '3', '2'};
table_keyboard['e'] = {'w', 's', 'd', 'r', '4', '3'};
table_keyboard['r'] = {'e', 'd', 'f', 't', '5', '4'};
table_keyboard['t'] = {'r', 'f', 'g', 'y', '6', '5'};
table_keyboard['y'] = {'t', 'g', 'h', 'u', '7', '6'};
table_keyboard['u'] = {'y', 'h', 'j', 'i', '8', '7'};
table_keyboard['i'] = {'u', 'j', 'k', 'o', '9', '8'};
table_keyboard['o'] = {'i', 'k', 'l', 'p', '0', '9'};
table_keyboard['p'] = {'o', 'l', '-', '0'};
-- home row
table_keyboard['a'] = {'z', 's' , 'w', 'q'};
table_keyboard['s'] = {'a', 'z', 'x', 'd', 'e', 'w'};
table_keyboard['d'] = {'s', 'x', 'c', 'f', 'r', 'e'};
table_keyboard['f'] = {'d', 'c', 'v', 'g', 't', 'r'};
table_keyboard['g'] = {'f', 'v', 'b', 'h', 'y', 't'};
table_keyboard['h'] = {'g', 'b', 'n', 'j', 'u', 'y'};
table_keyboard['j'] = {'h', 'n', 'm', 'k', 'i', 'u'};
table_keyboard['k'] = {'j', 'm', 'l', 'o', 'i'};
table_keyboard['l'] = {'k', 'p', 'o'};
-- bottom row
table_keyboard['z'] = {'x', 's', 'a'};
table_keyboard['x'] = {'z', 'c', 'd', 's'};
table_keyboard['c'] = {'x', 'v', 'f', 'd'};
table_keyboard['v'] = {'c', 'b', 'g', 'f'};
table_keyboard['b'] = {'v', 'n', 'h', 'g'};
table_keyboard['n'] = {'b', 'm', 'j', 'h'};
table_keyboard['m'] = {'n', 'k', 'j'};

function StringToTable(inputstring)
local tblReturn = {};

local length = String.Length(inputstring);

for i = 1, length do
tblReturn[i] = String.Mid(inputstring,i,1);
end

return tblReturn;
end

function TableToString(tableinput)
local strReturn = "";

for i, letter in tableinput do
strReturn = strReturn..letter;
end

return strReturn;
end

-- accepts a string
-- returns array of likely single "wrong key" typos
-- arrays contain only characters that are valid domain names
function getWrongKeyTypos( word )
word = String.Lower(word);
typos = {};
typos_index = 1;
length = String.Length( word );
-- check each character
for i = 1, length do
-- if character has replacements then create all replacements
char = String.Mid(word,i,1);
if( table_keyboard[char] ) then
for index, letter in table_keyboard[char] do
scratch = String.Left(word,i-1);
scratch = scratch..letter;
scratch = scratch..String.Right(word,length-i);

typos[typos_index] = scratch;
typos_index = typos_index + 1;
end
end -- if
end -- for

return typos;
end

-- accepts a string
-- returns array of likely single missed character typos
-- arrays contain only characters that are valid domain names
function getMissedCharTypos( word )
word = String.Lower(word);
typos = {};
typos_index = 1;
length = String.Length( word );

-- check each character
for i = 1, length do
local tempWord = String.Left(word,i-1);
tempWord = tempWord..String.Right(word,length-i);

typos[typos_index] = tempWord;
typos_index = typos_index + 1;
end

return typos;
end

-- accepts a string
-- returns array of likely transposed character typos
-- arrays contain only characters that are valid domain names
function getTransposedCharTypos( word )
word = String.Lower(word);
typos = {};
typos_index = 1;
length = String.Length( word );
-- check each character
for i = 1, length do
if( i ~= length )then
local tblWord = StringToTable(word);
local tempChar = tblWord[i];

tblWord[i] = tblWord[i+1];
tblWord[i+1] = tempChar;

local tempWord = TableToString(tblWord);

typos[typos_index] = tempWord;
typos_index = typos_index + 1;
end
end

return typos;
end

-- accepts a string
-- returns array of likely double entered character typos
-- arrays contain only characters that are valid domain names
function getDoubleCharTypos( word )
word = String.Lower(word);
typos = {};
typos_index = 1;
length = String.Length( word );

-- check each character
for i = 1, length do

local char = String.Mid(word,i,1);
local tempWord = String.Left(word,i);
tempWord = tempWord..char;
tempWord = tempWord..String.Right(word,length-i);

typos[typos_index] = tempWord;
typos_index = typos_index + 1;
end

return typos;
end


In the On Click of the button:




Input.SetText("Output","");

local strOutput = "";
local strTheWord = Input.GetText("Word");

-- Wrong Keystrike
strOutput = strOutput.."Wrong Keystrike:\r\n\r\n";
tblTypos = getWrongKeyTypos(strTheWord);
if(tblTypos)then
for i,word in tblTypos do
strOutput = strOutput..word;
strOutput = strOutput.."\r\n";
end
end

-- Missed Characters
strOutput = strOutput.."\r\nMissed Characters:\r\n\r\n";
tblTypos = getMissedCharTypos(strTheWord);
if(tblTypos)then
for i,word in tblTypos do
strOutput = strOutput..word;
strOutput = strOutput.."\r\n";
end
end

-- Single Transposed
strOutput = strOutput.."\r\nSingle Transposed Character:\r\n\r\n";
tblTypos = getTransposedCharTypos(strTheWord);
if(tblTypos)then
for i,word in tblTypos do
strOutput = strOutput..word;
strOutput = strOutput.."\r\n";
end
end

-- Double Character
strOutput = strOutput.."\r\nDouble Character:\r\n\r\n";
tblTypos = getDoubleCharTypos(strTheWord);
if(tblTypos)then
for i,word in tblTypos do
strOutput = strOutput..word;
strOutput = strOutput.."\r\n";
end
end


Input.SetText("Output",strOutput);

4thstar
05-27-2006, 04:20 AM
Hey Bret.
Many thanks for your time on this , I think i have a mind block when it comes to php so get lost in it before i even start :)

The example you have given is fantastic for me :)

Many thanks
Kind Regards
Carl