Search in sources :

Example 6 with Sentence

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;
}
Also used : Task(nars.entity.Task) ExecutionResult(nars.operator.Operator.ExecutionResult) Sentence(nars.entity.Sentence)

Example 7 with Sentence

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

Example 8 with Sentence

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));
}
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 9 with Sentence

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

Example 10 with Sentence

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

Aggregations

Sentence (nars.entity.Sentence)70 Task (nars.entity.Task)54 Term (nars.language.Term)40 BudgetValue (nars.entity.BudgetValue)39 TruthValue (nars.entity.TruthValue)39 Stamp (nars.entity.Stamp)25 CompoundTerm (nars.language.CompoundTerm)24 Statement (nars.language.Statement)13 Conjunction (nars.language.Conjunction)11 Concept (nars.entity.Concept)10 Implication (nars.language.Implication)10 Inheritance (nars.language.Inheritance)8 Interval (nars.language.Interval)8 ArrayList (java.util.ArrayList)6 Equivalence (nars.language.Equivalence)6 HashMap (java.util.HashMap)5 AnswerHandler (nars.io.events.AnswerHandler)5 NARSwing (nars.gui.NARSwing)4 Narsese (nars.io.Narsese)4 Product (nars.language.Product)4