我已经在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中获得此结果?
最佳答案
设置一个Writer并告诉Jess使用它:
Writer writer = new StringWriter();
rete.addOutputRouter( "t", writer );
// run Jess writing to router "t"
System.out.println( writer.toString() );