Search in sources :

Example 66 with Sentence

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

the class TextOutputHandler method getOutputString.

/**
 * generates a human-readable string from an output channel and signal
 */
public static CharSequence getOutputString(Class channel, Object signal, final boolean showStamp, final NAR nar, final StringBuilder buffer) {
    buffer.setLength(0);
    if (signal instanceof Exception) {
        Exception e = (Exception) signal;
        buffer.append(e.getClass().getSimpleName()).append(": ").append(e.getMessage());
        /*if (showStackTrace)*/
        {
            buffer.append(" ").append(Arrays.asList(e.getStackTrace()));
        }
    } else if (signal instanceof Task) {
        Task t = (Task) signal;
        Sentence s = t.sentence;
        buffer.append(s.toString(nar, showStamp));
    } else if (signal instanceof Sentence) {
        Sentence s = (Sentence) signal;
        buffer.append(s.toString(nar, showStamp));
    } else if (signal instanceof Object[]) {
        if (channel == Answer.class) {
            Object[] o = (Object[]) signal;
            Task task = (Task) o[0];
            Sentence belief = (Sentence) o[1];
            Sentence question = task.sentence;
            Sentence answer = belief;
            buffer.append(answer.toString(nar, showStamp));
        } else
            buffer.append(Arrays.toString((Object[]) signal));
    } else {
        buffer.append(signal.toString());
    }
    return Texts.unescape(buffer);
}
Also used : Answer(nars.io.events.Events.Answer) Task(nars.entity.Task) Sentence(nars.entity.Sentence) IOException(java.io.IOException)

Example 67 with Sentence

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

the class DerivationContext method doublePremiseTaskRevised.

/* --------------- new task building --------------- */
/**
 * Shared final operations by all double-premise rules, called from the
 * rules except StructuralRules
 *
 * @param newContent The content of the sentence in task
 * @param newTruth The truth value of the sentence in task
 * @param newBudget The budget value in task
 */
public boolean doublePremiseTaskRevised(final Term newContent, final TruthValue newTruth, final BudgetValue newBudget) {
    Stamp derived_stamp = getTheNewStamp().clone();
    // stamp was already obsorbed
    this.resetOccurrenceTime();
    Sentence newSentence = new Sentence(newContent, getCurrentTask().sentence.punctuation, newTruth, derived_stamp);
    Task newTask = new Task(newSentence, newBudget, getCurrentBelief());
    // allows overlap since overlap was already checked on revisable( function
    return derivedTask(newTask, true, false, true);
}
Also used : Task(nars.entity.Task) Stamp(nars.entity.Stamp) Sentence(nars.entity.Sentence)

Example 68 with Sentence

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

the class TemporalInferenceControl method proceedWithTemporalInduction.

public static List<Task> proceedWithTemporalInduction(final Sentence newEvent, final Sentence stmLast, Task controllerTask, DerivationContext nal, boolean SucceedingEventsInduction, boolean addToMemory, boolean allowSequence) {
    if (SucceedingEventsInduction && !controllerTask.isElemOfSequenceBuffer()) {
        // todo refine, add directbool in task
        return null;
    }
    if (newEvent.isEternal() || !controllerTask.isInput()) {
        return null;
    }
    if (newEvent.punctuation != Symbols.JUDGMENT_MARK || stmLast.punctuation != Symbols.JUDGMENT_MARK)
        // temporal inductions for judgements only
        return null;
    nal.setTheNewStamp(newEvent.stamp, stmLast.stamp, nal.memory.time());
    nal.setCurrentTask(controllerTask);
    Sentence previousBelief = stmLast;
    nal.setCurrentBelief(previousBelief);
    Sentence currentBelief = newEvent;
    // if(newEvent.getPriority()>Parameters.TEMPORAL_INDUCTION_MIN_PRIORITY)
    return TemporalRules.temporalInduction(currentBelief, previousBelief, nal, SucceedingEventsInduction, addToMemory, allowSequence);
}
Also used : Sentence(nars.entity.Sentence)

Example 69 with Sentence

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

the class Evaluate method execute.

/**
 * To create a quest 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.QUEST_MARK, null, new Stamp(memory));
    BudgetValue budget = new BudgetValue(Parameters.DEFAULT_QUEST_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 70 with Sentence

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

the class Feel method feeling.

/**
 * To get the current value of an internal sensor
 *
 * @param value The value to be checked, in [0, 1]
 * @param memory The memory in which the operation is executed
 * @return Immediate results as Tasks
 */
protected ArrayList<Task> feeling(float value, Memory memory) {
    Stamp stamp = new Stamp(memory, Tense.Present);
    TruthValue truth = new TruthValue(value, Parameters.DEFAULT_JUDGMENT_CONFIDENCE);
    Term predicate = new SetInt(feelingTerm);
    Term content = Inheritance.make(selfSubject, predicate);
    Sentence sentence = new Sentence(content, Symbols.JUDGMENT_MARK, truth, stamp);
    float quality = BudgetFunctions.truthToQuality(truth);
    BudgetValue budget = new BudgetValue(Parameters.DEFAULT_JUDGMENT_PRIORITY, Parameters.DEFAULT_JUDGMENT_DURABILITY, quality);
    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) SetInt(nars.language.SetInt) 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