Dear All,
When executing the code below I receive the following error:
-------------------------------------------------------------------------------------------
f-0 (MAIN::Exerc_Funcao (Fun_Processo "operador1") (Fun_Emp "operador2")
(Treinado "nao"))
For a total of 1 facts in module MAIN.
Exception in thread "main" Jess reported an error in routine
Context.getReturn
while executing (+ ?Humano)
while executing (store Newuser (+ ?Humano)).
Message: No such variable Humano.
Program text: ( store Newuser ( + ?Humano ) ) at line 1.
at jess.Context.getVariable(Unknown Source)
at jess.Variable.resolveValue(Unknown Source)
at jess.dl.call(Unknown Source)
at jess.ab.a(Unknown Source)
at jess.Funcall.execute(Unknown Source)
at jess.FuncallValue.resolveValue(Unknown Source)
at jess.fk.call(Unknown Source)
at jess.ab.a(Unknown Source)
at jess.Funcall.execute(Unknown Source)
at jess.Jesp.a(Unknown Source)
at jess.Jesp.parseExpression(Unknown Source)
at jess.Jesp.promptAndParseOneExpression(Unknown Source)
at jess.Jesp.parse(Unknown Source)
at jess.Rete.eval(Unknown Source)
at jess.Rete.executeCommand(Unknown Source)
at acidentes.main(acidentes.java:35)
-------------------------------------------------------------------------------------------
import jess.*;
public class acidentes {
public static void main(String[] unused) throws JessException {
Rete engine = new Rete();
Deftemplate a = new Deftemplate("Exerc_Funcao", "Exerc_Funcao", engine);
a.addSlot("Fun_Processo", Funcall.NIL, "STRING");
a.addSlot("Fun_Emp", Funcall.NIL, "STRING");
a.addSlot("Treinado", Funcall.NIL, "STRING");
engine.addDeftemplate(a);
String[] dados = {"operador1", "operador2", "nao"};
Fact g = new Fact("Exerc_Funcao", engine);
g.setSlotValue("Fun_Processo", new Value(dados[0], RU.STRING));
g.setSlotValue("Fun_Emp",new Value(dados[1], RU.STRING));
g.setSlotValue("Treinado",new Value(dados[2], RU.STRING));
engine.assertFact(g);
engine.executeCommand("(facts)");
String rules ="(defrule Verifica_Funcao";
rules +="(Exerc_Funcao {Treinado == nao})";
rules +="=>";
rules +="(bind ?Humano (+ ?Humano 3)))";
engine.executeCommand(rules);
engine.executeCommand("(run)");
engine.executeCommand("(store Newuser(+ ?Humano))");
Value Newvalue = engine.fetch("Newuser");
int results = 0;
if(Newvalue != null){
results = Newvalue.intValue(engine.getGlobalContext());
}
System.out.println(results);
}
}
According to the error the variable does not exists.
Could you please help me?
Regards,