use of nars.entity.Task in project opennars by opennars.
the class SentenceTablePanel method output.
@Override
public void output(Class c, Object o) {
if (o instanceof Task) {
Task t = (Task) o;
float priority = t.getPriority();
Sentence s = t.sentence;
float freq = -1;
float conf = -1;
TruthValue truth = s.truth;
if (truth != null) {
freq = truth.getFrequency();
conf = truth.getConfidence();
}
// t.getParentTask();
Task pt = null;
String parentTask = (pt != null) ? pt.toStringExternal() : "";
// TODO use table sort instead of formatting numbers with leading '0's
data.addRow(new Object[] { String.format("%08d", nar.time()), s, s.punctuation, freq == -1 ? "" : freq, conf == -1 ? "" : conf, String.format("%03d", s.term.getComplexity()), priority, parentTask });
}
}
use of nars.entity.Task in project opennars by opennars.
the class StructuralRules method transformSetRelation.
/* -------------------- set transform -------------------- */
/**
* {<S --> {P}>} |- <S <-> {P}>
*
* @param compound The set compound
* @param statement The premise
* @param side The location of the indicated term in the premise
* @param nal Reference to the memory
*/
static void transformSetRelation(CompoundTerm compound, Statement statement, short side, DerivationContext nal) {
if (compound.size() > 1) {
return;
}
if (statement instanceof Inheritance) {
if (((compound instanceof SetExt) && (side == 0)) || ((compound instanceof SetInt) && (side == 1))) {
return;
}
}
Term sub = statement.getSubject();
Term pre = statement.getPredicate();
Statement content;
if (statement instanceof Inheritance) {
content = Similarity.make(sub, pre);
} else {
if (((compound instanceof SetExt) && (side == 0)) || ((compound instanceof SetInt) && (side == 1))) {
content = Inheritance.make(pre, sub);
} else {
content = Inheritance.make(sub, pre);
}
}
if (content == null) {
return;
}
Task task = nal.getCurrentTask();
Sentence sentence = task.sentence;
TruthValue truth = sentence.truth;
BudgetValue budget;
if (sentence.isJudgment()) {
budget = BudgetFunctions.compoundForward(truth, content, nal);
} else {
budget = BudgetFunctions.compoundBackward(content, nal);
}
nal.singlePremiseTask(content, truth, budget);
}
use of nars.entity.Task in project opennars by opennars.
the class StructuralRules method structuralStatement.
/**
* Common final operations of the above two methods
*
* @param subject The subject of the new task
* @param predicate The predicate of the new task
* @param truth The truth value of the new task
* @param nal Reference to the memory
*/
private static void structuralStatement(Term subject, Term predicate, int order, TruthValue truth, DerivationContext nal) {
Task task = nal.getCurrentTask();
Term oldContent = task.getTerm();
if (oldContent instanceof Statement) {
Statement content = Statement.make((Statement) oldContent, subject, predicate, order);
if (content != null) {
BudgetValue budget = BudgetFunctions.compoundForward(truth, content, nal);
nal.singlePremiseTask(content, truth, budget);
}
}
}
use of nars.entity.Task in project opennars by opennars.
the class StructuralRules method structuralDecompose1.
/**
* {<(S|T) --> P>, S@(S|T)} |- <S --> P> {<S --> (P&T)>, P@(P&T)} |- <S --> P>
*
* @param compound The compound term
* @param index The location of the indicated term in the compound
* @param statement The premise
* @param nal Reference to the memory
*/
static void structuralDecompose1(CompoundTerm compound, short index, Statement statement, DerivationContext nal) {
if (index >= compound.term.length) {
return;
}
Term component = compound.term[index];
Task task = nal.getCurrentTask();
Sentence sentence = task.sentence;
int order = sentence.getTemporalOrder();
TruthValue truth = sentence.truth;
if (truth == null) {
return;
}
final float reliance = Parameters.reliance;
TruthValue truthDed = TruthFunctions.deduction(truth, reliance);
TruthValue truthNDed = TruthFunctions.negation(TruthFunctions.deduction(truth, reliance));
Term subj = statement.getSubject();
Term pred = statement.getPredicate();
if (compound.equals(subj)) {
if (compound instanceof IntersectionInt) {
structuralStatement(component, pred, order, truthDed, nal);
} else if ((compound instanceof SetExt) && (compound.size() > 1)) {
Term[] t1 = new Term[] { component };
structuralStatement(new SetExt(t1), pred, order, truthDed, nal);
} else if (compound instanceof DifferenceInt) {
if (index == 0) {
structuralStatement(component, pred, order, truthDed, nal);
} else {
structuralStatement(component, pred, order, truthNDed, nal);
}
}
} else if (compound.equals(pred)) {
if (compound instanceof IntersectionExt) {
structuralStatement(subj, component, order, truthDed, nal);
} else if ((compound instanceof SetInt) && (compound.size() > 1)) {
structuralStatement(subj, new SetInt(component), order, truthDed, nal);
} else if (compound instanceof DifferenceExt) {
if (index == 0) {
structuralStatement(subj, component, order, truthDed, nal);
} else {
structuralStatement(subj, component, order, truthNDed, nal);
}
}
}
}
use of nars.entity.Task in project opennars by opennars.
the class StructuralRules method structuralCompound.
/* --------------- Disjunction and Conjunction transform --------------- */
/**
* {(&&, A, B), A@(&&, A, B)} |- A, or answer (&&, A, B)? using A {(||, A,
* B), A@(||, A, B)} |- A, or answer (||, A, B)? using A
*
* @param compound The premise
* @param component The recognized component in the premise
* @param compoundTask Whether the compound comes from the task
* @param nal Reference to the memory
*/
static boolean structuralCompound(CompoundTerm compound, Term component, boolean compoundTask, int index, DerivationContext nal) {
if (compound instanceof Conjunction) {
if (nal.getCurrentTask().getTerm() == compound) {
// only for # for now, will be gradually applied to &/ later
Conjunction conj = (Conjunction) compound;
if (conj.getTemporalOrder() == TemporalRules.ORDER_FORWARD && conj.isSpatial) {
// and some also to && &|
// flattenSequence(compound, component, compoundTask, index, nal);
groupSequence(compound, component, compoundTask, index, nal);
// takeOutFromConjunction(compound, component, compoundTask, index, nal);
splitConjunctionApart(compound, component, compoundTask, index, nal);
}
if (conj.getTemporalOrder() == TemporalRules.ORDER_FORWARD) {
seqToImage(conj, index, nal);
}
}
}
if (component.hasVarIndep()) {
// moved down here since flattening also works when indep
return false;
}
// and also for &/ with index > 0
if ((compound instanceof Conjunction) && !compound.getIsSpatial() && (compound.getTemporalOrder() == TemporalRules.ORDER_FORWARD) && (index != 0)) {
return false;
}
final Term content = compoundTask ? component : compound;
Task task = nal.getCurrentTask();
Sentence sentence = task.sentence;
TruthValue truth = sentence.truth;
final float reliance = Parameters.reliance;
BudgetValue budget;
if (sentence.isQuestion() || sentence.isQuest()) {
budget = BudgetFunctions.compoundBackward(content, nal);
} else {
// [03:25] <patham9> <a --> b>. (&&,<a --> b>,<x --> y>). => <x --> y>
if ((sentence.isJudgment() || sentence.isGoal()) && ((!compoundTask && compound instanceof Disjunction) || (compoundTask && compound instanceof Conjunction))) {
truth = TruthFunctions.deduction(truth, reliance);
} else {
TruthValue v1, v2;
v1 = TruthFunctions.negation(truth);
v2 = TruthFunctions.deduction(v1, reliance);
truth = TruthFunctions.negation(v2);
}
budget = BudgetFunctions.forward(truth, nal);
}
return nal.singlePremiseTask(content, truth, budget);
}
Aggregations