Search in sources :

Example 6 with Concept

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

the class ConceptMonitor method strongestPrecondition.

public static Sentence strongestPrecondition(NAR nar, String conc, String statement) {
    Concept c = ConceptMonitor.concept(nar, conc);
    Term st = stringToTerm(nar, statement);
    if (c != null && st != null) {
        for (Task t : c.executable_preconditions) {
            if (CompoundTerm.replaceIntervals(t.getTerm()).equals(CompoundTerm.replaceIntervals(st))) {
                return t.sentence;
            }
        }
    }
    return null;
}
Also used : Concept(nars.entity.Concept) Task(nars.entity.Task) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term)

Example 7 with Concept

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

the class Memory method conceptualize.

/**
 * Get the Concept associated to a Term, or create it.
 *
 *   Existing concept: apply tasklink activation (remove from bag, adjust budget, reinsert)
 *   New concept: set initial activation, insert
 *   Subconcept: extract from cache, apply activation, insert
 *
 * If failed to insert as a result of null bag, returns null
 *
 * A displaced Concept resulting from insert is forgotten (but may be stored in optional  subconcept memory
 *
 * @param term indicating the concept
 * @return an existing Concept, or a new one, or null
 */
public Concept conceptualize(final BudgetValue budget, Term term) {
    if (term instanceof Interval) {
        return null;
    }
    term = CompoundTerm.replaceIntervals(term);
    // see if concept is active
    Concept concept = concepts.take(term);
    if (concept == null) {
        // create new concept, with the applied budget
        concept = new Concept(budget, term, this);
        // if (memory.logic!=null)
        // memory.logic.CONCEPT_NEW.commit(term.getComplexity());
        emit(Events.ConceptNew.class, concept);
    } else if (concept != null) {
        // apply budget to existing concept
        // memory.logic.CONCEPT_ACTIVATE.commit(term.getComplexity());
        BudgetFunctions.activate(concept.budget, budget, BudgetFunctions.Activating.TaskLink);
    } else {
        // unable to create, ex: has variables
        return null;
    }
    Concept displaced = concepts.putBack(concept, cycles(param.conceptForgetDurations), this);
    if (displaced == null) {
        // added without replacing anything
        return concept;
    } else if (displaced == concept) {
        // not able to insert
        conceptRemoved(displaced);
        return null;
    } else {
        conceptRemoved(displaced);
        return concept;
    }
}
Also used : Concept(nars.entity.Concept) Events(nars.io.events.Events) Interval(nars.language.Interval)

Example 8 with Concept

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

the class Remind method execute.

/**
 * To activate a concept as if a question has been asked about it
 *
 * @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 term = args[1];
    Concept concept = memory.conceptualize(Consider.budgetMentalConcept(operation), term);
    BudgetValue budget = new BudgetValue(Parameters.DEFAULT_QUESTION_PRIORITY, Parameters.DEFAULT_QUESTION_DURABILITY, 1);
    activate(memory, concept, budget, Activating.TaskLink);
    return null;
}
Also used : Concept(nars.entity.Concept) BudgetValue(nars.entity.BudgetValue) Term(nars.language.Term)

Example 9 with Concept

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

the class ComplexEmotions method setEnabled.

@Override
public boolean setEnabled(NAR n, boolean enabled) {
    if (enabled) {
        Memory memory = n.memory;
        if (obs == null) {
            obs = new EventObserver() {

                @Override
                public void event(Class event, Object[] a) {
                    if (event != Events.TaskDerive.class && event != Events.InduceSucceedingEvent.class)
                        return;
                    Task future_task = (Task) a[0];
                    if (future_task.sentence.getOccurenceTime() > n.time()) {
                        Concept c = n.memory.concept(future_task.getTerm());
                        float true_expectation = 0.5f;
                        float false_expectation = 0.5f;
                        if (c != null) {
                            if (c.desires.size() > 0 && c.beliefs.size() > 0) {
                                // Fear:
                                if (future_task.sentence.truth.getExpectation() > true_expectation && c.desires.get(0).sentence.truth.getExpectation() < false_expectation) {
                                    // n.addInput("<(*,{SELF},fear) --> ^feel>. :|:");
                                    float weight = future_task.getPriority();
                                    float fear = solutionQuality(true, c.desires.get(0), future_task.sentence, memory);
                                    float newValue = fear * weight;
                                    fear += newValue * weight;
                                    fear /= 1.0f + weight;
                                    // incrase concept priority by fear value:
                                    Concept C1 = memory.concept(future_task.getTerm());
                                    if (C1 != null) {
                                        C1.incPriority(fear);
                                    }
                                    memory.emit(Answer.class, "Fear value=" + fear);
                                    System.out.println("Fear value=" + fear);
                                }
                            }
                        }
                    }
                }
            };
        }
        memory.event.set(obs, enabled, Events.InduceSucceedingEvent.class, Events.TaskDerive.class);
    }
    return true;
}
Also used : EventObserver(nars.io.events.EventEmitter.EventObserver) Concept(nars.entity.Concept) Answer(nars.io.events.Events.Answer) Task(nars.entity.Task) Events(nars.io.events.Events) Memory(nars.storage.Memory)

Example 10 with Concept

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

the class Consider method execute.

/**
 * To activate a concept as if a question has been asked about it
 *
 * @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 term = args[1];
    Concept concept = memory.conceptualize(Consider.budgetMentalConcept(operation), term);
    DerivationContext cont = new DerivationContext(memory);
    cont.setCurrentConcept(concept);
    GeneralInferenceControl.fireConcept(cont, 1);
    return null;
}
Also used : Concept(nars.entity.Concept) DerivationContext(nars.control.DerivationContext) Term(nars.language.Term)

Aggregations

Concept (nars.entity.Concept)30 Task (nars.entity.Task)18 Term (nars.language.Term)14 Sentence (nars.entity.Sentence)10 BudgetValue (nars.entity.BudgetValue)7 Events (nars.io.events.Events)6 CompoundTerm (nars.language.CompoundTerm)6 TruthValue (nars.entity.TruthValue)5 Interval (nars.language.Interval)4 ArrayList (java.util.ArrayList)3 Conjunction (nars.language.Conjunction)3 Color (java.awt.Color)2 HashSet (java.util.HashSet)2 LinkedList (java.util.LinkedList)2 DerivationContext (nars.control.DerivationContext)2 Item (nars.entity.Item)2 Stamp (nars.entity.Stamp)2 Implication (nars.language.Implication)2 NAR (nars.main.NAR)2 Memory (nars.storage.Memory)2