Search in sources :

Example 6 with Task

use of nars.entity.Task 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 Task

use of nars.entity.Task in project opennars by opennars.

the class ConcatVisionChannel method step_start.

@Override
public void step_start() {
    Position samplePos = sampling.get(0);
    Task current = inputs[samplePos.Y][samplePos.X];
    int k = 0;
    for (int i = 1; i < sampling.size(); i++) {
        Position samplePos2 = sampling.get(i);
        Task prem2 = inputs[samplePos2.Y][samplePos2.X];
        List<Task> seq = proceedWithTemporalInduction(current.sentence, prem2.sentence, prem2, new DerivationContext(nar.memory), true, false, true);
        if (seq != null) {
            for (Task t : seq) {
                if (!t.sentence.isEternal()) {
                    // TODO improve API, this check should not be necessary
                    current = t;
                    break;
                }
            }
        }
        k++;
    }
    System.out.println(k);
    System.out.println(current);
    // feeds results into "upper" sensory channels:
    this.results.add(current);
    this.step_finished();
}
Also used : Task(nars.entity.Task) DerivationContext(nars.control.DerivationContext)

Example 8 with Task

use of nars.entity.Task in project opennars by opennars.

the class Memory method inputTask.

/* There are several types of new tasks, all added into the
     newTasks list, to be processed in the next cycleMemory.
     Some of them are reported and/or logged. */
/**
 * Input task processing. Invoked by the outside or inside environment.
 * Outside: StringParser (addInput); Inside: InnateOperator (feedback). Input
 * tasks with low priority are ignored, and the others are put into task
 * buffer.
 *
 * @param t The addInput task
 */
public void inputTask(final Task t, boolean emitIn) {
    if (!checked) {
        checked = true;
        isjUnit = isJUnitTest();
    }
    if (t instanceof Task) {
        Task task = (Task) t;
        Stamp s = task.sentence.stamp;
        if (s.getCreationTime() == -1)
            s.setCreationTime(time(), Parameters.DURATION);
        if (emitIn) {
            emit(IN.class, task);
        }
        if (task.budget.aboveThreshold()) {
            addNewTask(task, "Perceived");
        } else {
            removeTask(task, "Neglected");
        }
    }
}
Also used : Task(nars.entity.Task) Stamp(nars.entity.Stamp)

Example 9 with Task

use of nars.entity.Task 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 10 with Task

use of nars.entity.Task 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)

Aggregations

Task (nars.entity.Task)78 Sentence (nars.entity.Sentence)54 Term (nars.language.Term)37 BudgetValue (nars.entity.BudgetValue)36 TruthValue (nars.entity.TruthValue)34 Stamp (nars.entity.Stamp)25 CompoundTerm (nars.language.CompoundTerm)21 Concept (nars.entity.Concept)18 Conjunction (nars.language.Conjunction)11 Statement (nars.language.Statement)10 Events (nars.io.events.Events)8 Inheritance (nars.language.Inheritance)8 Interval (nars.language.Interval)8 Narsese (nars.io.Narsese)6 SetExt (nars.language.SetExt)6 SetInt (nars.language.SetInt)6 ArrayList (java.util.ArrayList)5 DerivationContext (nars.control.DerivationContext)5 Implication (nars.language.Implication)5 Memory (nars.storage.Memory)5