获取字符串变量中的CLIPS / Jess输出

时间:2017-03-14 19:17:17

标签: java clips jess

我已经在netbeans中集成了jess和java。我想访问字符串变量中的输出。

当我(运行).clp文件并给它一个输入时,它显示输出,但我想在字符串变量中获得此输出。我怎样才能做到这一点??请帮忙。这是我的.clp文件代码。

(deftemplate problem
(multislot name)
(slot symptom))

(deffacts probelms
(probelm (name (create$ "Air filter"  "fuel injector problem" "fuel pressure regualtor")) 
    (symptom Black-Smoke))
    )

(defrule reading-input
=>
(printout t "Enter the symptom your car Shows: " )
(assert (var (read))))

(defrule checking-input
(var ?symptom)
(probelm  (symptom ?symptom1)(name $?name1))
(test (eq ?symptom ?symptom1)) 
 =>
(printout t "Problems can be " $?name1 crlf))

在java中运行它的代码

 public static string path="C:\Users\Taimoor Mirza\Documents\car.CLP";  
  Rete r=new Rete();
   r.batch(path);
   r.reset();
   r.run();

这个运行良好,当我进入Black-Smoke时,这给了我运行exe的可能症状。 我想在字符串中得到这些症状。怎么才能在String中得到这个结果???

2 个答案:

答案 0 :(得分:1)

设置一个Writer并告诉Jess使用它:

Writer writer = new StringWriter();
rete.addOutputRouter( "t", writer );
// run Jess writing to router "t"
System.out.println( writer.toString() );

答案 1 :(得分:0)

请参阅手册中有关I / O路由器的部分,此处为:http://www.jessrules.com/jess/docs/71/library.html#routers。使用java.io.StringWriter作为输出路由器,然后从StringWriter

中检索文本