Context Final

new topic     » topic index » view thread      » older message » newer message

------=_NextPart_000_0043_01BFE179.1FCD3DA0
        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

After some thinking and studying, I say a major flaw in the algorithm of =
the previous Context, and also some design issues. Which is why I've =
reshaped the whole library. Here is the new improved include file. Its =
also a whole let better managed and cleaner code, its still as fast as I =
could make it. Also it should be pretty memory efficient, considering =
what its doing.

You can use it like you would use most other expert language tools. Use =
it for an RPG game, an advanced database, a help system, or any other =
place where abstract models, context-sensitive and relationship are the =
keywords or your programming problem.

The file is inserted below and because of that, I've chosen for HTML =
rather than a text message. No zip, no attachment.

Greetings,=20

Ralf N.
nieuwen at xs4all.nl

-------------------------------------------------------------------------=
-----------------
--
--     CONTEXT.E                                                 June =
2000
--     (c) By Ralf Nieuwenhuijsen                           USE AT OWN =
RISK
--
-------------------------------------------------------------------------=
-----------------
--
--     Offers context sensitive information management through the =
*formal* routines:
--
--          context c
--          query q, left, right
--
--          c =3D EMPTY
--
--          define ( c, left, right )
--          ask_query ( c, q )
--
--       However, you can also use the quick'n'dirty interface, where =
all strings are
--     parsed into chunks and stored in a seperate database, to save =
precious memory
--     space:
--
--          concept (prefix)
--            the (left) equals (right)
--            the (left) setto (some_value)
--          top_level ()
--
--          ask (query)
--
--       Prefix, query, left and right will be parsed. I.E. you can say =
things like:=20
--         =20
--          ask ("Application ProgramName")=20
--
-------------------------------------------------------------------------=
-----------------
-------------------------------------------------------------------------=
-----------------
-- Variables & Constants

  sequence
   l_rules, r_rules
  constant
   TRUE =3D 1, FALSE =3D 0
  global constant
   EMPTY =3D {{}, {}, FALSE}

  l_rules =3D {} r_rules =3D {}

-------------------------------------------------------------------------=
-----------------
-- Basic Types

  type code (atom x)
    return x >=3D 0 and x <=3D length( names )
  end type

  global type context (sequence s)
    return length(s) =3D 3 and length(s[1]) =3D length(s[2])
  end type

  global type query (sequence s)

    for index =3D 1 to length(s) do
      if not code (s[index]) then
        return FALSE
      end if
    end for

    return TRUE
  end type

-------------------------------------------------------------------------=
-----------------
-- Core Routines

  function new (query l, query r)
  integer pos

    pos =3D find (1, l_rules)
    if pos then
      r_rules[pos] =3D r
    else
      l_rules =3D append (l_rules, l)
      r_rules =3D append (r_rules, r)
      return length(l_rules)
    end if

    return pos
  end function

  function tree_straighten (context c, integer i, integer o)

    if c[3] !=3D o then
      return c
    end if
    c[3] =3D i

    for index =3D 1 to length(c[2]) do
      c[2][index] =3D tree_straighten (c[2][index], i, o)
    end for

    return c
  end function

  function store_rule (sequence c, integer i, integer index)
  sequence item
  integer pos

    item =3D l_rules[i]

    if index > length(item) then
      c =3D tree_straighten (c, i, c[3])
    else
      pos =3D find (item[index], c[1])
      if pos then
        c[2][pos] =3D store_rule (c[2][pos], i, index+1)
      else
        c[1] =3D append (c[1], l_rules[i][index])
        c[2] =3D append (c[2], store_rule (EMPTY, i, index+1))
      end if

    end if

    return c
  end function

  function match_rules (context c, query s)
  integer pos

    for index =3D 1 to length(s) do

      pos =3D find (s[index], c[1])
      if pos then
        c =3D c[2][pos]
      else
        return c[3]
      end if

    end for

    return c[3]
  end function

-------------------------------------------------------------------------=
-----------------
-- Exportable Routines

  global function define (context c, query l, query r)
  integer i

    i =3D new (l, r)
    return store_rule (c, i, 1)
  end function

  global function ask_query (context c, query s)
  sequence olds
  integer i

    i =3D NONE olds =3D {}
    while compare (olds, s) do
      olds =3D s
      i =3D match_rules (c, s)
      if i then
        s =3D r_rules[i] & s[length(l_rules[i])+1..length(s)]
      elsif length(s) > 1 then
        s =3D s[2..length(s)]
      end if
    end while

    return s
  end function

-------------------------------------------------------------------------=
-----------------
-- Quick'n'dirty Interface

  constant WHITESPACE =3D 13 & 10 & 255 & 32
  sequence prefix, knowledge, lquery, names
  prefix =3D {} knowledge =3D EMPTY names =3D {}

  type char (integer i)
    return i >=3D 0 and i < 256
  end type

  type string (sequence s)

    for index =3D 1 to length(s) do
      if not char( s[index] ) then
        return FALSE
      end if
    end for

    return TRUE
  end type

  function parse (sequence query)
  sequence ret
  integer start, flag

   flag =3D FALSE ret =3D {}
   for index =3D 1 to length(query) do
     if flag then
       if find (query[index], WHITESPACE) then
         ret =3D append(ret, query[start..index-1])
         flag =3D FALSE
       end if
     else
       if not find (query[index], WHITESPACE) then
         flag =3D TRUE
         start =3D index
       end if
     end if
   end for
   if flag then
     return append(ret, query[start..length(query)])
   else
     return ret
   end if
  end function

  function flatten (sequence s, object p)
  sequence result

   result =3D ""
   for index =3D 1 to length(s) - 1 do
     result &=3D s[index] & p
   end for

   if not length(s) then return "" end if

   return result & s[length(s)]
  end function

  function to_names (sequence x)

    for index =3D 1 to length(x) do
      x[index] =3D names[x[index]]
    end for

    return x
  end function

  function to_codes (sequence x)
  integer pos

    for index =3D 1 to length(x) do
      pos =3D find( x[index], names )
      if not pos then
        names =3D append( names, x[index] )
        pos =3D length( names )
      end if
      x[index] =3D pos
    end for

    return x
  end function

  global procedure concept (sequence s)
    prefix =3D to_codes ( parse (s) )
  end procedure

  global procedure top_level ()
    prefix =3D {}
  end procedure

  global procedure the (sequence s)
    lquery =3D to_codes ( parse (s) )
  end procedure

  global procedure equals (sequence s)
    s =3D to_codes ( parse (s) )
    knowledge =3D define (knowledge, lquery, s)
  end procedure

  global procedure setto (object x)
    x =3D to_codes ( {x} )
    knowledge =3D define (knowledge, lquery, x)
  end procedure

  global function ask (sequence s)
    return flatten(to_names (ask_query(knowledge, to_codes (parse(s))) =
), ' ')
  end function

---------------------------------------------------------------------

 Here the code ends! ..  Greetings, Ralf.





------=_NextPart_000_0043_01BFE179.1FCD3DA0
        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2314.1000" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=3DArial size=3D2>After some thinking and studying, I say =
a major=20
flaw in the algorithm of the previous Context, and also some design =
issues.=20
Which is why I've reshaped the whole library. Here is the new improved =
include=20
file. Its also a whole let better managed and cleaner code, its still as =
fast as=20
I could make it. Also it should be pretty memory efficient, considering=20
what&nbsp;its doing.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>You can use it like you would use most =
other expert=20
language tools. Use it for an RPG game, an advanced database, a help =
system, or=20
any other place where abstract models, context-sensitive and =
relationship are=20
the keywords or your programming problem.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>The file is inserted below and because =
of=20
that</FONT><FONT face=3DArial size=3D2>, I've chosen for HTML rather =
than a text=20
message. No zip, no attachment.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Greetings, </FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Ralf N.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2><A=20
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New"=20
nbsp;=20
June 2000<BR>--&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(c) By Ralf=20
&nbsp;&nbsp;&nbsp;&nbsp;=20
USE AT OWN=20
Offers context sensitive information management through the *formal*=20
p;=20
context c<BR>--&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
query q,=20
left, =
right<BR>--<BR>--&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
c=20
=3D =
EMPTY<BR>--<BR>--&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
define=20
( c, left, right =
ask_query ( c, q )<BR>--<BR>--&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
However, you=20
can also use the quick'n'dirty interface, where all strings=20
are<BR>--&nbsp;&nbsp;&nbsp;&nbsp; parsed into chunks and stored in a =
seperate=20
database, to save precious memory<BR>--&nbsp;&nbsp;&nbsp;&nbsp;=20
space:<BR>--<BR>--&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
concept=20
;&nbsp;=20
the (left) equals (right)</FONT></DIV>
<DIV><FONT face=3D"Courier New"=20
bsp;&nbsp;the=20
(left) setto=20
(some_value)<BR>--&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =

top_level =
ask (query)</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2>--</FONT></DIV>
<DIV><FONT face=3D"Courier New"=20
size=3D2>--&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Prefix, query, left =
and right=20
will be parsed. I.E. you can say things like: </FONT></DIV>
<DIV><FONT face=3D"Courier New"=20
size=3D2>--&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
</FONT></DIV>
<DIV><FONT face=3D"Courier New"=20
k=20
("Application ProgramName")=20
------------------------------------------------<BR>--=20
Variables &amp; Constants</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp; sequence<BR>&nbsp;&nbsp; =
l_rules,=20
r_rules<BR>&nbsp; constant<BR>&nbsp;&nbsp; TRUE =3D 1, FALSE =3D =
0<BR>&nbsp; global=20
constant<BR>&nbsp;&nbsp; EMPTY =3D {{}, {}, FALSE}</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp; l_rules =3D {} r_rules =
=3D=20
{}</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New"=20
--------------------------<BR>--=20
Basic Types</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp; type code (atom=20
x)<BR>&nbsp;&nbsp;&nbsp; return x &gt;=3D 0 and x &lt;=3D length( names =
)<BR>&nbsp;=20
end type</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp; global type context =
(sequence=20
s)<BR>&nbsp;&nbsp;&nbsp; return length(s) =3D 3 and length(s[1]) =3D=20
length(s[2])<BR>&nbsp; end type</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp; global type query =
(sequence=20
s)</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp;&nbsp;&nbsp; for index =
=3D 1 to=20
length(s) do<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if not code (s[index])=20
then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return=20
FALSE<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end if<BR>&nbsp;&nbsp;&nbsp; end =

for</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp;&nbsp;&nbsp; return =
TRUE<BR>&nbsp;=20
end type</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New"=20
--------------------------<BR>--=20
Core Routines</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp; function new (query l, =
query=20
r)<BR>&nbsp; integer pos</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp;&nbsp;&nbsp; pos =3D find =
(1,=20
l_rules)<BR>&nbsp;&nbsp;&nbsp; if pos =
then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
r_rules[pos] =3D r<BR>&nbsp;&nbsp;&nbsp; =
else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
l_rules =3D append (l_rules, l)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
r_rules =3D append=20
(r_rules, r)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return=20
length(l_rules)<BR>&nbsp;&nbsp;&nbsp; end if</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp;&nbsp;&nbsp; return =
pos<BR>&nbsp; end=20
function</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp; function tree_straighten =
(context c,=20
integer i, integer o)</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp;&nbsp;&nbsp; if c[3] !=3D =
o=20
then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return c<BR>&nbsp;&nbsp;&nbsp; =
end=20
if<BR>&nbsp;&nbsp;&nbsp; c[3] =3D i</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp;&nbsp;&nbsp; for index =
=3D 1 to=20
length(c[2]) do<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c[2][index] =3D =
tree_straighten=20
(c[2][index], i, o)<BR>&nbsp;&nbsp;&nbsp; end for</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp;&nbsp;&nbsp; return =
c<BR>&nbsp; end=20
function</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp; function store_rule =
(sequence c,=20
integer i, integer index)<BR>&nbsp; sequence item<BR>&nbsp; integer=20
pos</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp;&nbsp;&nbsp; item =3D=20
l_rules[i]</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp;&nbsp;&nbsp; if index =
&gt;=20
length(item) then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c =3D =
tree_straighten (c, i,=20
c[3])<BR>&nbsp;&nbsp;&nbsp; else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pos =
=3D find=20
(item[index], c[1])<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if pos=20
then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c[2][pos] =3D =
store_rule=20
(c[2][pos], i, index+1)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c[1] =3D append =
(c[1],=20
l_rules[i][index])<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c[2] =
=3D append=20
(c[2], store_rule (EMPTY, i, index+1))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
end=20
if</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp;&nbsp;&nbsp; end =
if</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp;&nbsp;&nbsp; return =
c<BR>&nbsp; end=20
function</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp; function match_rules =
(context c,=20
query s)<BR>&nbsp; integer pos</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp;&nbsp;&nbsp; for index =
=3D 1 to=20
length(s) do</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
pos =3D find=20
(s[index], c[1])<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if pos=20
then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c =3D=20
c[2][pos]<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return=20
c[3]<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end if</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp;&nbsp;&nbsp; end =
for</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp;&nbsp;&nbsp; return =
c[3]<BR>&nbsp;=20
end function</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New"=20
--------------------------<BR>--=20
Exportable Routines</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp; global function define =
(context c,=20
query l, query r)<BR>&nbsp; integer i</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp;&nbsp;&nbsp; i =3D new =
(l,=20
r)<BR>&nbsp;&nbsp;&nbsp; return store_rule (c, i, 1)<BR>&nbsp; end=20
function</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp; global function =
ask_query (context=20
c, query s)<BR>&nbsp; sequence olds<BR>&nbsp; integer i</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp;&nbsp;&nbsp; i =3D NONE =
olds =3D=20
{}<BR>&nbsp;&nbsp;&nbsp; while compare (olds, s)=20
do<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; olds =3D =
s<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
i =3D match_rules (c, s)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if i=20
then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; s =3D r_rules[i] =
&amp;=20
s[length(l_rules[i])+1..length(s)]<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
elsif=20
length(s) &gt; 1 then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; s =
=3D=20
s[2..length(s)]<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end =
if<BR>&nbsp;&nbsp;&nbsp;=20
end while</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp;&nbsp;&nbsp; return =
s<BR>&nbsp; end=20
function</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New"=20
--------------------------<BR>--=20
Quick'n'dirty Interface</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp; constant WHITESPACE =3D =
13 &amp; 10=20
&amp; 255 &amp; 32<BR>&nbsp; sequence prefix, knowledge, lquery, =
names<BR>&nbsp;=20
prefix =3D {} knowledge =3D EMPTY names =3D {}</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp; type char (integer=20
i)<BR>&nbsp;&nbsp;&nbsp; return i &gt;=3D 0 and i &lt; 256<BR>&nbsp; end =

type</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp; type string (sequence=20
s)</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp;&nbsp;&nbsp; for index =
=3D 1 to=20
length(s) do<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if not char( s[index] )=20
then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return=20
FALSE<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end if<BR>&nbsp;&nbsp;&nbsp; end =

for</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp;&nbsp;&nbsp; return =
TRUE<BR>&nbsp;=20
end type</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp; function parse (sequence =

query)<BR>&nbsp; sequence ret<BR>&nbsp; integer start, flag</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp;&nbsp; flag =3D FALSE ret =
=3D=20
{}<BR>&nbsp;&nbsp; for index =3D 1 to length(query) =
do<BR>&nbsp;&nbsp;&nbsp;&nbsp;=20
if flag then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if find =
(query[index],=20
WHITESPACE) then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ret =
=3D=20
append(ret,=20
; flag=20
=3D FALSE<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end=20
if<BR>&nbsp;&nbsp;&nbsp;&nbsp; =
else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if=20
not find (query[index], WHITESPACE)=20
then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; flag =3D=20
TRUE<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; start =3D=20
index<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end =
if<BR>&nbsp;&nbsp;&nbsp;&nbsp;=20
end if<BR>&nbsp;&nbsp; end for<BR>&nbsp;&nbsp; if flag=20
then<BR>&nbsp;&nbsp;&nbsp;&nbsp; return append(ret,=20
query[start..length(query)])<BR>&nbsp;&nbsp; =
else<BR>&nbsp;&nbsp;&nbsp;&nbsp;=20
return ret<BR>&nbsp;&nbsp; end if<BR>&nbsp; end function</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp; function flatten =
(sequence s, object=20
p)<BR>&nbsp; sequence result</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp;&nbsp; result =3D =
""<BR>&nbsp;&nbsp;=20
for index =3D 1 to length(s) - 1 do<BR>&nbsp;&nbsp;&nbsp;&nbsp; result =
&amp;=3D=20
s[index] &amp; p<BR>&nbsp;&nbsp; end for</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp;&nbsp; if not length(s) =
then return=20
"" end if</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp;&nbsp; return result =
&amp;=20
s[length(s)]<BR>&nbsp; end function</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp; function to_names =
(sequence=20
x)</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp;&nbsp;&nbsp; for index =
=3D 1 to=20
length(x) do<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; x[index] =3D=20
names[x[index]]<BR>&nbsp;&nbsp;&nbsp; end for</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp;&nbsp;&nbsp; return =
x<BR>&nbsp; end=20
function</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp; function to_codes =
(sequence=20
x)<BR>&nbsp; integer pos</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp;&nbsp;&nbsp; for index =
=3D 1 to=20
length(x) do<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pos =3D find( x[index], =
names=20
)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if not pos=20
then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; names =3D append( =
names,=20
x[index] )<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pos =3D length( =
names=20
)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end =
if<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
x[index] =3D pos<BR>&nbsp;&nbsp;&nbsp; end for</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp;&nbsp;&nbsp; return =
x<BR>&nbsp; end=20
function</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp; global procedure concept =
(sequence=20
s)<BR>&nbsp;&nbsp;&nbsp; prefix =3D to_codes ( parse (s) )<BR>&nbsp; end =

procedure</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp; global procedure =
top_level=20
()<BR>&nbsp;&nbsp;&nbsp; prefix =3D {}<BR>&nbsp; end =
procedure</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp; global procedure the =
(sequence=20
s)<BR>&nbsp;&nbsp;&nbsp; lquery =3D to_codes ( parse (s) )<BR>&nbsp; end =

procedure</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp; global procedure equals =
(sequence=20
s)<BR>&nbsp;&nbsp;&nbsp; s =3D to_codes ( parse (s) =
)<BR>&nbsp;&nbsp;&nbsp;=20
knowledge =3D define (knowledge, lquery, s)<BR>&nbsp; end =
procedure</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp; global procedure setto =
(object=20
x)<BR>&nbsp;&nbsp;&nbsp; x =3D to_codes ( {x} )<BR>&nbsp;&nbsp;&nbsp; =
knowledge =3D=20
define (knowledge, lquery, x)<BR>&nbsp; end procedure</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp; global function ask =
(sequence=20
s)<BR>&nbsp;&nbsp;&nbsp; return flatten(to_names (ask_query(knowledge, =
to_codes=20
(parse(s))) ), ' ')<BR>&nbsp; end function</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial=20
-----</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;Here&nbsp;the code ends! ..&nbsp; =
Greetings,=20
Ralf.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>

------=_NextPart_000_0043_01BFE179.1FCD3DA0--

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu