[alicebot-archcomm] <srai> stack

Dr. Rich Wallace alicebot-archcomm@list.alicebot.org
Sat, 1 Mar 2003 17:43:47 +0100 (CET)


Program M says the stars are fixed at every level of recursion.  A local
variable "environ", saved on the stack, stores the binding environment for
the stars at each call to Srai().


--- Srai:- "symbolic reduction" in AIML, also known as "syntactic rewrite",
--- "simple recursion", "stimulus-response" or "synonym resolution."

proc Srai(x, environ);
  [client, stars, matchpath, depth] := environ;
  topic := Normalize(Predicates(client, 'topic'));
  thats := Predicates(client, 'thats');
  if thats(1) /= om and #thats(1) > 0 then
    that := Normalize(thats(1)(#thats(1)));
  else that := 'Undefined';
  end if;
  x := Response(environ, x);
  x := Normalize(x);
  if x = om or x = '' then return ['You said nothing','']; end if;
  input := x;
  path := split(x+" that "+that+" topic "+topic, ' ');
  stars := [];
  matchpath := '';
  result := [template, stars, matchpath];
  Matchai(ROOT, path, 1, result);
  [template, stars, matchpath] := result;
  environ :=  [client, stars, matchpath, depth+1];
  reply := Response(environ, template);
  if reply = '' then
    reply := 'I said nothing.';
  end if;
  reply ?:= 'I said OM.';
  reply := Formalize(reply);
  return [reply, matchpath];
end proc;


--- Response: top level AIML template evaluator.

proc Response(environ, remainder);
  [client, stars, matchpath, depth] := environ;
  prefix := '';
  if depth < DeepestDepth then
    environ :=  [client, stars, matchpath, depth+1];
    while remainder /= '' loop;
      remainder := Macroai(remainder); --- AIML Macro Substitutions
      [result, remainder] := Tagai(environ, remainder); -- Process tag.
      remainder :=  prefix + result + remainder; --- Recombine result.
      remainder := Trimai(remainder);
      prefix := span(remainder, templatechars); --- Advance to next '<'
    end loop;
  end if;
  return prefix;
end proc;

> Gary Dubuque wrote:
>>
>> Implementation orientated, do stars nest through <srai> tags so when
>> you use them after </srai> they are from the current context and not
>> from the last match that took place, that is, not inherited?
>>
> Should be!
>
> Please see
> http://list.alicebot.org/pipermail/alicebot-general/2002-December/007189.html
>
> It has been fixed for ProgramD - look around near this thread:
> http://list.alicebot.org/pipermail/alicebot-general/2002-December/007161.html
> (the zip-links are invalid).
>
> The next release of ProgramV will be fixed too.
>
> Ernest
>
> --
>               ProgramV - Alice on Perl - available at
>                http://www.virtualitas.net/perl/aiml/
>
>       VIRTUALITAS - Manufacturer of fine OOPPS - since 1996
> ********************************************************************* *
> VIRTUALITAS Inc.               *      http://www.virtualitas.net  * *
>                             *                                  * *
> European Consultant Office     *                                  * *
> Internationales Handelszentrum *                                  * *
> Friedrichstraße 95             *   contact:Ernest Lergon          * *
> 10117 Berlin / Germany         *    mailto:Ernest@virtualitas.net *
> *********************************************************************
>       PGP-Fingerprint 6E6F DC17 A886 342D  D63F 7880 12F5 6BA9
>         PGP-Key http://www.virtualitas.net/Ernest_Lergon.asc
>
> _______________________________________________
> alicebot-archcomm mailing list
> alicebot-archcomm@list.alicebot.org
> http://list.alicebot.org/mailman/listinfo/alicebot-archcomm


-- 
Dr. Rich
W A L L A C E
ALICE A.I. Foundation
drwallace@www.alicebot.org