use of nars.language.Term in project opennars by opennars.
the class BagOperationsTest method testBagSequence.
public static void testBagSequence(Bag b) {
// different id, different priority
b.putIn(makeConcept("a", 0.1f));
b.putIn(makeConcept("b", 0.15f));
assertEquals(2, b.size());
b.clear();
// same priority, different id
b.putIn(makeConcept("a", 0.1f));
b.putIn(makeConcept("b", 0.1f));
assertEquals(2, b.size());
b.putIn(makeConcept("c", 0.2f));
assertEquals(2, b.size());
assertEquals(0.1f, b.getMinPriority(), 0.001f);
assertEquals(0.2f, b.getMaxPriority(), 0.001f);
// if (b instanceof GearBag()) return;
b.putIn(makeConcept("b", 0.4f));
assertEquals(2, b.size());
assertEquals(0.2f, b.getMinPriority(), 0.001f);
assertEquals(0.4f, b.getMaxPriority(), 0.001f);
Item tb = b.take(new Term("b"));
assertTrue(tb != null);
assertEquals(1, b.size());
assertEquals(0.4f, tb.getPriority(), 0.001f);
Item tc = b.takeNext();
assertEquals(0, b.size());
assertEquals(0.2f, tc.getPriority(), 0.001f);
assertEquals(null, b.putIn(makeConcept("a", 0.2f)));
assertEquals(null, b.putIn(makeConcept("b", 0.3f)));
if (b instanceof LevelBag) {
// replaces item on level
assertEquals("a", b.putIn(makeConcept("c", 0.1f)).name().toString());
}
}
use of nars.language.Term in project opennars by opennars.
the class Remind method execute.
/**
* To activate a concept as if a question has been asked about it
*
* @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 term = args[1];
Concept concept = memory.conceptualize(Consider.budgetMentalConcept(operation), term);
BudgetValue budget = new BudgetValue(Parameters.DEFAULT_QUESTION_PRIORITY, Parameters.DEFAULT_QUESTION_DURABILITY, 1);
activate(memory, concept, budget, Activating.TaskLink);
return null;
}
use of nars.language.Term 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.language.Term 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.language.Term in project opennars by opennars.
the class Count method function.
@Override
protected Term function(Memory memory, Term[] x) {
if (x.length != 1) {
throw new RuntimeException(requireMessage);
}
Term content = x[0];
if (!(content instanceof SetExt) && !(content instanceof SetInt)) {
throw new RuntimeException(requireMessage);
}
int n = ((CompoundTerm) content).size();
return Term.get(n);
}
Aggregations