SRL Archive - Test corner

Autoresponder


weequ

2010-01-17 05:24:04

program AutoResponder;


type
SubClass = record
Name: String;
Words: Array of String;
end;
MainClass = record
Name: String;
Words: Array of String;
SubClass: Array[0..10] of SubClass;
end;
WordRecord = record
MainClass: Array[0..10] of MainClass;
end;

//------------------------------------------------------------------------------

function ArrayInStr(Str: String; Arr: TStringArray): String;
var
I: Integer;
begin
for I := 0 to High(Arr) do
if Pos(LowerCase(Arr[I]), Str) > 0 then
Break;
if I <= High(Arr) then Result := Arr[I];
end;

//------------------------------------------------------------------------------

function ArraysInStr(Str: String; Arr: Array of TStringArray): Array of String;
var
I: Integer;
begin
SetLength(Result, Length(Arr));
for I := 0 to High(Arr) do
Result[I] := ArrayInStr(Str, Arr[I]);
end;

//------------------------------------------------------------------------------

function CombineStringArrays(Arr: Array of TStringArray): TStringArray;
var
I, II: Integer;
begin
for I := 0 to High(Arr) do
for II := 0 to High(Arr[I]) do
begin
SetArrayLength(Result, Length(Result)+1);
Result[High(result)] := Arr[I][II];
end;
end;

//------------------------------------------------------------------------------

function SearchClass(S: String): TStringArray;
begin
Result := [];
end;

//------------------------------------------------------------------------------

function DeclareWords: WordRecord;
begin
Result.MainClass[0].Name := 'questions';
Result.MainClass[0].Words := ['?', 'what', 'who', 'when', 'where', 'how', 'why'];

Result.MainClass[1].Name := 'greetings';
Result.MainClass[1].Words := ['hi', 'hello', 'hey'];


Result.MainClass[2].Name := 'funny';
Result.MainClass[2].Words := ['lol', 'lmao', 'rofl', 'haha'];


Result.MainClass[3].Name := 'smiles';
Result.MainClass[3].SubClass[0].Name := 'good';
Result.MainClass[3].SubClass[0].Words := [':)', ':D', ';)', '(:', 'xd', ':P'];
Result.MainClass[3].SubClass[1].Name := 'average';
Result.MainClass[3].SubClass[1].Words := [':/', ':o'];
Result.MainClass[3].SubClass[2].Name := 'bad';
Result.MainClass[3].SubClass[2].Words := [':(', ':S', ';(', '):', '-.-'];
Result.MainClass[3].Words := CombineStringArrays([Result.MainClass[3].SubClass[0].Words,
Result.MainClass[3].SubClass[1].Words, Result.MainClass[3].SubClass[2].Words]);


Result.MainClass[4].Name := 'persons';
Result.MainClass[4].SubClass[0].Name := 'good';
Result.MainClass[4].SubClass[0].Words := ['m8', 'mate'];
Result.MainClass[4].SubClass[1].Name := 'average';
Result.MainClass[4].SubClass[1].Words := ['dude'];
Result.MainClass[4].SubClass[2].Name := 'good';
Result.MainClass[4].SubClass[2].Words := ['noob', 'idiot', 'newbs'];
Result.MainClass[4].Words := CombineStringArrays([Result.MainClass[4].SubClass[0].Words,
Result.MainClass[4].SubClass[1].Words, Result.MainClass[4].SubClass[2].Words]);


Result.MainClass[5].Name := 'skills';
Result.MainClass[5].Words := ['agility', 'attack', 'construction', 'cooking', 'runecrafting',
'crafting', 'defence', 'farming', 'firemaking', 'fishing', 'fletching', 'herblore',
'hitpoints', 'hunter', 'magic', 'mining', 'prayer', 'ranged', 'slayer', 'smithing',
'strength', 'summoning', 'thieving', 'woodcutting'];
end;

//------------------------------------------------------------------------------

function FilledStringsInArray(Arr: TStringArray): Integer;
var
I: Integer;
begin
for I := 0 to High(Arr) do
if Arr[I] <> '' then Inc(Result);
end;

//------------------------------------------------------------------------------

function GetAnsver(Text: String): String;
var
Words: WordRecord;
begin
Words := DeclareWords;
Result := '';
end;

//------------------------------------------------------------------------------

begin
WriteLn(GetAnsver(':)'));
end.
It doesn't ansver to anything yet. Please comment and give suggestions.
Should I use variant arrays so I could add subsubsub classes etc..?

Gu3st...

2010-01-17 05:32:44

I knew you were making one! That's why I put Hello, Hi, Bye and cya into the array - explanation thingy ;)

Good job :)

Naum

2010-01-17 05:56:24

Looking good, you could use With..Do statements with your records. Furthermore, some of your procedures, afiak, are already in SRL for example ArrayInStr is already in SRL (Text.scar) as:

function ArrInStr(arrS: TStringArray; str: string): Boolean;

weequ

2010-01-17 06:14:01

Thanks Naum. Do statements sounds like a great idea.
My function results which string was found in the str instead of boolean.

Edit: Naum mind explaining how to use with..do? I never used with and I don't know how to use them in records :P

Sabzi

2010-01-17 06:48:46

I take the chance and explain it with an example.

with SubClass do
begin
Name := 'onioun';
Words := ['in', 'pui', 'poiu'];
end;
So you don't have to always type "SubClass.". I don't know other uses for with but there maybe some.

weequ

2010-01-17 07:19:53

Ty but is there any way to put array as a class type?

Now I have it like this:
function DeclareWords: WordRecord;
begin
with Result do
begin
MainClass[0].Name := 'questions';
MainClass[0].Words := ['?', 'what', 'who', 'when', 'where', 'how', 'why'];

MainClass[1].Name := 'greetings';
MainClass[1].Words := ['hi', 'hello', 'hey'];


MainClass[2].Name := 'funny';
MainClass[2].Words := ['lol', 'lmao', 'rofl', 'haha'];


MainClass[3].Name := 'smiles';
MainClass[3].SubClass[0].Name := 'good';
MainClass[3].SubClass[0].Words := [':)', ':D', ';)', '(:', 'xd', ':P'];
MainClass[3].SubClass[1].Name := 'average';
MainClass[3].SubClass[1].Words := [':/', ':o'];
MainClass[3].SubClass[2].Name := 'bad';
MainClass[3].SubClass[2].Words := [':(', ':S', ';(', '):', '-.-'];
MainClass[3].Words := CombineStringArrays([Result.MainClass[3].SubClass[0].Words,
MainClass[3].SubClass[1].Words, Result.MainClass[3].SubClass[2].Words]);


MainClass[4].Name := 'persons';
MainClass[4].SubClass[0].Name := 'good';
MainClass[4].SubClass[0].Words := ['m8', 'mate'];
MainClass[4].SubClass[1].Name := 'average';
MainClass[4].SubClass[1].Words := ['dude'];
MainClass[4].SubClass[2].Name := 'good';
MainClass[4].SubClass[2].Words := ['noob', 'idiot', 'newbs'];
MainClass[4].Words := CombineStringArrays([Result.MainClass[4].SubClass[0].Words,
MainClass[4].SubClass[1].Words, Result.MainClass[4].SubClass[2].Words]);


MainClass[5].Name := 'skills';
MainClass[5].Words := ['agility', 'attack', 'construction', 'cooking', 'runecrafting',
'crafting', 'defence', 'farming', 'firemaking', 'fishing', 'fletching', 'herblore',
'hitpoints', 'hunter', 'magic', 'mining', 'prayer', 'ranged', 'slayer', 'smithing',
'strength', 'summoning', 'thieving', 'woodcutting'];
end;
end;

Gu3st...

2010-01-17 07:46:16

Anything with dots (.) can be used with with…do
like players:

with Players[0] do
Name := 'Zyt3x';
Pass := 'nevergonnaletyoudown';
Nick := 'The Game. Oh, and you lost ;)';
Pin := '0101';
Loc := '... And so did I :(';
end;

for your proc:
with MainClass[1] do
Name := 'greetings';
Words := ['hi', 'hello', 'hey'];
end

weequ

2010-01-17 09:45:08

I know but i meaned like
with Players do
begin
[0].Name.....
end;

Gu3st...

2010-01-17 09:47:05

From: antti mies
I know but i meant like
with Players do
begin
[0].Name.....
end;
No, I don't think that's possible.. You can try but it would most likely return a compiling error

Sabzi

2010-01-17 12:20:43

From: antti mies
I know but i meaned like
with Players do
begin
[0].Name.....
end;


You can do that like:
with Players[0] do
begin
Name ...
end;
Often used in DeclarePlayers procedures.

weequ

2010-01-17 17:23:56

Yup but that doesn't make it any shorter in this case :(

Gu3st...

2010-01-17 17:34:27

From: antti mies
Yup but that doesn't make it any shorter in this case :(
It usually doesn't :p
It just looks cooler

I am making an AI Auto Responder, want to join me making it, antti? :)
You can find my msn by clicking that butterfly next to my location