Search in sources :

Example 36 with Sentence

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

Example 37 with Sentence

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

Example 38 with Sentence

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

Example 39 with Sentence

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;
}
Also used : Tense(nars.language.Tense) 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 40 with Sentence

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