Search in sources :

Example 46 with CompoundTerm

use of nars.language.CompoundTerm in project opennars by opennars.

the class SyllogisticRules method elimiVarDep.

/**
 * {(&&, <#x() --> S>, <#x() --> P>>, <M --> P>} |- <M --> S>
 *
 * @param compound The compound term to be decomposed
 * @param component The part of the compound to be removed
 * @param compoundTask Whether the compound comes from the task
 * @param nal Reference to the memory
 */
static void elimiVarDep(CompoundTerm compound, Term component, boolean compoundTask, DerivationContext nal) {
    Term comp = null;
    for (Term t : compound) {
        Term[] unify = new Term[] { t, component };
        if (Variables.unify(Symbols.VAR_DEPENDENT, unify)) {
            comp = t;
            break;
        }
        if (Variables.unify(Symbols.VAR_QUERY, unify)) {
            comp = t;
            break;
        }
    }
    if (comp == null) {
        return;
    }
    Term content = reduceComponents(compound, comp, nal.mem());
    if ((content == null) || ((content instanceof Statement) && ((Statement) content).invalid())) {
        return;
    }
    Task task = nal.getCurrentTask();
    Sentence sentence = task.sentence;
    Sentence belief = nal.getCurrentBelief();
    TruthValue v1 = sentence.truth;
    TruthValue v2 = belief.truth;
    TruthValue truth = null;
    BudgetValue budget;
    if (sentence.isQuestion() || sentence.isQuest()) {
        budget = (compoundTask ? BudgetFunctions.backward(v2, nal) : BudgetFunctions.backwardWeak(v2, nal));
    } else {
        if (sentence.isGoal()) {
            // to check
            truth = (compoundTask ? TruthFunctions.desireDed(v1, v2) : TruthFunctions.desireInd(v1, v2));
        } else {
            truth = (compoundTask ? TruthFunctions.anonymousAnalogy(v1, v2) : TruthFunctions.anonymousAnalogy(v2, v1));
        }
        budget = BudgetFunctions.compoundForward(truth, content, nal);
    }
    nal.doublePremiseTask(content, truth, budget, false, false);
}
Also used : BudgetValue(nars.entity.BudgetValue) Task(nars.entity.Task) Statement(nars.language.Statement) TruthValue(nars.entity.TruthValue) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term) Sentence(nars.entity.Sentence)

Aggregations

CompoundTerm (nars.language.CompoundTerm)46 Term (nars.language.Term)43 TruthValue (nars.entity.TruthValue)30 BudgetValue (nars.entity.BudgetValue)27 Sentence (nars.entity.Sentence)20 Statement (nars.language.Statement)19 Conjunction (nars.language.Conjunction)18 Task (nars.entity.Task)17 Inheritance (nars.language.Inheritance)13 Implication (nars.language.Implication)8 HashMap (java.util.HashMap)7 Variable (nars.language.Variable)7 Interval (nars.language.Interval)6 SetExt (nars.language.SetExt)6 SetInt (nars.language.SetInt)6 Product (nars.language.Product)5 TruthFunctions.reduceConjunction (nars.inference.TruthFunctions.reduceConjunction)4 Equivalence (nars.language.Equivalence)4 ImageExt (nars.language.ImageExt)4 ImageInt (nars.language.ImageInt)4