Search in sources :

Example 36 with Concept

use of nars.concept.Concept in project narchy by automenta.

the class Abbreviation method input.

private void input(Prioritized b, Consumer<PLink<Compound>> each, Compound t, float scale, NAR nar) {
    int vol = t.volume();
    if (vol < volume.lo())
        return;
    if (vol <= volume.hi()) {
        if (t.concept().equals(t)) /* identical to its conceptualize */
        {
            Concept abbreviable = nar.concept(t);
            if ((abbreviable != null) && !(abbreviable instanceof PermanentConcept) && abbreviable.meta("abbr") == null) {
                each.accept(new PLink<>(t, b.priElseZero()));
            }
        }
    } else {
        // recursiely try subterms of a temporal or exceedingly large concept
        // budget with a proportion of this compound relative to their volume contribution
        float subScale = 1f / (1 + t.subs());
        t.forEach(x -> {
            if (x.subs() > 0)
                input(b, each, ((Compound) x), subScale, nar);
        });
    }
}
Also used : Concept(nars.concept.Concept) PermanentConcept(nars.concept.PermanentConcept) PermanentConcept(nars.concept.PermanentConcept)

Example 37 with Concept

use of nars.concept.Concept in project narchy by automenta.

the class Abbreviation method abbreviate.

// private float scoreIfExceeds(Budget task, float min) {
// float s = or(task.priIfFiniteElseZero(), task.qua());
// if (s >= min) {
// s *= abbreviationProbability.floatValue();
// if (s >= min) {
// 
// //higher probability for terms nearer the thresh. smaller and larger get less chance
// //                s *= 1f - unitize(
// //                        Math.abs(task.volume() - volThresh) /
// //                                (threshFalloffRate) );
// 
// if (s >= min)
// return s;
// }
// }
// return -1;
// }
// private boolean createRelation = false;
protected boolean abbreviate(@NotNull Compound abbreviated, @NotNull Prioritized b, NAR nar) {
    @Nullable Concept abbrConcept = nar.concept(abbreviated);
    if (abbrConcept != null && !(abbrConcept instanceof AliasConcept) && !(abbrConcept instanceof PermanentConcept)) {
        final boolean[] succ = { false };
        abbrConcept.meta("abbr", (ac) -> {
            Term abbreviatedTerm = abbreviated.term();
            AliasConcept a1 = new AliasConcept(newSerialTerm(), abbrConcept, nar);
            nar.on(a1);
            // set the abbreviated term to resolve to the abbreviation
            nar.concepts.set(abbreviated.term(), a1);
            if (!abbreviatedTerm.equals(abbreviated.term()))
                // set the abbreviated term to resolve to the abbreviation
                nar.concepts.set(abbreviatedTerm, a1);
            // Compound abbreviation = newRelation(abbreviated, id);
            // if (abbreviation == null)
            // return null; //maybe could happen
            // 
            // Task abbreviationTask = Task.tryTask(abbreviation, BELIEF, $.t(1f, abbreviationConfidence.floatValue()),
            // (te, tr) -> {
            // 
            // NALTask ta = new NALTask(
            // te, BELIEF, tr,
            // nar.time(), ETERNAL, ETERNAL,
            // new long[]{nar.time.nextStamp()}
            // );
            // 
            // 
            // ta.meta(Abbreviation.class, new Term[]{abbreviatedTerm, aliasTerm.term()});
            // ta.log("Abbreviate"); //, abbreviatedTerm, aliasTerm
            // ta.setPri(b);
            // 
            // nar.runLater(()->nar.input(ta));
            logger.info("{} => {}", a1, abbreviatedTerm);
            // 
            // 
            // return ta;
            // 
            // //if (abbreviation != null) {
            // 
            // //logger.info("{} <=== {}", alias, abbreviatedTerm);
            // 
            // });
            // abbreviationTask.priority();
            // if (srcCopy == null) {
            // delete();
            // } else {
            // float p = srcCopy.priSafe(-1);
            // if (p < 0) {
            // delete();
            // } else {
            // setPriority(p);
            // }
            // }
            // 
            // return this;
            succ[0] = true;
            return a1;
        });
        return succ[0];
    }
    return false;
}
Also used : Concept(nars.concept.Concept) PermanentConcept(nars.concept.PermanentConcept) PermanentConcept(nars.concept.PermanentConcept) Term(nars.term.Term) Nullable(org.jetbrains.annotations.Nullable)

Example 38 with Concept

use of nars.concept.Concept in project narchy by automenta.

the class ConceptIndex method onRemove.

protected final void onRemove(Termed value) {
    if (value instanceof Concept) {
        if (value instanceof PermanentConcept) {
            // refuse deletion
            nar.runLater(() -> {
                set(value);
            });
        } else {
            Concept c = (Concept) value;
            if (c instanceof TaskConcept)
                forget((TaskConcept) c);
            c.delete(nar);
        }
    }
}
Also used : TaskConcept(nars.concept.TaskConcept) Concept(nars.concept.Concept) PermanentConcept(nars.concept.PermanentConcept) PermanentConcept(nars.concept.PermanentConcept) TaskConcept(nars.concept.TaskConcept)

Example 39 with Concept

use of nars.concept.Concept in project narchy by automenta.

the class STMLinkage method link.

protected static void link(Task ta, float pri, Task tb, short cid, NAR nar) {
    /**
     * current task's...
     */
    Concept ca = ta.concept(nar, true);
    if (ca != null) {
        Concept cb = tb.concept(nar, true);
        if (cb != null) {
            if (!cb.equals(ca)) {
                // null or same concept?
                // TODO handle overflow?
                cb.termlinks().putAsync(new CauseLink.PriCauseLink(ca.term(), pri, cid));
                ca.termlinks().putAsync(new CauseLink.PriCauseLink(cb.term(), pri, cid));
            // //tasklinks, not sure:
            // Tasklinks.linkTask(ta, interStrength, cb);
            // Tasklinks.linkTask(tb, interStrength, ca);
            } else {
                // create a self-termlink
                ca.termlinks().putAsync(new CauseLink.PriCauseLink(ca.term(), pri, cid));
            }
        }
    }
}
Also used : Concept(nars.concept.Concept) CauseLink(nars.link.CauseLink)

Example 40 with Concept

use of nars.concept.Concept in project narchy by automenta.

the class LinkageTest method linksIndirectly.

boolean linksIndirectly(@NotNull Concept src, @NotNull Concept target, @NotNull NAR nar) {
    for (PriReference<Term> entry : src.termlinks()) {
        // test 1st level link
        Term w = entry.get();
        if (target.equals(w))
            return true;
        Concept ww = nar.concept(w);
        if (ww != null) {
            if (target.equals(ww)) {
                return true;
            }
            // test 2nd level link
            for (PriReference<Term> entry2 : ww.termlinks()) {
                Term e = entry2.get();
                if (target.equals(e))
                    return true;
                Concept ee = nar.concept(e);
                if (ee != null && target.equals(ee))
                    return true;
            }
        }
    }
    return false;
}
Also used : Concept(nars.concept.Concept) Term(nars.term.Term)

Aggregations

Concept (nars.concept.Concept)47 TaskConcept (nars.concept.TaskConcept)19 Term (nars.term.Term)19 Test (org.junit.jupiter.api.Test)15 Nullable (org.jetbrains.annotations.Nullable)11 Truth (nars.truth.Truth)9 NAR (nars.NAR)6 Termed (nars.term.Termed)6 FasterList (jcog.list.FasterList)4 PermanentConcept (nars.concept.PermanentConcept)4 BeliefTable (nars.table.BeliefTable)4 TestNAR (nars.test.TestNAR)4 Util (jcog.Util)3 PriReference (jcog.pri.PriReference)3 GL2 (com.jogamp.opengl.GL2)2 java.io (java.io)2 java.util (java.util)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Op (nars.Op)2 CauseLink (nars.link.CauseLink)2