Search in sources :

Example 11 with Stamp

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

the class Name method execute.

/**
 * To create a judgment 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 compound = args[1];
    Term atomic = args[2];
    Similarity content = Similarity.make(compound, atomic);
    // a naming convension
    TruthValue truth = new TruthValue(1, 0.9999f);
    Sentence sentence = new Sentence(content, Symbols.JUDGMENT_MARK, truth, new Stamp(memory));
    BudgetValue budget = new BudgetValue(Parameters.DEFAULT_JUDGMENT_PRIORITY, Parameters.DEFAULT_JUDGMENT_DURABILITY, truth);
    return Lists.newArrayList(new Task(sentence, budget, true));
}
Also used : BudgetValue(nars.entity.BudgetValue) Task(nars.entity.Task) Similarity(nars.language.Similarity) Stamp(nars.entity.Stamp) TruthValue(nars.entity.TruthValue) Term(nars.language.Term) Sentence(nars.entity.Sentence)

Example 12 with Stamp

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

the class DerivationContext method setTheNewStamp.

/**
 * creates a lazy/deferred StampBuilder which only constructs the stamp if getTheNewStamp() is actually invoked
 */
public void setTheNewStamp(final Stamp first, final Stamp second, final long time) {
    newStamp = null;
    newStampBuilder = new StampBuilder() {

        @Override
        public Stamp build() {
            return new Stamp(first, second, time);
        }
    };
}
Also used : Stamp(nars.entity.Stamp)

Example 13 with Stamp

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

the class DerivationContext method singlePremiseTask.

/**
 * Shared final operations by all single-premise rules, called in
 * StructuralRules
 *
 * @param newContent The content of the sentence in task
 * @param punctuation The punctuation of the sentence in task
 * @param newTruth The truth value of the sentence in task
 * @param newBudget The budget value in task
 */
public boolean singlePremiseTask(final Term newContent, final char punctuation, final TruthValue newTruth, final BudgetValue newBudget) {
    if (!newBudget.aboveThreshold())
        return false;
    Sentence taskSentence = getCurrentTask().sentence;
    if (taskSentence.isGoal() || taskSentence.isJudgment() || getCurrentBelief() == null) {
        setTheNewStamp(new Stamp(taskSentence.stamp, getTime()));
    } else {
        // to answer a question with negation in NAL-5 --- move to activated task?
        setTheNewStamp(new Stamp(getCurrentBelief().stamp, getTime()));
    }
    if (newContent.subjectOrPredicateIsIndependentVar()) {
        return false;
    }
    if (newContent instanceof Interval) {
        return false;
    }
    Stamp derive_stamp = this.getTheNewStamp().clone();
    // stamp was already obsorbed into task
    this.resetOccurrenceTime();
    Sentence newSentence = new Sentence(newContent, punctuation, newTruth, derive_stamp);
    Task newTask = Task.make(newSentence, newBudget, getCurrentTask());
    if (newTask != null) {
        return derivedTask(newTask, false, true, false);
    }
    return false;
}
Also used : Task(nars.entity.Task) Stamp(nars.entity.Stamp) Sentence(nars.entity.Sentence) Interval(nars.language.Interval)

Example 14 with Stamp

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

the class DerivationContext method doublePremiseTask.

public List<Task> doublePremiseTask(final Term newContent, final TruthValue newTruth, final BudgetValue newBudget, boolean temporalInduction, boolean overlapAllowed, boolean addToMemory) {
    List<Task> ret = new ArrayList<Task>();
    if (newContent == null) {
        return null;
    }
    if (!newBudget.aboveThreshold()) {
        return null;
    }
    if ((newContent != null) && (!(newContent instanceof Interval)) && (!(newContent instanceof Variable))) {
        if (newContent.subjectOrPredicateIsIndependentVar()) {
            return null;
        }
        // because occurrence time will be reset:
        Stamp derive_stamp = getTheNewStamp().clone();
        // stamp was already obsorbed into task
        this.resetOccurrenceTime();
        try {
            final Sentence newSentence = new Sentence(newContent, getCurrentTask().sentence.punctuation, newTruth, derive_stamp);
            newSentence.producedByTemporalInduction = temporalInduction;
            final Task newTask = Task.make(newSentence, newBudget, getCurrentTask(), getCurrentBelief());
            if (newTask != null) {
                boolean added = derivedTask(newTask, false, false, overlapAllowed, addToMemory);
                if (added) {
                    ret.add(newTask);
                }
            }
        } catch (CompoundTerm.UnableToCloneException e) {
            return null;
        }
        // "Since in principle it is always valid to eternalize a tensed belief"
        if (temporalInduction && Parameters.IMMEDIATE_ETERNALIZATION) {
            try {
                TruthValue truthEt = TruthFunctions.eternalize(newTruth);
                Stamp st = derive_stamp.clone();
                st.setEternal();
                final Sentence newSentence = new Sentence(newContent, getCurrentTask().sentence.punctuation, truthEt, st);
                newSentence.producedByTemporalInduction = temporalInduction;
                final Task newTask = Task.make(newSentence, newBudget, getCurrentTask(), getCurrentBelief());
                if (newTask != null) {
                    boolean added = derivedTask(newTask, false, false, overlapAllowed, addToMemory);
                    if (added) {
                        ret.add(newTask);
                    }
                }
            } catch (CompoundTerm.UnableToCloneException e) {
                return null;
            }
        }
        return ret;
    }
    return null;
}
Also used : CompoundTerm(nars.language.CompoundTerm) Task(nars.entity.Task) Variable(nars.language.Variable) Stamp(nars.entity.Stamp) TruthValue(nars.entity.TruthValue) ArrayList(java.util.ArrayList) Sentence(nars.entity.Sentence) Interval(nars.language.Interval)

Example 15 with Stamp

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

the class FunctionOperator method execute.

// abstract protected int getMinArity();
// abstract protected int getMaxArity();
@Override
protected ArrayList<Task> execute(Operation operation, Term[] args, Memory m) {
    // TODO make memory access optional by constructor argument
    // TODO allow access to NAR instance?
    int numArgs = args.length - 1;
    if (numArgs < 1) {
        throw new RuntimeException("Requires at least 1 arguments");
    }
    if (numArgs < 2) /*&& !(this instanceof Javascript)*/
    {
        throw new RuntimeException("Requires at least 2 arguments");
    }
    // last argument a variable?
    Term lastTerm = args[numArgs];
    boolean variable = lastTerm instanceof Variable;
    if (!variable) /*&& !(this instanceof Javascript)*/
    {
        throw new RuntimeException("output can not be specified");
    }
    int numParam = numArgs - 1;
    /*if(this instanceof Javascript && !variable) {
            numParam++;
        }*/
    Term[] x = new Term[numParam];
    System.arraycopy(args, 1, x, 0, numParam);
    Term y;
    // try {
    y = function(m, x);
    if (y == null) {
        return null;
    }
    /*if(!variable && this instanceof Javascript) {
                return null;
            }*/
    // m.emit(SynchronousFunctionOperator.class, Arrays.toString(x) + " | " + y);
    /*}
        catch (Exception e) {
            throw e;
        }*/
    Variable var = new Variable("$1");
    // Term actual_part = Similarity.make(var, y);
    // Variable vardep=new Variable("#1");
    // Term actual_dep_part = Similarity.make(vardep, y);
    operation = (Operation) operation.setComponent(0, ((CompoundTerm) operation.getSubject()).setComponent(numArgs, y, m), m);
    float confidence = Parameters.DEFAULT_JUDGMENT_CONFIDENCE;
    if (variable) {
        Sentence s = new Sentence(operation, Symbols.JUDGMENT_MARK, new TruthValue(1.0f, Parameters.DEFAULT_JUDGMENT_CONFIDENCE), new Stamp(m));
        return Lists.newArrayList(new Task(s, new BudgetValue(Parameters.DEFAULT_JUDGMENT_PRIORITY, Parameters.DEFAULT_FEEDBACK_DURABILITY, truthToQuality(s.getTruth())), true));
    } else {
        return null;
    }
}
Also used : BudgetValue(nars.entity.BudgetValue) Task(nars.entity.Task) Variable(nars.language.Variable) Stamp(nars.entity.Stamp) TruthValue(nars.entity.TruthValue) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term) Sentence(nars.entity.Sentence)

Aggregations

Stamp (nars.entity.Stamp)28 Sentence (nars.entity.Sentence)25 Task (nars.entity.Task)25 BudgetValue (nars.entity.BudgetValue)22 TruthValue (nars.entity.TruthValue)18 Term (nars.language.Term)17 Interval (nars.language.Interval)5 Implication (nars.language.Implication)4 Variable (nars.language.Variable)4 Operation (nars.operator.Operation)4 ArrayList (java.util.ArrayList)3 CompoundTerm (nars.language.CompoundTerm)3 Conjunction (nars.language.Conjunction)3 Inheritance (nars.language.Inheritance)3 Concept (nars.entity.Concept)2 Narsese (nars.io.Narsese)2 Events (nars.io.events.Events)2 Equivalence (nars.language.Equivalence)2 Product (nars.language.Product)2 Memory (nars.storage.Memory)2