Search in sources :

Example 11 with Term

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());
    }
}
Also used : Item(nars.entity.Item) Term(nars.language.Term) LevelBag(nars.storage.LevelBag)

Example 12 with Term

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;
}
Also used : Concept(nars.entity.Concept) BudgetValue(nars.entity.BudgetValue) Term(nars.language.Term)

Example 13 with Term

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));
}
Also used : BudgetValue(nars.entity.BudgetValue) Task(nars.entity.Task) Stamp(nars.entity.Stamp) TruthValue(nars.entity.TruthValue) Term(nars.language.Term) Sentence(nars.entity.Sentence)

Example 14 with Term

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));
}
Also used : BudgetValue(nars.entity.BudgetValue) Task(nars.entity.Task) Stamp(nars.entity.Stamp) Term(nars.language.Term) Sentence(nars.entity.Sentence)

Example 15 with Term

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);
}
Also used : CompoundTerm(nars.language.CompoundTerm) SetExt(nars.language.SetExt) SetInt(nars.language.SetInt) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term)

Aggregations

Term (nars.language.Term)109 CompoundTerm (nars.language.CompoundTerm)66 BudgetValue (nars.entity.BudgetValue)48 TruthValue (nars.entity.TruthValue)46 Sentence (nars.entity.Sentence)40 Task (nars.entity.Task)37 Statement (nars.language.Statement)28 Conjunction (nars.language.Conjunction)20 Inheritance (nars.language.Inheritance)19 Stamp (nars.entity.Stamp)17 Concept (nars.entity.Concept)14 Implication (nars.language.Implication)13 Product (nars.language.Product)11 NAR (nars.main.NAR)9 Interval (nars.language.Interval)8 Test (org.junit.Test)8 HashMap (java.util.HashMap)7 SetExt (nars.language.SetExt)7 SetInt (nars.language.SetInt)7 Variable (nars.language.Variable)7