use of nars.nal.nal3.SetExt in project narchy by automenta.
the class BooleanChallenge method event.
@Override
public void event(Class event, Object[] arguments) {
if (!(arguments[0] instanceof Task))
return;
Task answer = (Task) arguments[0];
if (!answer.isJudgment())
return;
if (answer.isInput()) {
// this is a repetition of something explicitly input
return;
}
// if (!started) {
// if (answer.getTerm().toString().equals(startChallenge)) {
// started = true;
// }
// else {
// return;
// }
// }
// for now, assume the qustion term is answer term
Term qterm = answer.getTerm();
if (answerProvided.contains(qterm)) {
return;
}
if (answer.getConfidence() < confThreshold)
return;
Term t = answer.getTerm();
if (t instanceof Inheritance) {
Term subj = ((Inheritance) t).getSubject();
Term pred = ((Inheritance) t).getPredicate();
if ((subj instanceof SetExt) && (((SetExt) subj).length() == 1))
subj = ((Compound) subj).term[0];
if (subj instanceof Product) {
Product p = (Product) subj;
int[] n = n(p, 3);
if (n != null) {
boolean correct = false;
switch(pred.toString()) {
case "and":
correct = evalAnd(n);
break;
case "or":
correct = evalOr(n);
break;
case "xor":
correct = evalXor(n);
break;
// case "not": correct = evalNot(n); break;
default:
return;
}
float freq = answer.getFrequency();
float conf = answer.getConfidence();
if (freq < freqThresh) {
// invert
correct = !correct;
freq = 1f - freq;
}
if (freq < (1.0 - freqThresh)) {
// not clear 0 or 1
return;
}
addScore(qterm, answer, correct, freq * conf);
if (!correct) {
System.err.println(answer.getExplanation());
if (failOnError)
System.exit(1);
// give correct answer
if (correctFeedback) {
// String c = getTerm(n[0], n[1], pred.toString(), not(n[2])) + ('.');
Term fc = nar.term(getTerm(n[0], n[1], pred.toString(), n[2]));
String c = "(--," + fc + ("). %1.00;" + n2(inputConf) + "%");
nar.input(c);
answerProvided.add(fc);
questionScores.remove(fc);
}
}
}
}
}
}
Aggregations