Search in sources :

Example 31 with Statement

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

the class SyllogisticRules method abdIndCom.

/**
 * {<M ==> S>, <M ==> P>} |- {<S ==> P>, <P ==> S>, <S <=> P>}
 *
 * @param term1 Subject of the first new task
 * @param term2 Predicate of the first new task
 * @param sentence1 The first premise
 * @param sentence2 The second premise
 * @param figure Locations of the shared term in premises --- can be
 * removed?
 * @param nal Reference to the memory
 */
static void abdIndCom(Term term1, Term term2, final Sentence sentence1, final Sentence sentence2, final int figure, final DerivationContext nal) {
    if (Statement.invalidStatement(term1, term2) || Statement.invalidPair(term1, term2)) {
        return;
    }
    int order1 = sentence1.term.getTemporalOrder();
    int order2 = sentence2.term.getTemporalOrder();
    int order = abdIndComOrder(order1, order2);
    Statement taskContent = (Statement) sentence1.term;
    TruthValue truth1 = null;
    TruthValue truth2 = null;
    TruthValue truth3 = null;
    BudgetValue budget1, budget2, budget3;
    TruthValue value1 = sentence1.truth;
    TruthValue value2 = sentence2.truth;
    if (sentence1.isQuestion()) {
        budget1 = BudgetFunctions.backward(value2, nal);
        budget2 = BudgetFunctions.backwardWeak(value2, nal);
        budget3 = BudgetFunctions.backward(value2, nal);
    } else if (sentence1.isQuest()) {
        budget1 = BudgetFunctions.backwardWeak(value2, nal);
        budget2 = BudgetFunctions.backward(value2, nal);
        budget3 = BudgetFunctions.backwardWeak(value2, nal);
    } else {
        if (sentence1.isGoal()) {
            // P --> S
            truth1 = TruthFunctions.desireStrong(value1, value2);
            // S --> P
            truth2 = TruthFunctions.desireWeak(value2, value1);
            // S <-> P
            truth3 = TruthFunctions.desireStrong(value1, value2);
        } else {
            // isJudgment
            // P --> S
            truth1 = TruthFunctions.abduction(value1, value2);
            // S --> P
            truth2 = TruthFunctions.abduction(value2, value1);
            // S <-> P
            truth3 = TruthFunctions.comparison(value1, value2);
        }
        budget1 = BudgetFunctions.forward(truth1, nal);
        budget2 = BudgetFunctions.forward(truth2, nal);
        budget3 = BudgetFunctions.forward(truth3, nal);
    }
    long delta2 = 0;
    while ((term2 instanceof Conjunction) && (((CompoundTerm) term2).term[0] instanceof Interval)) {
        Interval interval = (Interval) ((CompoundTerm) term2).term[0];
        delta2 += interval.time;
        term2 = ((CompoundTerm) term2).setComponent(0, null, nal.mem());
    }
    long delta1 = 0;
    while ((term1 instanceof Conjunction) && (((CompoundTerm) term1).term[0] instanceof Interval)) {
        Interval interval = (Interval) ((CompoundTerm) term1).term[0];
        delta1 += interval.time;
        term1 = ((CompoundTerm) term1).setComponent(0, null, nal.mem());
    }
    if (order != ORDER_INVALID) {
        nal.getTheNewStamp().setOccurrenceTime(delta1);
        nal.doublePremiseTask(Statement.make(taskContent, term1, term2, order), truth1, budget1, false, false);
        nal.getTheNewStamp().setOccurrenceTime(delta2);
        nal.doublePremiseTask(Statement.make(taskContent, term2, term1, reverseOrder(order)), truth2, budget2, false, false);
        nal.getTheNewStamp().setOccurrenceTime(delta1);
        nal.doublePremiseTask(Statement.makeSym(taskContent, term1, term2, order), truth3, budget3, false, false);
    }
    if (Parameters.BREAK_NAL_HOL_BOUNDARY && order1 == order2 && taskContent.isHigherOrderStatement() && sentence2.term.isHigherOrderStatement()) {
        /*  if(truth1!=null) 
                truth1=truth1.clone();
            if(truth2!=null) 
                truth2=truth2.clone();*/
        if (truth3 != null)
            truth3 = truth3.clone();
        /* nal.doublePremiseTask(
                Statement.make(NativeOperator.INHERITANCE, term1, term2), 
                    truth1, budget1.clone(),false, false);
            nal.doublePremiseTask(
                Statement.make(NativeOperator.INHERITANCE, term2, term1), 
                    truth2, budget2.clone(),false, false);*/
        nal.doublePremiseTask(Statement.make(NativeOperator.SIMILARITY, term1, term2, TemporalRules.ORDER_NONE), truth3, budget3.clone(), false, false);
    }
}
Also used : BudgetValue(nars.entity.BudgetValue) CompoundTerm(nars.language.CompoundTerm) Statement(nars.language.Statement) TruthValue(nars.entity.TruthValue) Conjunction(nars.language.Conjunction) Interval(nars.language.Interval)

Example 32 with Statement

use of nars.language.Statement 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

Statement (nars.language.Statement)32 CompoundTerm (nars.language.CompoundTerm)29 Term (nars.language.Term)28 BudgetValue (nars.entity.BudgetValue)21 TruthValue (nars.entity.TruthValue)20 Sentence (nars.entity.Sentence)13 Task (nars.entity.Task)10 Conjunction (nars.language.Conjunction)9 Inheritance (nars.language.Inheritance)9 Implication (nars.language.Implication)6 Equivalence (nars.language.Equivalence)5 Interval (nars.language.Interval)4 SetExt (nars.language.SetExt)4 SetInt (nars.language.SetInt)4 HashMap (java.util.HashMap)3 TruthFunctions.reduceConjunction (nars.inference.TruthFunctions.reduceConjunction)3 ImageExt (nars.language.ImageExt)3 ImageInt (nars.language.ImageInt)3 Product (nars.language.Product)3 Similarity (nars.language.Similarity)3