Search in sources :

Example 56 with Term

use of nars.language.Term in project opennars by opennars.

the class Concept method buildTermLinks.

/**
 * Recursively build TermLinks between a compound and its components
 * <p>
 * called only from Memory.continuedProcess
 *
 * @param taskBudget The BudgetValue of the task
 */
public void buildTermLinks(final BudgetValue taskBudget) {
    if (termLinkTemplates.size() == 0) {
        return;
    }
    BudgetValue subBudget = distributeAmongLinks(taskBudget, termLinkTemplates.size());
    if (!subBudget.aboveThreshold()) {
        return;
    }
    for (final TermLink template : termLinkTemplates) {
        if (template.type == TermLink.TRANSFORM) {
            continue;
        }
        Term target = template.target;
        final Concept concept = memory.conceptualize(taskBudget, target);
        if (concept == null) {
            continue;
        }
        // this termLink to that and vice versa
        insertTermLink(new TermLink(target, template, subBudget));
        concept.insertTermLink(new TermLink(term, template, subBudget));
        if (target instanceof CompoundTerm && template.type != TermLink.TEMPORAL) {
            concept.buildTermLinks(subBudget);
        }
    }
}
Also used : CompoundTerm(nars.language.CompoundTerm) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term)

Example 57 with Term

use of nars.language.Term 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)

Example 58 with Term

use of nars.language.Term in project opennars by opennars.

the class Operation method makeName.

public static CharSequence makeName(final CharSequence op, final Term[] arg) {
    final StringBuilder nameBuilder = // estimate
    new StringBuilder(16).append(COMPOUND_TERM_OPENER.ch).append(op);
    int n = 0;
    for (final Term t : arg) {
        /*if(n==arg.length-1) {
                break;
            }*/
        nameBuilder.append(Symbols.ARGUMENT_SEPARATOR);
        nameBuilder.append(t.name());
        n++;
    }
    nameBuilder.append(COMPOUND_TERM_CLOSER.ch);
    return nameBuilder.toString();
}
Also used : Term(nars.language.Term)

Example 59 with Term

use of nars.language.Term in project opennars by opennars.

the class Anticipate method updateAnticipations.

public void updateAnticipations() {
    if (anticipations.isEmpty())
        return;
    long now = nal.memory.time();
    // share stamps created by tasks in this cycle
    boolean hasNewTasks = !newTasks.isEmpty();
    Iterator<Map.Entry<Vector2Int, LinkedHashSet<Term>>> aei = anticipations.entrySet().iterator();
    while (aei.hasNext()) {
        Map.Entry<Vector2Int, LinkedHashSet<Term>> ae = aei.next();
        long aTime = ae.getKey().predictedOccurenceTime;
        long predictionstarted = ae.getKey().predictionCreationTime;
        if (aTime < predictionstarted) {
            // its about the past..
            return;
        }
        // lets say  a and <(&/,a,+4) =/> b> leaded to prediction of b with specific occurence time
        // this indicates that this interval can be reconstructed by looking by when the prediction
        // happened and for what time it predicted, Only when the happening would already lead to <(&/,a,+5) =/> b>
        // we are allowed to apply CWA already, i think this is the perfect time to do this
        // since there is no way anymore that the observation would support <(&/,a,+4) =/> b> at this time,
        // also this way it is not applied to early, it seems to be the perfect time to me,
        // making hopeExpirationWindow parameter entirely osbolete
        Interval Int = new Interval(aTime - predictionstarted);
        // ok we know the magnitude now, let's now construct a interval with magnitude one higher
        // (this we can skip because magnitudeToTime allows it without being explicitly constructed)
        // ok, and what predicted occurence time would that be? because only if now is bigger or equal, didnt happen is true
        double expiredate = predictionstarted + Int.time * Parameters.ANTICIPATION_TOLERANCE;
        // 
        boolean didntHappen = (now >= expiredate);
        boolean maybeHappened = hasNewTasks && !didntHappen;
        if ((!didntHappen) && (!maybeHappened))
            continue;
        LinkedHashSet<Term> terms = ae.getValue();
        Iterator<Term> ii = terms.iterator();
        while (ii.hasNext()) {
            Term aTerm = ii.next();
            boolean remove = false;
            if (didntHappen) {
                deriveDidntHappen(aTerm, aTime);
                remove = true;
            }
            if (maybeHappened) {
                if (newTasks.remove(aTerm)) {
                    // in case it happened, temporal induction will do the rest, else deriveDidntHappen occurred
                    if (!remove) {
                        nal.memory.emit(CONFIRM.class, aTerm);
                    }
                    remove = true;
                    hasNewTasks = !newTasks.isEmpty();
                }
            }
            if (remove)
                ii.remove();
        }
        if (terms.isEmpty()) {
            // remove this time entry because its terms have been emptied
            aei.remove();
        }
    }
    newTasks.clear();
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Term(nars.language.Term) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Interval(nars.language.Interval)

Example 60 with Term

use of nars.language.Term 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)

Aggregations

Term (nars.language.Term)109 CompoundTerm (nars.language.CompoundTerm)66 BudgetValue (nars.entity.BudgetValue)48 TruthValue (nars.entity.TruthValue)46 Sentence (nars.entity.Sentence)40 Task (nars.entity.Task)37 Statement (nars.language.Statement)28 Conjunction (nars.language.Conjunction)20 Inheritance (nars.language.Inheritance)19 Stamp (nars.entity.Stamp)17 Concept (nars.entity.Concept)14 Implication (nars.language.Implication)13 Product (nars.language.Product)11 NAR (nars.main.NAR)9 Interval (nars.language.Interval)8 Test (org.junit.Test)8 HashMap (java.util.HashMap)7 SetExt (nars.language.SetExt)7 SetInt (nars.language.SetInt)7 Variable (nars.language.Variable)7