use of nars.entity.Sentence 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.Sentence in project opennars by opennars.
the class SentenceTablePanel method newSelectedGraphPanel.
public void newSelectedGraphPanel() {
Term[] sel = new Term[table.getSelectedRows().length];
int k = 0;
for (int i : table.getSelectedRows()) {
Sentence w = (Sentence) table.getValueAt(i, 1);
sel[k] = w.term;
k++;
}
TermSyntaxVis tt = new TermSyntaxVis(sel);
syntaxPanel = new PCanvas(tt);
syntaxPanel.setZoom(10f);
NWindow w = new NWindow("", syntaxPanel);
w.setSize(400, 400);
w.setVisible(true);
// ProcessingGraphPanel2 pgp = new ProcessingGraphPanel2(getSelectedRows(1)) {
//
// @Override
// public DirectedMultigraph getGraph() {
//
// DefaultGraphizer graphizer = new DefaultGraphizer(true, true, true, true, 0, false, false) {
//
// protected void addSentence(NARGraph g, Sentence s) {
// Term t = s.content;
// addTerm(g, t);
// //g.addEdge(s, s.content, new NARGraph.SentenceContent());
//
// if (t instanceof CompoundTerm) {
// CompoundTerm ct = ((CompoundTerm) t);
// Set<Term> contained = ct.getContainedTerms();
//
// for (Term x : contained) {
// addTerm(g, x);
// if (ct.containsTerm(x)) {
// g.addEdge(x, t, new NARGraph.TermContent());
// }
//
// for (Term y : contained) {
// addTerm(g, y);
//
// if (x != y) {
// if (x.containsTerm(y)) {
// g.addEdge(y, x, new NARGraph.TermContent());
// }
// }
// }
// }
// }
// }
//
// @Override
// public void onTime(NARGraph g, long time) {
// super.onTime(g, time);
//
// for (Object o : getItems()) {
//
// if (o instanceof Task) {
// g.addVertex(o);
// addSentence(g, ((Task) o).sentence);
// } else if (o instanceof Sentence) {
// g.addVertex(o);
// addSentence(g, (Sentence) o);
// }
// }
// //add sentences
// }
//
// };
//
// app.updating = true;
//
// graphizer.setShowSyntax(showSyntax);
//
// NARGraph g = new NARGraph();
// g.add(nar, newSelectedGraphFilter(), graphizer);
// return g;
// }
//
// @Override
// public int edgeColor(Object edge) {
// return NARSwing.getColor(edge.toString(), 0.5f, 0.5f).getRGB();
// }
//
// @Override
// public float edgeWeight(Object edge) {
// return 10;
// }
//
// @Override
// public int vertexColor(Object vertex) {
// return NARSwing.getColor(vertex.toString(), 0.5f, 0.5f).getRGB();
// }
//
// };
// NWindow w = new NWindow("", pgp);
// w.setSize(400, 400);
// w.setVisible(true);
}
use of nars.entity.Sentence in project opennars by opennars.
the class LocalRules method solutionQuality.
/**
* Evaluate the quality of the judgment as a solution to a problem
*
* @param problem A goal or question
* @param solution The solution to be evaluated
* @return The quality of the judgment as the solution
*/
public static float solutionQuality(boolean rateByConfidence, final Task probT, final Sentence solution, Memory memory) {
Sentence problem = probT.sentence;
if ((probT.sentence.punctuation != solution.punctuation && solution.term.hasVarQuery()) || !matchingOrder(problem.getTemporalOrder(), solution.getTemporalOrder())) {
return 0.0F;
}
TruthValue truth = solution.truth;
if (problem.getOccurenceTime() != solution.getOccurenceTime()) {
truth = solution.projectionTruth(problem.getOccurenceTime(), memory.time());
}
// so the previous handling to let whether the problem has query vars decide was wrong.
if (!rateByConfidence) {
return (float) (truth.getExpectation() / Math.sqrt(Math.sqrt(Math.sqrt(solution.term.getComplexity() * Parameters.COMPLEXITY_UNIT))));
} else {
return truth.getConfidence();
}
}
use of nars.entity.Sentence in project opennars by opennars.
the class LocalRules method trySolution.
/**
* Check if a Sentence provide a better answer to a Question or Goal
*
* @param belief The proposed answer
* @param task The task to be processed
* @param memory Reference to the memory
*/
public static boolean trySolution(Sentence belief, final Task task, final DerivationContext nal, boolean report) {
Sentence problem = task.sentence;
Memory memory = nal.mem();
Sentence oldBest = task.getBestSolution();
if (oldBest != null) {
boolean rateByConfidence = oldBest.getTerm().equals(belief.getTerm());
float newQ = solutionQuality(rateByConfidence, task, belief, memory);
float oldQ = solutionQuality(rateByConfidence, task, oldBest, memory);
if (oldQ >= newQ) {
if (problem.isGoal()) {
memory.emotion.adjustSatisfaction(oldQ, task.getPriority(), nal);
}
memory.emit(Unsolved.class, task, belief, "Lower quality");
return false;
}
}
task.setBestSolution(memory, belief);
// memory.logic.SOLUTION_BEST.commit(task.getPriority());
BudgetValue budget = solutionEval(task, belief, task, nal);
if ((budget != null) && budget.aboveThreshold()) {
// Solution Activated
if (task.sentence.punctuation == Symbols.QUESTION_MARK || task.sentence.punctuation == Symbols.QUEST_MARK) {
if (task.isInput() && report) {
// only show input tasks as solutions
memory.emit(Answer.class, task, belief);
} else {
// solution to quests and questions can be always showed
memory.emit(OutputHandler.class, task, belief);
}
} else {
// goal things only show silence related
memory.emit(OutputHandler.class, task, belief);
}
nal.addTask(nal.getCurrentTask(), budget, belief, task.getParentBelief());
return true;
} else {
memory.emit(Unsolved.class, task, belief, "Insufficient budget");
}
return false;
}
use of nars.entity.Sentence in project opennars by opennars.
the class RuleTables method syllogisms.
/* ----- syllogistic inferences ----- */
/**
* Meta-table of syllogistic rules, indexed by the content classes of the
* taskSentence and the belief
*
* @param tLink The link to task
* @param bLink The link to belief
* @param taskTerm The content of task
* @param beliefTerm The content of belief
* @param nal Reference to the memory
*/
private static void syllogisms(TaskLink tLink, TermLink bLink, Term taskTerm, Term beliefTerm, DerivationContext nal) {
Sentence taskSentence = nal.getCurrentTask().sentence;
Sentence belief = nal.getCurrentBelief();
int figure;
if (taskTerm instanceof Inheritance) {
if (beliefTerm instanceof Inheritance) {
figure = indexToFigure(tLink, bLink);
asymmetricAsymmetric(taskSentence, belief, figure, nal);
} else if (beliefTerm instanceof Similarity) {
figure = indexToFigure(tLink, bLink);
asymmetricSymmetric(taskSentence, belief, figure, nal);
} else {
detachmentWithVar(belief, taskSentence, bLink.getIndex(0), nal);
}
} else if (taskTerm instanceof Similarity) {
if (beliefTerm instanceof Inheritance) {
figure = indexToFigure(bLink, tLink);
asymmetricSymmetric(belief, taskSentence, figure, nal);
} else if (beliefTerm instanceof Similarity) {
figure = indexToFigure(bLink, tLink);
symmetricSymmetric(belief, taskSentence, figure, nal);
} else if (beliefTerm instanceof Implication) {
// Bridge to higher order statements:
figure = indexToFigure(tLink, bLink);
asymmetricSymmetric(belief, taskSentence, figure, nal);
} else if (beliefTerm instanceof Equivalence) {
// Bridge to higher order statements:
figure = indexToFigure(tLink, bLink);
symmetricSymmetric(belief, taskSentence, figure, nal);
}
} else if (taskTerm instanceof Implication) {
if (beliefTerm instanceof Implication) {
figure = indexToFigure(tLink, bLink);
asymmetricAsymmetric(taskSentence, belief, figure, nal);
} else if (beliefTerm instanceof Equivalence) {
figure = indexToFigure(tLink, bLink);
asymmetricSymmetric(taskSentence, belief, figure, nal);
} else if (beliefTerm instanceof Inheritance) {
detachmentWithVar(taskSentence, belief, tLink.getIndex(0), nal);
} else if (beliefTerm instanceof Similarity) {
// Bridge to higher order statements:
figure = indexToFigure(tLink, bLink);
asymmetricSymmetric(taskSentence, belief, figure, nal);
}
} else if (taskTerm instanceof Equivalence) {
if (beliefTerm instanceof Implication) {
figure = indexToFigure(bLink, tLink);
asymmetricSymmetric(belief, taskSentence, figure, nal);
} else if (beliefTerm instanceof Equivalence) {
figure = indexToFigure(bLink, tLink);
symmetricSymmetric(belief, taskSentence, figure, nal);
} else if (beliefTerm instanceof Inheritance) {
detachmentWithVar(taskSentence, belief, tLink.getIndex(0), nal);
} else if (beliefTerm instanceof Similarity) {
// Bridge to higher order statements:
figure = indexToFigure(tLink, bLink);
symmetricSymmetric(belief, taskSentence, figure, nal);
}
}
}
Aggregations