use of nars.entity.Sentence in project opennars by opennars.
the class Anticipate method anticipationFeedback.
public void anticipationFeedback(Term content, Task t, Memory memory) {
if (anticipationOperator) {
Operation op = (Operation) Operation.make(Product.make(Term.SELF, content), this);
TruthValue truth = new TruthValue(1.0f, Parameters.DEFAULT_JUDGMENT_CONFIDENCE);
Stamp st;
if (t == null) {
st = new Stamp(memory);
} else {
st = t.sentence.stamp.clone();
st.setOccurrenceTime(memory.time());
}
Sentence s = new Sentence(op, Symbols.JUDGMENT_MARK, truth, st);
Task newTask = new Task(s, new BudgetValue(Parameters.DEFAULT_JUDGMENT_PRIORITY * InternalExperience.INTERNAL_EXPERIENCE_PRIORITY_MUL, Parameters.DEFAULT_JUDGMENT_DURABILITY * InternalExperience.INTERNAL_EXPERIENCE_DURABILITY_MUL, BudgetFunctions.truthToQuality(truth)), true);
memory.addNewTask(newTask, "Perceived (Internal Experience: Anticipation)");
}
}
use of nars.entity.Sentence in project opennars by opennars.
the class Terms method prepareComponentLinks.
/**
* Collect TermLink templates into a list, go down one level except in
* special cases
* <p>
*
* @param componentLinks The list of TermLink templates built so far
* @param type The type of TermLink to be built
* @param term The CompoundTerm for which the links are built
*/
public static ArrayList<TermLink> prepareComponentLinks(final ArrayList<TermLink> componentLinks, final short type, final CompoundTerm t) {
boolean tEquivalence = (t instanceof Equivalence);
boolean tImplication = (t instanceof Implication);
for (int i = 0; i < t.size(); i++) {
Term t1 = t.term[i];
t1 = new Sentence(t1, Symbols.TERM_NORMALIZING_WORKAROUND_MARK, null, null).term;
if (!(t1 instanceof Variable)) {
componentLinks.add(new TermLink(type, t1, i));
}
if ((tEquivalence || (tImplication && (i == 0))) && ((t1 instanceof Conjunction) || (t1 instanceof Negation))) {
prepareComponentLinks(componentLinks, TermLink.COMPOUND_CONDITION, (CompoundTerm) t1);
} else if (t1 instanceof CompoundTerm) {
final CompoundTerm ct1 = (CompoundTerm) t1;
// cache because this loop is critical
final int ct1Size = ct1.size();
boolean t1ProductOrImage = (t1 instanceof Product) || (t1 instanceof ImageExt) || (t1 instanceof ImageInt);
for (int j = 0; j < ct1Size; j++) {
Term t2 = ct1.term[j];
t2 = new Sentence(t2, Symbols.TERM_NORMALIZING_WORKAROUND_MARK, null, null).term;
if (!t2.hasVar()) {
if (t1ProductOrImage) {
if (type == TermLink.COMPOUND_CONDITION) {
componentLinks.add(new TermLink(TermLink.TRANSFORM, t2, 0, i, j));
} else {
componentLinks.add(new TermLink(TermLink.TRANSFORM, t2, i, j));
}
} else {
componentLinks.add(new TermLink(type, t2, i, j));
}
}
if ((t2 instanceof Product) || (t2 instanceof ImageExt) || (t2 instanceof ImageInt)) {
CompoundTerm ct2 = (CompoundTerm) t2;
final int ct2Size = ct2.size();
for (int k = 0; k < ct2Size; k++) {
Term t3 = ct2.term[k];
t3 = new Sentence(t3, Symbols.TERM_NORMALIZING_WORKAROUND_MARK, null, null).term;
if (!t3.hasVar()) {
if (type == TermLink.COMPOUND_CONDITION) {
componentLinks.add(new TermLink(TermLink.TRANSFORM, t3, 0, i, j, k));
} else {
componentLinks.add(new TermLink(TermLink.TRANSFORM, t3, i, j, k));
}
}
}
}
}
}
}
return componentLinks;
}
use of nars.entity.Sentence 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.Sentence 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.Sentence in project opennars by opennars.
the class AnswerHandler method event.
@Override
public void event(Class event, Object[] args) {
if (event == Answer.class) {
Task task = (Task) args[0];
Sentence belief = (Sentence) args[1];
if (task.equals(question)) {
onSolution(belief);
}
}
}
Aggregations