Search in sources :

Example 1 with Disjunction

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

the class CompositionalRules method decomposeCompound.

/**
 * {<(S|P) ==> M>, <P ==> M>} |- <S ==> M>
 *
 * @param implication The implication term to be decomposed
 * @param componentCommon The part of the implication to be removed
 * @param term1 The other term in the contentInd
 * @param index The location of the shared term: 0 for subject, 1 for
 * predicate
 * @param compoundTask Whether the implication comes from the task
 * @param nal Reference to the memory
 */
private static void decomposeCompound(CompoundTerm compound, Term component, Term term1, int index, boolean compoundTask, int order, DerivationContext nal) {
    if ((compound instanceof Statement) || (compound instanceof ImageExt) || (compound instanceof ImageInt)) {
        return;
    }
    Term term2 = reduceComponents(compound, component, nal.mem());
    if (term2 == null) {
        return;
    }
    long delta = 0;
    while ((term2 instanceof Conjunction) && (((CompoundTerm) term2).term[0] instanceof Interval)) {
        Interval interval = (Interval) ((CompoundTerm) term2).term[0];
        delta += interval.time;
        term2 = ((CompoundTerm) term2).setComponent(0, null, nal.mem());
    }
    Task task = nal.getCurrentTask();
    Sentence sentence = task.sentence;
    Sentence belief = nal.getCurrentBelief();
    Statement oldContent = (Statement) task.getTerm();
    TruthValue v1, v2;
    if (compoundTask) {
        v1 = sentence.truth;
        v2 = belief.truth;
    } else {
        v1 = belief.truth;
        v2 = sentence.truth;
    }
    TruthValue truth = null;
    Term content;
    if (index == 0) {
        content = Statement.make(oldContent, term1, term2, order);
        if (content == null) {
            return;
        }
        if (oldContent instanceof Inheritance) {
            if (compound instanceof IntersectionExt) {
                truth = reduceConjunction(v1, v2);
            } else if (compound instanceof IntersectionInt) {
                truth = reduceDisjunction(v1, v2);
            } else if ((compound instanceof SetInt) && (component instanceof SetInt)) {
                truth = reduceConjunction(v1, v2);
            } else if ((compound instanceof SetExt) && (component instanceof SetExt)) {
                truth = reduceDisjunction(v1, v2);
            } else if (compound instanceof DifferenceExt) {
                if (compound.term[0].equals(component)) {
                    truth = reduceDisjunction(v2, v1);
                } else {
                    truth = reduceConjunctionNeg(v1, v2);
                }
            }
        } else if (oldContent instanceof Implication) {
            if (compound instanceof Conjunction) {
                truth = reduceConjunction(v1, v2);
            } else if (compound instanceof Disjunction) {
                truth = reduceDisjunction(v1, v2);
            }
        }
    } else {
        content = Statement.make(oldContent, term2, term1, order);
        if (content == null) {
            return;
        }
        if (oldContent instanceof Inheritance) {
            if (compound instanceof IntersectionInt) {
                truth = reduceConjunction(v1, v2);
            } else if (compound instanceof IntersectionExt) {
                truth = reduceDisjunction(v1, v2);
            } else if ((compound instanceof SetExt) && (component instanceof SetExt)) {
                truth = reduceConjunction(v1, v2);
            } else if ((compound instanceof SetInt) && (component instanceof SetInt)) {
                truth = reduceDisjunction(v1, v2);
            } else if (compound instanceof DifferenceInt) {
                if (compound.term[1].equals(component)) {
                    truth = reduceDisjunction(v2, v1);
                } else {
                    truth = reduceConjunctionNeg(v1, v2);
                }
            }
        } else if (oldContent instanceof Implication) {
            if (compound instanceof Disjunction) {
                truth = reduceConjunction(v1, v2);
            } else if (compound instanceof Conjunction) {
                truth = reduceDisjunction(v1, v2);
            }
        }
    }
    if (truth != null) {
        BudgetValue budget = BudgetFunctions.compoundForward(truth, content, nal);
        if (delta != 0) {
            long baseTime = task.sentence.getOccurenceTime();
            if (baseTime != Stamp.ETERNAL) {
                baseTime += delta;
                nal.getTheNewStamp().setOccurrenceTime(baseTime);
            }
        }
        // (allow overlap), a form of detachment
        nal.doublePremiseTask(content, truth, budget, false, true);
    }
}
Also used : CompoundTerm(nars.language.CompoundTerm) BudgetValue(nars.entity.BudgetValue) Task(nars.entity.Task) Statement(nars.language.Statement) Inheritance(nars.language.Inheritance) ImageInt(nars.language.ImageInt) SetInt(nars.language.SetInt) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term) IntersectionInt(nars.language.IntersectionInt) Implication(nars.language.Implication) DifferenceInt(nars.language.DifferenceInt) Disjunction(nars.language.Disjunction) TruthFunctions.reduceDisjunction(nars.inference.TruthFunctions.reduceDisjunction) IntersectionExt(nars.language.IntersectionExt) TruthValue(nars.entity.TruthValue) TruthFunctions.reduceConjunction(nars.inference.TruthFunctions.reduceConjunction) Conjunction(nars.language.Conjunction) SetExt(nars.language.SetExt) ImageExt(nars.language.ImageExt) DifferenceExt(nars.language.DifferenceExt) Sentence(nars.entity.Sentence) Interval(nars.language.Interval)

Example 2 with Disjunction

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

the class CompositionalRules method decomposeStatement.

/**
 * {(||, S, P), P} |- S {(&&, S, P), P} |- S
 *
 * @param implication The implication term to be decomposed
 * @param componentCommon The part of the implication to be removed
 * @param compoundTask Whether the implication comes from the task
 * @param nal Reference to the memory
 */
static void decomposeStatement(CompoundTerm compound, Term component, boolean compoundTask, int index, DerivationContext nal) {
    boolean isTemporalConjunction = (compound instanceof Conjunction) && !((Conjunction) compound).isSpatial;
    if (isTemporalConjunction && (compound.getTemporalOrder() == TemporalRules.ORDER_FORWARD) && (index != 0)) {
        return;
    }
    long occurrence_time = nal.getTheNewStamp().getOccurrenceTime();
    if (isTemporalConjunction && (compound.getTemporalOrder() == TemporalRules.ORDER_FORWARD)) {
        if (!nal.getCurrentTask().sentence.isEternal() && compound.term[index + 1] instanceof Interval) {
            long shift_occurrence = ((Interval) compound.term[1]).time;
            occurrence_time = nal.getCurrentTask().sentence.getOccurenceTime() + shift_occurrence;
        }
    }
    Task task = nal.getCurrentTask();
    Sentence taskSentence = task.sentence;
    Sentence belief = nal.getCurrentBelief();
    Term content = reduceComponents(compound, component, nal.mem());
    if (content == null) {
        return;
    }
    TruthValue truth = null;
    BudgetValue budget;
    if (taskSentence.isQuestion() || taskSentence.isQuest()) {
        budget = BudgetFunctions.compoundBackward(content, nal);
        nal.getTheNewStamp().setOccurrenceTime(occurrence_time);
        nal.doublePremiseTask(content, truth, budget, false, false);
        // special inference to answer conjunctive questions with query variables
        if (taskSentence.term.hasVarQuery()) {
            Concept contentConcept = nal.mem().concept(content);
            if (contentConcept == null) {
                return;
            }
            Sentence contentBelief = contentConcept.getBelief(nal, task);
            if (contentBelief == null) {
                return;
            }
            Task contentTask = new Task(contentBelief, task.budget, false);
            nal.setCurrentTask(contentTask);
            Term conj = Conjunction.make(component, content);
            truth = intersection(contentBelief.truth, belief.truth);
            budget = BudgetFunctions.compoundForward(truth, conj, nal);
            nal.getTheNewStamp().setOccurrenceTime(occurrence_time);
            nal.doublePremiseTask(conj, truth, budget, false, false);
        }
    } else {
        TruthValue v1, v2;
        if (compoundTask) {
            v1 = taskSentence.truth;
            v2 = belief.truth;
        } else {
            v1 = belief.truth;
            v2 = taskSentence.truth;
        }
        if (compound instanceof Conjunction) {
            if (taskSentence.isGoal()) {
                if (compoundTask) {
                    truth = intersection(v1, v2);
                } else {
                    return;
                }
            } else {
                // isJudgment
                truth = reduceConjunction(v1, v2);
            }
        } else if (compound instanceof Disjunction) {
            if (taskSentence.isGoal()) {
                if (compoundTask) {
                    truth = reduceConjunction(v2, v1);
                } else {
                    return;
                }
            } else {
                // isJudgment
                truth = reduceDisjunction(v1, v2);
            }
        } else {
            return;
        }
        budget = BudgetFunctions.compoundForward(truth, content, nal);
    }
    nal.getTheNewStamp().setOccurrenceTime(occurrence_time);
    nal.doublePremiseTask(content, truth, budget, false, false);
}
Also used : BudgetValue(nars.entity.BudgetValue) Concept(nars.entity.Concept) Task(nars.entity.Task) Disjunction(nars.language.Disjunction) TruthFunctions.reduceDisjunction(nars.inference.TruthFunctions.reduceDisjunction) TruthValue(nars.entity.TruthValue) TruthFunctions.reduceConjunction(nars.inference.TruthFunctions.reduceConjunction) Conjunction(nars.language.Conjunction) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term) Sentence(nars.entity.Sentence) Interval(nars.language.Interval)

Example 3 with Disjunction

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

the class StructuralRules method structuralCompound.

/* --------------- Disjunction and Conjunction transform --------------- */
/**
 * {(&&, A, B), A@(&&, A, B)} |- A, or answer (&&, A, B)? using A {(||, A,
 * B), A@(||, A, B)} |- A, or answer (||, A, B)? using A
 *
 * @param compound The premise
 * @param component The recognized component in the premise
 * @param compoundTask Whether the compound comes from the task
 * @param nal Reference to the memory
 */
static boolean structuralCompound(CompoundTerm compound, Term component, boolean compoundTask, int index, DerivationContext nal) {
    if (compound instanceof Conjunction) {
        if (nal.getCurrentTask().getTerm() == compound) {
            // only for # for now, will be gradually applied to &/ later
            Conjunction conj = (Conjunction) compound;
            if (conj.getTemporalOrder() == TemporalRules.ORDER_FORWARD && conj.isSpatial) {
                // and some also to && &|
                // flattenSequence(compound, component, compoundTask, index, nal);
                groupSequence(compound, component, compoundTask, index, nal);
                // takeOutFromConjunction(compound, component, compoundTask, index, nal);
                splitConjunctionApart(compound, component, compoundTask, index, nal);
            }
            if (conj.getTemporalOrder() == TemporalRules.ORDER_FORWARD) {
                seqToImage(conj, index, nal);
            }
        }
    }
    if (component.hasVarIndep()) {
        // moved down here since flattening also works when indep
        return false;
    }
    // and also for &/ with index > 0
    if ((compound instanceof Conjunction) && !compound.getIsSpatial() && (compound.getTemporalOrder() == TemporalRules.ORDER_FORWARD) && (index != 0)) {
        return false;
    }
    final Term content = compoundTask ? component : compound;
    Task task = nal.getCurrentTask();
    Sentence sentence = task.sentence;
    TruthValue truth = sentence.truth;
    final float reliance = Parameters.reliance;
    BudgetValue budget;
    if (sentence.isQuestion() || sentence.isQuest()) {
        budget = BudgetFunctions.compoundBackward(content, nal);
    } else {
        // [03:25] <patham9> <a --> b>.     (&&,<a --> b>,<x --> y>).   =>    <x --> y>
        if ((sentence.isJudgment() || sentence.isGoal()) && ((!compoundTask && compound instanceof Disjunction) || (compoundTask && compound instanceof Conjunction))) {
            truth = TruthFunctions.deduction(truth, reliance);
        } else {
            TruthValue v1, v2;
            v1 = TruthFunctions.negation(truth);
            v2 = TruthFunctions.deduction(v1, reliance);
            truth = TruthFunctions.negation(v2);
        }
        budget = BudgetFunctions.forward(truth, nal);
    }
    return nal.singlePremiseTask(content, truth, budget);
}
Also used : BudgetValue(nars.entity.BudgetValue) Task(nars.entity.Task) Disjunction(nars.language.Disjunction) TruthValue(nars.entity.TruthValue) Conjunction(nars.language.Conjunction) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term) Sentence(nars.entity.Sentence)

Aggregations

BudgetValue (nars.entity.BudgetValue)3 Sentence (nars.entity.Sentence)3 Task (nars.entity.Task)3 TruthValue (nars.entity.TruthValue)3 CompoundTerm (nars.language.CompoundTerm)3 Conjunction (nars.language.Conjunction)3 Disjunction (nars.language.Disjunction)3 Term (nars.language.Term)3 TruthFunctions.reduceConjunction (nars.inference.TruthFunctions.reduceConjunction)2 TruthFunctions.reduceDisjunction (nars.inference.TruthFunctions.reduceDisjunction)2 Interval (nars.language.Interval)2 Concept (nars.entity.Concept)1 DifferenceExt (nars.language.DifferenceExt)1 DifferenceInt (nars.language.DifferenceInt)1 ImageExt (nars.language.ImageExt)1 ImageInt (nars.language.ImageInt)1 Implication (nars.language.Implication)1 Inheritance (nars.language.Inheritance)1 IntersectionExt (nars.language.IntersectionExt)1 IntersectionInt (nars.language.IntersectionInt)1