use of nars.entity.Sentence in project opennars by opennars.
the class OutputContainsCondition method cond.
public boolean cond(Class channel, Object signal) {
if ((channel == OUT.class) || (channel == EXE.class)) {
String o;
if (signal instanceof Task) {
// only compare for Sentence string, faster than TextOutput.getOutputString
// which also does unescaping, etc..
Task t = (Task) signal;
Sentence s = t.sentence;
o = s.toString(nar, false).toString();
if (o.contains(containing)) {
if (saveSimilar) {
exact.add(t);
}
return true;
}
} else {
Task t = null;
if (signal instanceof ExecutionResult)
t = ((ExecutionResult) signal).getTask();
o = TextOutputHandler.getOutputString(channel, signal, false, false, nar).toString();
if (o.contains(containing)) {
if ((saveSimilar) && (t != null)) {
exact.add(t);
}
return true;
}
}
if (saveSimilar) {
int dist = levenshteinDistance(o, containing);
if (almost.size() >= maxSimilars) {
SimilarOutput last = almost.last();
if (dist < last.distance) {
almost.remove(last);
almost.add(new SimilarOutput(o, dist));
}
} else {
almost.add(new SimilarOutput(o, dist));
}
}
}
/*if (channel == ERR.class) {
Assert.assertTrue(signal.toString(), false);
}*/
return false;
}
use of nars.entity.Sentence in project opennars by opennars.
the class Memory method processNewTasks.
/**
* Process the newTasks accumulated in the previous workCycle, accept input
* ones and those that corresponding to existing concepts, plus one from the
* buffer.
*/
public void processNewTasks() {
Task task;
// don't include new tasks produced in the current workCycle
int counter = newTasks.size();
while (counter-- > 0) {
task = newTasks.removeFirst();
boolean enterDirect = true;
if (/*task.isElemOfSequenceBuffer() || task.isObservablePrediction() || */
enterDirect || task.isInput() || task.sentence.isQuest() || task.sentence.isQuestion() || concept(task.sentence.term) != null) {
// new input or existing concept
localInference(task);
} else {
Sentence s = task.sentence;
if (s.isJudgment() || s.isGoal()) {
double d = s.getTruth().getExpectation();
if (s.isJudgment() && d > Parameters.DEFAULT_CREATION_EXPECTATION) {
// new concept formation
novelTasks.putIn(task);
} else if (s.isGoal() && d > Parameters.DEFAULT_CREATION_EXPECTATION_GOAL) {
// new concept formation
novelTasks.putIn(task);
} else {
removeTask(task, "Neglected");
}
}
}
}
}
use of nars.entity.Sentence in project opennars by opennars.
the class Want method execute.
/**
* To create a goal with a given statement
* @param args Arguments, a Statement followed by an optional tense
* @param memory The memory in which the operation is executed
* @return Immediate results as Tasks
*/
@Override
protected ArrayList<Task> execute(Operation operation, Term[] args, Memory memory) {
Term content = args[1];
TruthValue truth = new TruthValue(1, Parameters.DEFAULT_JUDGMENT_CONFIDENCE);
Sentence sentence = new Sentence(content, Symbols.GOAL_MARK, truth, new Stamp(memory));
BudgetValue budget = new BudgetValue(Parameters.DEFAULT_GOAL_PRIORITY, Parameters.DEFAULT_GOAL_DURABILITY, truth);
return Lists.newArrayList(new Task(sentence, budget, true));
}
use of nars.entity.Sentence in project opennars by opennars.
the class Wonder method execute.
/**
* To create a question with a given statement
* @param args Arguments, a Statement followed by an optional tense
* @param memory The memory in which the operation is executed
* @return Immediate results as Tasks
*/
@Override
protected ArrayList<Task> execute(Operation operation, Term[] args, Memory memory) {
Term content = args[1];
Sentence sentence = new Sentence(content, Symbols.QUESTION_MARK, null, new Stamp(memory));
BudgetValue budget = new BudgetValue(Parameters.DEFAULT_QUESTION_PRIORITY, Parameters.DEFAULT_QUESTION_DURABILITY, 1);
return Lists.newArrayList(new Task(sentence, budget, true));
}
use of nars.entity.Sentence in project opennars by opennars.
the class Emotions method adjustBusy.
public void adjustBusy(float newValue, float weight, DerivationContext nal) {
busy += newValue * weight;
busy /= (1.0f + weight);
if (!enabled) {
return;
}
float frequency = -1;
if (Math.abs(busy - lastbusy) > CHANGE_THRESHOLD && nal.memory.time() - last_busy_time > change_steps_demanded) {
if (busy > Parameters.BUSY_EVENT_HIGHER_THRESHOLD && lastbusy <= Parameters.BUSY_EVENT_HIGHER_THRESHOLD) {
frequency = 1.0f;
}
if (busy < Parameters.BUSY_EVENT_LOWER_THRESHOLD && lastbusy >= Parameters.BUSY_EVENT_LOWER_THRESHOLD) {
frequency = 0.0f;
}
lastbusy = busy;
last_busy_time = nal.memory.time();
}
if (frequency != -1) {
// ok lets add an event now
Term predicate = SetInt.make(new Term("busy"));
Term subject = new Term("SELF");
Inheritance inh = Inheritance.make(subject, predicate);
TruthValue truth = new TruthValue(busy, Parameters.DEFAULT_JUDGMENT_CONFIDENCE);
Sentence s = new Sentence(inh, Symbols.JUDGMENT_MARK, truth, new Stamp(nal.memory));
s.stamp.setOccurrenceTime(nal.memory.time());
Task t = new Task(s, new BudgetValue(Parameters.DEFAULT_JUDGMENT_PRIORITY, Parameters.DEFAULT_JUDGMENT_DURABILITY, BudgetFunctions.truthToQuality(truth)), true);
nal.addTask(t, "emotion");
}
}
Aggregations