gpt4 book ai didi

java - 在字符串变量中获取 CLIPS/Jess 输出

转载 作者:行者123 更新时间:2023-11-30 06:50:54 24 4
gpt4 key购买 nike

我已经在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 时可能出现的症状。我想把这些症状放在一个字符串中。我怎样才能在字符串中得到这个结果???

最佳答案

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

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

关于java - 在字符串变量中获取 CLIPS/Jess 输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42794711/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com