Search in sources :

Example 1 with TermLink

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

the class GeneralInferenceControl method fireTaskLink.

protected static void fireTaskLink(DerivationContext nal, int termLinks) {
    final Task task = nal.currentTaskLink.getTarget();
    nal.setCurrentTerm(nal.currentConcept.term);
    nal.setCurrentTaskLink(nal.currentTaskLink);
    nal.setCurrentBeliefLink(null);
    // one of the two places where this variable is set
    nal.setCurrentTask(task);
    nal.memory.emotion.adjustBusy(nal.currentTaskLink.getPriority(), nal.currentTaskLink.getDurability(), nal);
    if (nal.currentTaskLink.type == TermLink.TRANSFORM) {
        nal.setCurrentBelief(null);
        // TermLink tasklink_as_termlink = new TermLink(nal.currentTaskLink.getTerm(), TermLink.TRANSFORM, nal.getCurrentTaskLink().index);
        // if(nal.currentTaskLink.novel(tasklink_as_termlink, nal.memory.time(), true)) { //then record yourself, but also here novelty counts
        // to turn this into structural inference as below?
        RuleTables.transformTask(nal.currentTaskLink, nal);
    // }
    } else {
        while (termLinks > 0) {
            final TermLink termLink = nal.currentConcept.selectTermLink(nal.currentTaskLink, nal.memory.time());
            if (termLink == null) {
                break;
            }
            fireTermlink(termLink, nal);
            nal.currentConcept.returnTermLink(termLink);
            termLinks--;
        }
    }
    nal.memory.emit(Events.ConceptFire.class, nal);
// memory.logic.TASKLINK_FIRE.commit(currentTaskLink.budget.getPriority());
}
Also used : Task(nars.entity.Task) TermLink(nars.entity.TermLink) Events(nars.io.events.Events)

Example 2 with TermLink

use of nars.entity.TermLink 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 3 with TermLink

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

the class BudgetFunctions method budgetInference.

/**
 * Common processing for all inference step
 *
 * @param qual Quality of the inference
 * @param complexity Syntactic complexity of the conclusion
 * @param nal Reference to the memory
 * @return Budget of the conclusion task
 */
private static BudgetValue budgetInference(final float qual, final float complexity, final nars.control.DerivationContext nal) {
    Item t = nal.getCurrentTaskLink();
    if (t == null) {
        t = nal.getCurrentTask();
    }
    float priority = t.getPriority();
    float durability = t.getDurability() / complexity;
    final float quality = qual / complexity;
    final TermLink bLink = nal.getCurrentBeliefLink();
    if (bLink != null) {
        priority = or(priority, bLink.getPriority());
        durability = and(durability, bLink.getDurability());
        final float targetActivation = conceptActivation(nal.memory, bLink.target);
        bLink.incPriority(or(quality, targetActivation));
        bLink.incDurability(quality);
    }
    return new BudgetValue(priority, durability, quality);
}
Also used : BudgetValue(nars.entity.BudgetValue) Item(nars.entity.Item) TermLink(nars.entity.TermLink)

Example 4 with TermLink

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

the class NARGraphDisplay method edge.

@Override
public void edge(AbstractGraphVis<V, E> g, EdgeVis<V, E> e) {
    E edge = e.edge;
    int color = defaultEdgeColor;
    float thickness = lineWidth;
    if (edge instanceof NARGraph.TermLinkEdge) {
        TermLink t = ((NARGraph.TermLinkEdge) edge).getObject();
        float p = t.getPriority();
        thickness = (1 + p) * lineWidth;
        color = Video.color(255f * (0.5f + p * 0.5f), 255f * (0.5f + p * 0.5f), 125f, 255f * (0.5f + p * 0.5f));
    }
    if (edge instanceof NARGraph.TaskLinkEdge) {
        TaskLink t = ((NARGraph.TaskLinkEdge) edge).getObject();
        float p = t.targetTask.getPriority();
        thickness = (1 + p) * lineWidth;
        color = Video.color(125f, 255f * (0.5f + p * 0.5f), 125f, 255f * (0.5f + p * 0.5f));
    }
    e.color = color;
    e.thickness = thickness;
}
Also used : TermLink(nars.entity.TermLink) TaskLink(nars.entity.TaskLink)

Example 5 with TermLink

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

the class DefaultGraphizer method onFinish.

@Override
public void onFinish(NARGraph g) {
    if (includeSyntax > 0) {
        for (final Term a : terms.keySet()) {
            if (a instanceof CompoundTerm) {
                CompoundTerm c = (CompoundTerm) a;
                g.addVertex(c.operator());
                g.addEdge(c.operator(), c, new NARGraph.TermType());
                if (includeSyntax - 1 > 0) {
                    recurseTermComponents(g, c, includeSyntax - 1);
                }
            }
        }
    }
    if (includeTermContent) {
        for (final Term a : terms.keySet()) {
            for (final Term b : terms.keySet()) {
                if (a == b) {
                    continue;
                }
                if (a.containsTerm(b)) {
                    g.addVertex(a);
                    g.addVertex(b);
                    g.addEdge(a, b, new NARGraph.TermContent());
                }
                if (b.containsTerm(a)) {
                    g.addVertex(a);
                    g.addVertex(b);
                    g.addEdge(b, a, new NARGraph.TermContent());
                }
            }
        }
    }
    if (includeDerivations && includeBeliefs) {
        for (final Map.Entry<Sentence, Concept> s : sentenceTerms.entrySet()) {
            final Sentence derivedSentence = s.getKey();
            final Concept derived = s.getValue();
            for (final Map.Entry<Sentence, Concept> t : sentenceTerms.entrySet()) {
                if (s == t) {
                    continue;
                }
                final Sentence deriverSentence = t.getKey();
                final Concept deriver = t.getValue();
                if (derived == deriver) {
                    continue;
                }
            }
        }
    }
    if (includeTermLinks) {
        for (Map.Entry<TermLink, Concept> et : termLinks.entrySet()) {
            TermLink t = et.getKey();
            Concept from = et.getValue();
            Concept to = terms.get(t.target);
            if (to != null) {
                g.addEdge(from, to, new NARGraph.TermLinkEdge(t));
            }
        }
    }
    if (includeTaskLinks) {
        for (Map.Entry<TaskLink, Concept> et : taskLinks.entrySet()) {
            TaskLink t = et.getKey();
            if (this.taskPriorityThreshold != null && t.getPriority() > this.taskPriorityThreshold.get()) {
                Concept from = et.getValue();
                if (t.targetTask != null) {
                    Task theTask = t.targetTask;
                    if (!g.containsVertex(theTask)) {
                        g.addVertex(theTask);
                        Term term = theTask.getTerm();
                        if (term != null) {
                            Concept c = terms.get(term);
                            if (c != null) {
                                if (g.containsVertex(c)) {
                                    g.addVertex(c);
                                }
                                g.addEdge(c, theTask, new NARGraph.TermContent());
                            }
                        }
                        onTask(theTask);
                    }
                    g.addEdge(from, t.targetTask, new NARGraph.TaskLinkEdge(t));
                }
            }
        }
    }
}
Also used : CompoundTerm(nars.language.CompoundTerm) Concept(nars.entity.Concept) TermLink(nars.entity.TermLink) Task(nars.entity.Task) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term) TaskLink(nars.entity.TaskLink) Map(java.util.Map) HashMap(java.util.HashMap) Sentence(nars.entity.Sentence)

Aggregations

TermLink (nars.entity.TermLink)8 TaskLink (nars.entity.TaskLink)5 Task (nars.entity.Task)4 BudgetValue (nars.entity.BudgetValue)3 Sentence (nars.entity.Sentence)3 CompoundTerm (nars.language.CompoundTerm)2 Term (nars.language.Term)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Concept (nars.entity.Concept)1 Item (nars.entity.Item)1 Events (nars.io.events.Events)1