Search in sources :

Example 1 with PermanentConcept

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

the class TreeConceptIndex method set.

@Override
public void set(Term src, Termed target) {
    @NotNull TermKey k = key(src);
    concepts.acquireWriteLock();
    try {
        // TODO cache ref to where this resolved to accelerate the put() below
        Termed existing = concepts.get(k);
        if (existing != target && !(existing instanceof PermanentConcept)) {
            concepts.put(k, target);
        }
    } finally {
        concepts.releaseWriteLock();
    }
}
Also used : Termed(nars.term.Termed) PermanentConcept(nars.concept.PermanentConcept) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with PermanentConcept

use of nars.concept.PermanentConcept 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 3 with PermanentConcept

use of nars.concept.PermanentConcept 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 4 with PermanentConcept

use of nars.concept.PermanentConcept 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)

Aggregations

PermanentConcept (nars.concept.PermanentConcept)4 Concept (nars.concept.Concept)3 TaskConcept (nars.concept.TaskConcept)1 Term (nars.term.Term)1 Termed (nars.term.Termed)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1