Как читать / использовать пользовательский ввод с помощью CLIPS - PullRequest
0 голосов
/ 27 марта 2019

Я работаю над проектом Clips.Я пытаюсь в первую очередь хранить факты (это нормально).Затем я пытаюсь попросить пользователя предоставить подробную информацию о драгоценных камнях, которые хранятся в виде фактов, и на основе их ответов предоставить им правильное название камня.

(deftemplate gem
(slot name)
(slot hardness)
(slot density)
(multislot colors))

(deffacts gems
(gem (name diamond) (hardness 10) (density 3.52) (colors yellow, brown, green, blue, white, colorless))
(gem (name corundum) (hardness 9) (density 4) (colors red, pink, yellow, brown, green, blue, violet, black, white, colorless))
(gem (name chrysoberyl) (hardness 8.5) (density 3.72) (colors yellow,brown,green))
(gem (name spinel) (hardness 8) (density 3.6) (colors red, pink, yellow, brown, green, blue, violet, white, colorless)))

(defrule reading-input
  =>
(printout t "Enter the hardness of the gem: " )
(assert (var(read)))
(printout t "Enter the density of the gem: " )
(assert (var(read)))
(printout t "Enter the color of the gem: " )
(assert (var(read))))

(defrule checking-input
(var ?hardness)
(var ?density)
(var ?colors)
(gem (name ?name1) (hardness ?hardness1) (density ?density1) (colors $?colors1))
(test (= ?hardness ?hardness1))
(test (= ?hardness ?hardness1))
(test (member$ ?hardness ?hardness1))
 =>
(printout t "Gem is " ?name1 crlf))

Я новичок в CLIPS и не могу понять, как заставить вышеуказанный код работать правильно, несмотря на то, что потратил на это часы.Любая помощь будет оценена. Спасибо.

1 Ответ

1 голос
/ 27 марта 2019
         CLIPS (6.31 2/3/18)
CLIPS> 
(deftemplate gem
   (slot name)
   (slot hardness)
   (slot density)
   (multislot colors))
CLIPS>  
(deffacts gems
   (gem (name diamond) (hardness 10) (density 3.52) (colors yellow brown green blue white colorless))
   (gem (name corundum) (hardness 9) (density 4) (colors red pink yellow brown green blue violet black white colorless))
   (gem (name chrysoberyl) (hardness 8.5) (density 3.72) (colors yellow brown green))
   (gem (name spinel) (hardness 8) (density 3.6) (colors red pink yellow brown green blue violet white colorless)))
CLIPS> 
(defrule reading-input
   =>
   (printout t "Enter the hardness of the gem: " )
   (assert (hardness (read)))
   (printout t "Enter the density of the gem: " )
   (assert (density (read)))
   (printout t "Enter the color of the gem: " )
   (assert (color (read))))
CLIPS> 
(defrule checking-input
   (hardness ?hardness)
   (density ?density)
   (color ?color)
   (gem (name ?name1) (hardness ?hardness1) (density ?density1) (colors $?colors1))
   (test (= ?hardness ?hardness1))
   (test (= ?density ?density1))
   (test (member$ ?color ?colors1))
    =>
   (printout t "Gem is " ?name1 crlf))
CLIPS> (reset)
CLIPS> (run)
Enter the hardness of the gem: 9
Enter the density of the gem: 4
Enter the color of the gem: green
Gem is corundum
CLIPS> 
...