home *** CD-ROM | disk | FTP | other *** search
- 10 poke53280,15:poke53281,0:
- 100 print"[147]inference engine"
- 110 print"enter facts in this form:"
- 120 print" a bear is a mammal"
- 130 print"questions like this:"
- 140 print" what is a bear"
- 150 print"enter bye to exit"
- 160 dim b$(100),fa(100,20),fl(100),stk(100)
- 170 na=4:for l=1 to na:read art$(l):next:data a,an,is,what
- 180 print:inputa$:for l=1 to h:t$(l)="":next:h=1
- 190 rem parse the list
- 200 for l=1 to len(a$):j$=mid$(a$,l,1)
- 210 rem look for spaces
- 220 if j$=" " then h=h+1:goto240
- 230 t$(h)=t$(h)+j$
- 240 next:if t$(1)="exit" or t$(1)="quit" or t$(1)="bye" then print"[147]":end
- 250 nn=1
- 260 for i=1 to h:f=0
- 270 for l=1 to na
- 280 if art$(l)=t$(i) then f=1
- 290 next l
- 300 if f=0 then w$(nn)=t$(i):nn=nn+1
- 310 next i
- 320 if t$(1)="what" then440
- 330 if nn<>3 then print"must have two nouns":goto180
- 340 rem build fact table
- 350 n=1:gosub570:i1=i
- 360 n=2:gosub570:i2=i:j=0
- 370 if fa(i1,j)=0 then fa(i1,j)=i2:goto410
- 380 if fa(i1,j)=i2 then print"already know that":goto180
- 390 j=j+1:if j>20 then print"fa array full, error"
- 400 goto370
- 410 print"understood"
- 420 goto180
- 430 rem respond to questions
- 440 if nn>2 then print"use one noun in questions":goto180
- 450 n=1:gosub570:i1=i
- 460 rem clear stack
- 470 for i=1 to 100:stk(i)=-1:fl(i)=-1:next:sp=0
- 480 rem display facts
- 490 j=0:k=i1:if fa(k,j)=0 then print"no knowledge about "w$(1):goto180
- 500 fl(k)=1:if fa(k,j)=-1 then540
- 510 t=fa(k,j)
- 520 if fl(t)=-1 then fl(t)=1:print" "b$(t);:sp=sp+1:stk(sp)=t
- 530 j=j+1:if j<=20 then500
- 540 if sp>0 then k=stk(sp):sp=sp-1:j=0:goto500
- 550 rem stack is empty, so we are done
- 560 goto180:rem go for more input
- 570 a$=w$(n):i=1
- 580 if b$(i)="" then b$(i)=a$:return
- 590 if b$(i)=a$ then return
- 600 i=i+1:if i>100 then print"b$ array full, error":return
- 610 goto580
-