home *** CD-ROM | disk | FTP | other *** search
/ Compute! Gazette 1989 December / 1989-12.d64 / feedback (.txt) < prev    next >
Commodore BASIC  |  2022-09-20  |  1KB  |  54 lines

  1. 10 poke53280,15:poke53281,0:
  2. 100 print"[147]inference engine"
  3. 110 print"enter facts in this form:"
  4. 120 print"     a bear is a mammal"
  5. 130 print"questions like this:"
  6. 140 print"     what is a bear"
  7. 150 print"enter bye to exit"
  8. 160 dim b$(100),fa(100,20),fl(100),stk(100)
  9. 170 na=4:for l=1 to na:read art$(l):next:data a,an,is,what
  10. 180 print:inputa$:for l=1 to h:t$(l)="":next:h=1
  11. 190 rem parse the list
  12. 200 for l=1 to len(a$):j$=mid$(a$,l,1)
  13. 210 rem look for spaces
  14. 220 if j$=" " then h=h+1:goto240
  15. 230 t$(h)=t$(h)+j$
  16. 240 next:if t$(1)="exit" or t$(1)="quit" or t$(1)="bye" then print"[147]":end
  17. 250 nn=1
  18. 260 for i=1 to h:f=0
  19. 270 for l=1 to na
  20. 280 if art$(l)=t$(i) then f=1
  21. 290 next l
  22. 300 if f=0 then w$(nn)=t$(i):nn=nn+1
  23. 310 next i
  24. 320 if t$(1)="what" then440
  25. 330 if nn<>3 then print"must have two nouns":goto180
  26. 340 rem build fact table
  27. 350 n=1:gosub570:i1=i
  28. 360 n=2:gosub570:i2=i:j=0
  29. 370 if fa(i1,j)=0 then fa(i1,j)=i2:goto410
  30. 380 if fa(i1,j)=i2 then print"already know that":goto180
  31. 390 j=j+1:if j>20 then print"fa array full, error"
  32. 400 goto370
  33. 410 print"understood"
  34. 420 goto180
  35. 430 rem respond to questions
  36. 440 if nn>2 then print"use one noun in questions":goto180
  37. 450 n=1:gosub570:i1=i
  38. 460 rem clear stack
  39. 470 for i=1 to 100:stk(i)=-1:fl(i)=-1:next:sp=0
  40. 480 rem display facts
  41. 490 j=0:k=i1:if fa(k,j)=0 then print"no knowledge about "w$(1):goto180
  42. 500 fl(k)=1:if fa(k,j)=-1 then540
  43. 510 t=fa(k,j)
  44. 520 if fl(t)=-1 then fl(t)=1:print"  "b$(t);:sp=sp+1:stk(sp)=t
  45. 530 j=j+1:if j<=20 then500
  46. 540 if sp>0 then k=stk(sp):sp=sp-1:j=0:goto500
  47. 550 rem stack is empty, so we are done
  48. 560 goto180:rem go for more input
  49. 570 a$=w$(n):i=1
  50. 580 if b$(i)="" then b$(i)=a$:return
  51. 590 if b$(i)=a$ then return
  52. 600 i=i+1:if i>100 then print"b$ array full, error":return
  53. 610 goto580
  54.