Expert systems in forth

Liste des GroupesRevenir à cl forth 
Sujet : Expert systems in forth
De : melahi_ahmed (at) *nospam* yahoo.fr (ahmed)
Groupes : comp.lang.forth
Date : 04. Jan 2025, 12:32:45
Autres entêtes
Organisation : novaBBS
Message-ID : <069d1724f6056b4c36d9e1ffaa3d606d@www.novabbs.com>
User-Agent : Rocksolid Light
Hi,
For my course, I've written a "Expert System Inference Engine":
expert_systems.fs.
It works (and tested) under gforth, iForth anf vfxForth.
Here is a session using it with a simple "animal data base": animal.fs.
1. What is necessary for the animal to be a zebra?
--------------------------------------------------
zebra :-?
rule: 15
  verify:  herbivore
  verify:  ungulate
  verify:  black-stripes
 ok
2.  What is necessary for the animal to be a penguin?
-----------------------------------------------------
penguin :-?
rule: 9
  verify:  swim
  verify:  black&white
  verify:  bird
 ok
3. Assert the conditions for the animal to be a penguin:
------------------------------------------------------
swim yes  ok
black&white yes  ok
bird yes  ok
  ok
4. Forward chaining (using these asserted facts):
-------------------------------------------------
->?  ok
result
 It is a penguin. ok
5. Type the facts that are true:
-------------------------------
facts
-> true_fact:
    action: ''
    text:
-> not_fact:
    action: ''
    text:
-> swim:
    action: ''
    text:
-> bird:
    action: ''
    text:
-> black&white:
    action: ''
    text:
-> penguin:
    action: '_penguin_  cr type'
    text:
 ok
6. Clear facts (true facts will be false):
-------------------------------------
clear_facts
 ok
7. Verify that (the true_fact is always true):
----------------------------------------------
facts
-> true_fact:
    action: ''
    text:
 ok
8. Backward chaining:
---------------------
<-?
  verify:  feathers <--- yes
apparently,
apparently,
  verify:  hair <---
  verify:  give-milk <---
  verify:  eat-vegetals <---
  verify:  eat-meat <---
  verify:  pointed-teeth <---
  verify:  claws <---
  verify:  forward-eyes <---
  verify:  mammal <---
  verify:  hoofs <---
  verify:  chew-cud <---
  verify:  swim <--- yes
  verify:  black&white <--- yes
apparently,
 It is a penguin.
  verify:  long-neck <---
  verify:  not-fly <--- yes
  verify:  black-stripes <---
  verify:  carnivore <---
  verify:  tawny-color <---
  verify:  herbivore <---
  verify:  ungulate <---
  verify:  long-legs <---
  verify:  dark-spots <---
  verify:  fly-well <---
  verify:  wings <---
  verify:  fly <---
apparently,
 It is a penguin.
final result:
-------------
finally,
 It is a penguin. ok
9. Another one:
---------------
<-?
  verify:  feathers <---
  verify:  wings <--- yes
  verify:  lay-eggs <---
  verify:  hair <---
  verify:  give-milk <--- yes
apparently,
  verify:  eat-vegetals <---
  verify:  eat-meat <---
  verify:  pointed-teeth <---
  verify:  claws <---
  verify:  forward-eyes <---
  verify:  hoofs <---
  verify:  chew-cud <---
  verify:  swim <---
  verify:  black&white <---
  verify:  bird <---
  verify:  long-neck <---
  verify:  not-fly <---
  verify:  black-stripes <---
  verify:  carnivore <---
  verify:  tawny-color <---
  verify:  herbivore <---
  verify:  ungulate <---
  verify:  long-legs <---
  verify:  dark-spots <---
  verify:  fly-well <---
  verify:  fly <--- yes
apparently,
 It is a bat.
apparently,
 It is a bat.
final result:
-------------
finally,
 It is a bat. ok
10. Another one:
----------------
<-?
  verify:  feathers <--- yes
apparently,
apparently,
  verify:  hair <---
  verify:  give-milk <---
  verify:  eat-vegetals <---
  verify:  eat-meat <---
  verify:  pointed-teeth <---
  verify:  claws <---
  verify:  forward-eyes <---
  verify:  mammal <---
  verify:  hoofs <---
  verify:  chew-cud <---
  verify:  swim <---
  verify:  black&white <--- yes
  verify:  long-neck <--- yes
  verify:  not-fly <--- yes
apparently,
 It is an ostrich.
  verify:  black-stripes <---
  verify:  carnivore <---
  verify:  tawny-color <---
  verify:  herbivore <---
  verify:  ungulate <---
  verify:  long-legs <---
  verify:  dark-spots <---
  verify:  fly-well <---
  verify:  fly <---
apparently,
 It is an ostrich.
final result:
-------------
finally,
 It is an ostrich. ok
11. Another one:
----------------
<-?
  verify:  feathers <---
  verify:  wings <---
  verify:  lay-eggs <---
  verify:  hair <--- yes
apparently,
apparently,
  verify:  eat-vegetals <---
  verify:  eat-meat <--- yes
apparently,
apparently,
  verify:  hoofs <---
  verify:  chew-cud <---
  verify:  swim <---
  verify:  black&white <---
  verify:  bird <---
  verify:  long-neck <---
  verify:  not-fly <--- yes
  verify:  black-stripes <--- yes
  verify:  tawny-color <--- yes
apparently,
 It is a tiger.
  verify:  herbivore <---
  verify:  ungulate <---
  verify:  long-legs <---
  verify:  dark-spots <---
  verify:  fly-well <---
  verify:  fly <---
apparently,
 It is a tiger.
final result:
-------------
finally,
 It is a tiger. ok
12. Another one:
----------------
<-?
  verify:  feathers <---
  verify:  wings <---
  verify:  lay-eggs <---
  verify:  hair <---
  verify:  give-milk <--- yes
apparently,
  verify:  eat-vegetals <---
  verify:  eat-meat <--- yes
apparently,
apparently,
  verify:  hoofs <---
  verify:  chew-cud <---
  verify:  swim <---
  verify:  black&white <--- yes
  verify:  bird <---
  verify:  long-neck <---
  verify:  not-fly <--- yes
  verify:  black-stripes <--- yes
  verify:  tawny-color <--- yes
apparently,
 It is a tiger.
  verify:  herbivore <---
  verify:  ungulate <---
  verify:  long-legs <---
  verify:  dark-spots <--- yes
apparently,
 It is a cheetah.
 It is a tiger.
  verify:  fly-well <---
  verify:  fly <---
apparently,
 It is a cheetah.
 It is a tiger.
final result:
-------------
finally,
 It is a cheetah.
 It is a tiger. ok
  ok
13. Type the rules:
-------------------
rules
Rule n°:0 :    bird        :- feathers .;
Rule n°:1 :    bird        :- wings , lay-eggs .;
Rule n°:2 :    mammal      :- hair .;
Rule n°:3 :    mammal      :- give-milk .;
Rule n°:4 :    herbivore   :- eat-vegetals .;
Rule n°:5 :    carnivore   :- eat-meat .;
Rule n°:6 :    carnivore   :- pointed-teeth , claws , forward-eyes .;
Rule n°:7 :    ungulate    :- mammal , hoofs .;
Rule n°:8 :    ungulate    :- mammal , chew-cud .;
Rule n°:9 :    penguin     :- swim , black&white , bird , fly notfact .;
Rule n°:10 :    ostrich     :- black&white , bird , long-neck , not-fly
;
Rule n°:11 :    tiger       :- black-stripes , carnivore , tawny-color ,
mammal .;
Rule n°:12 :    giraffe     :- herbivore , long-neck , ungulate ,
long-legs , dark-spots .;
Rule n°:13 :    cheetah     :- dark-spots , tawny-color , carnivore ,
mammal .;
Rule n°:14 :    albatros    :- fly-well , bird .;
Rule n°:15 :    zebra       :- herbivore , ungulate , black-stripes .;
Rule n°:16 :    bat         :- wings , fly , mammal .; ok
  ok
14. Verify mode of chaining:
----------------------------
mode forward ok
15. Change chaining mode:
-------------------------
backward_mode  ok
16. Verify it:
--------------
mode backward ok
17. Change chaining mode:
-------------------------
forward_mode  ok
18. Verify it:
--------------
mode forward ok
19. Type true facts:
--------------------
facts
-> true_fact:
    action: ''
    text:
-> not_fact:
    action: ''
    text:
-> give-milk:
    action: 'give-milk  yes'
    text:
-> not-fly:
    action: 'not-fly  yes'
    text:
-> tawny-color:
    action: 'tawny-color  yes'
    text:
-> dark-spots:
    action: 'dark-spots  yes'
    text:
-> black&white:
    action: 'black&white  yes'
    text:
-> mammal:
    action: ''
    text:
-> black-stripes:
    action: 'black-stripes  yes'
    text:
-> carnivore:
    action: ''
    text:
-> eat-meat:
    action: 'eat-meat  yes'
    text:
-> cheetah:
    action: '_cheetah_  cr type'
    text:
-> tiger:
    action: '_tiger_    cr type'
    text:
 ok
20. Clear facts and verify it:
------------------------------
clear_facts
 ok
facts
-> true_fact:
    action: ''
    text:
 ok
Ahmed
--

Date Sujet#  Auteur
4 Jan 25 * Expert systems in forth20ahmed
4 Jan 25 `* Re: Expert systems in forth19ahmed
4 Jan 25  `* Re: Expert systems in forth18ahmed
4 Jan 25   `* Re: Expert systems in forth17minforth
4 Jan 25    +* Re: Expert systems in forth6ahmed
5 Jan 25    i`* Re: Expert systems in forth5mhx
5 Jan 25    i `* Re: Expert systems in forth4ahmed
6 Jan 25    i  `* Re: Expert systems in forth3mhx
7 Jan 25    i   `* Re: Expert systems in forth2dxf
7 Jan 25    i    `- Re: Expert systems in forth1ahmed
5 Jan 25    `* Re: Expert systems in forth10Anton Ertl
5 Jan 25     `* Re: Expert systems in forth9ahmed
5 Jan 25      `* Re: Expert systems in forth8Anton Ertl
5 Jan 25       +* Re: Expert systems in forth3ahmed
5 Jan 25       i`* Re: Expert systems in forth2Anton Ertl
5 Jan 25       i `- Re: Expert systems in forth1ahmed
5 Jan 25       `* Re: Expert systems in forth4albert
5 Jan 25        +* Re: Expert systems in forth2ahmed
6 Jan 25        i`- Re: Expert systems in forth1ahmed
6 Jan 25        `- Re: Expert systems in forth1dxf

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal