use of nars.entity.BudgetValue in project opennars by opennars.
the class NAR method ask.
public NAR ask(String termString, AnswerHandler answered) throws InvalidInputException {
Task t;
addInput(t = new Task(new Sentence(new Narsese(this).parseTerm(termString), Symbols.QUESTION_MARK, null, new Stamp(memory, Tense.Eternal)), new BudgetValue(Parameters.DEFAULT_QUESTION_PRIORITY, Parameters.DEFAULT_QUESTION_DURABILITY, 1), true));
if (answered != null) {
answered.start(t, this);
}
return this;
}
use of nars.entity.BudgetValue in project opennars by opennars.
the class Narsese method parseTask.
/**
* Enter a new Task in String into the memory, called from InputWindow or
* locally.
*
* @param s the single-line addInput String
* @param memory Reference to the memory
* @param time The current time
* @return An experienced task
*/
public Task parseTask(String s) throws InvalidInputException {
StringBuilder buffer = new StringBuilder(Texts.escape(s));
String budgetString = getBudgetString(buffer);
String truthString = getTruthString(buffer);
Tense tense = parseTense(buffer);
String str = buffer.toString().trim();
int last = str.length() - 1;
char punc = str.charAt(last);
Stamp stamp = new Stamp(-1, /* if -1, will be set right before the Task is input */
tense, memory.newStampSerial(), Parameters.DURATION);
TruthValue truth = parseTruth(truthString, punc);
Term content = parseTerm(str.substring(0, last));
if (content == null)
throw new InvalidInputException("Content term missing");
Sentence sentence = new Sentence(content, punc, truth, stamp);
// if ((content instanceof Conjunction) && Variable.containVarDep(content.getName())) {
// sentence.setRevisible(false);
// }
BudgetValue budget = parseBudget(budgetString, punc, truth);
Task task = new Task(sentence, budget, true);
return task;
}
use of nars.entity.BudgetValue in project opennars by opennars.
the class BudgetFunctions method budgetInference.
/**
* Common processing for all inference step
*
* @param qual Quality of the inference
* @param complexity Syntactic complexity of the conclusion
* @param nal Reference to the memory
* @return Budget of the conclusion task
*/
private static BudgetValue budgetInference(final float qual, final float complexity, final nars.control.DerivationContext nal) {
Item t = nal.getCurrentTaskLink();
if (t == null) {
t = nal.getCurrentTask();
}
float priority = t.getPriority();
float durability = t.getDurability() / complexity;
final float quality = qual / complexity;
final TermLink bLink = nal.getCurrentBeliefLink();
if (bLink != null) {
priority = or(priority, bLink.getPriority());
durability = and(durability, bLink.getDurability());
final float targetActivation = conceptActivation(nal.memory, bLink.target);
bLink.incPriority(or(quality, targetActivation));
bLink.incDurability(quality);
}
return new BudgetValue(priority, durability, quality);
}
use of nars.entity.BudgetValue in project opennars by opennars.
the class BudgetFunctions method update.
/**
* Update a belief
*
* @param task The task containing new belief
* @param bTruth Truth value of the previous belief
* @return Budget value of the updating task
*/
static BudgetValue update(final Task task, final TruthValue bTruth) {
final TruthValue tTruth = task.sentence.truth;
final float dif = tTruth.getExpDifAbs(bTruth);
final float priority = or(dif, task.getPriority());
final float durability = aveAri(dif, task.getDurability());
final float quality = truthToQuality(bTruth);
return new BudgetValue(priority, durability, quality);
}
use of nars.entity.BudgetValue in project opennars by opennars.
the class Counting method setEnabled.
@Override
public boolean setEnabled(NAR n, boolean enabled) {
Memory memory = n.memory;
if (obs == null) {
obs = new EventObserver() {
@Override
public void event(Class event, Object[] a) {
if ((event != Events.TaskDerive.class && event != Events.TaskAdd.class))
return;
Task task = (Task) a[0];
if (task.getPriority() < InternalExperience.MINIMUM_PRIORITY_TO_CREATE_WANT_BELIEVE_ETC) {
return;
}
if (task.sentence.punctuation == Symbols.JUDGMENT_MARK) {
// lets say we have <{...} --> M>.
if (task.sentence.term instanceof Inheritance) {
Inheritance inh = (Inheritance) task.sentence.term;
if (inh.getSubject() instanceof SetExt) {
SetExt set_term = (SetExt) inh.getSubject();
// this gets the cardinality of M
int cardinality = set_term.size();
// now create term <(*,M,cardinality) --> CARDINALITY>.
Term[] product_args = new Term[] { inh.getPredicate(), Term.get(cardinality) };
// TODO CARDINATLITY can be a static final instance shared by all
Term new_term = Inheritance.make(new Product(product_args), /* --> */
CARDINALITY);
if (new_term == null) {
// this usually happens when product_args contains the term CARDINALITY in which case it is an invalid Inheritance statement
return;
}
TruthValue truth = task.sentence.truth.clone();
Stamp stampi = task.sentence.stamp.clone();
Sentence j = new Sentence(new_term, Symbols.JUDGMENT_MARK, truth, stampi);
BudgetValue budg = task.budget.clone();
Task newTask = new Task(j, budg, true);
memory.addNewTask(newTask, "Derived (Cardinality)");
}
}
}
}
};
}
memory.event.set(obs, enabled, Events.TaskDerive.class);
return true;
}
Aggregations