March 6, 2012

Example of add rules in knowledge base by using clips commands

Example of add rules in knowledge base by using clips commands

e.g.

  1. If a patient has 101 degree Fahrenheit temperature, yellow spots, red rash and infected throat then assert
    that disease is diagnosed as allergy and print out that patient is suffering from allergy.Note: Disease is a parameter of title diagnose
  2. If disease is diagnosed as allergy then assert that Novidat and Evil are the medicines suggested by the
    doctor as treatment and print out that Novidat and Evil medicines should be used.Note: Medicine is a parameter of title treatment.

Clips Commands & Implementation:

  1. CLIPS> (defrule diagnose “Diagnose Disease for a Patient”
    (temperature-is “101 degree fahrenheit”)
    (spots-are yellow)
    (rash-is red)
    (throat-is infected)
    =>
    (assert (disease-diagnosed-as allergy))
    )

    CLIPS> (assert (temperature-is “101 degree fahrenheit”))

    CLIPS> (assert (spots-are yellow))

    CLIPS> (assert (rash-is red))

    CLIPS> (assert (throat-is infected))

    CLIPS> (facts)
    f-0 (temperature-is “101 degree fahrenheit”)
    f-1 (spots-are yellow)
    f-2 (rash-is red)
    f-3 (throat-is infected)
    For a total of 4 facts.

    CLIPS> (rules)
    diagnose
    For a total of 1 defrule.

    CLIPS> (run)
    CLIPS> (defrule quickDiagnose
    (throat-is infected)
    =>
    (assert (throat-needs treatment))
    )

    CLIPS> (rules)
    diagnose
    quickDiagnose
    For a total of 2 defrules.

    CLIPS> (run)

    CLIPS> (facts)
    f-0 (temperature-is “101 degree fahrenheit”)
    f-1 (spots-are yellow)
    f-2 (rash-is red)
    f-3 (throat-is infected)
    f-4 (disease-diagnosed-as allergy)
    f-5 (throat-needs treatment)
    For a total of 6 facts.

    CLIPS> (rules)
    diagnose
    quickDiagnose
    For a total of 2 defrules.

  2. CLIPS> (defrule treatment “Suggest medicines for treatment”
    (disease-diagnosed-as allergy)
    =>
    (assert (medicine “Novidat and Evil”))
    (printout t “are the medicines suggested for allergy”))

    CLIPS> (assert (disease-diagnosed-as allergy))

    CLIPS> (facts)
    f-0 (disease-diagnosed-as allergy)
    For a total of 1 fact.

    CLIPS> (rules)
    treatment
    For a total of 1 defrule.

    CLIPS> (run)
    are the medicines suggested for allergy

Last updated: March 19, 2014