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;
}
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;
}
}
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;
}
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;
}
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;
}
Aggregations