Search in sources :

Example 56 with TruthValue

use of nars.entity.TruthValue 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)

Example 57 with TruthValue

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

the class StructuralRules method contraposition.

/**
 * {<A ==> B>, A@(--, A)} |- <(--, B) ==> (--, A)>
 *
 * @param statement The premise
 * @param memory Reference to the memory
 */
protected static boolean contraposition(final Statement statement, final Sentence sentence, final DerivationContext nal) {
    Memory memory = nal.mem();
    // memory.logic.CONTRAPOSITION.commit(statement.complexity);
    Term subj = statement.getSubject();
    Term pred = statement.getPredicate();
    Statement content = Statement.make(statement, Negation.make(pred), Negation.make(subj), TemporalRules.reverseOrder(statement.getTemporalOrder()));
    if (content == null)
        return false;
    TruthValue truth = sentence.truth;
    BudgetValue budget;
    if (sentence.isQuestion() || sentence.isQuest()) {
        if (content instanceof Implication) {
            budget = BudgetFunctions.compoundBackwardWeak(content, nal);
        } else {
            budget = BudgetFunctions.compoundBackward(content, nal);
        }
        return nal.singlePremiseTask(content, Symbols.QUESTION_MARK, truth, budget);
    } else {
        if (content instanceof Implication) {
            truth = TruthFunctions.contraposition(truth);
        }
        budget = BudgetFunctions.compoundForward(truth, content, nal);
        return nal.singlePremiseTask(content, Symbols.JUDGMENT_MARK, truth, budget);
    }
}
Also used : BudgetValue(nars.entity.BudgetValue) Memory(nars.storage.Memory) Statement(nars.language.Statement) TruthValue(nars.entity.TruthValue) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term) Implication(nars.language.Implication)

Example 58 with TruthValue

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

the class StructuralRules method transformProductImage.

/* -------------------- products and images transform -------------------- */
/**
 * Equivalent transformation between products and images {<(*, S, M) --> P>,
 * S@(*, S, M)} |- <S --> (/, P, _, M)> {<S --> (/, P, _, M)>, P@(/, P, _,
 * M)} |- <(*, S, M) --> P> {<S --> (/, P, _, M)>, M@(/, P, _, M)} |- <M -->
 * (/, P, S, _)>
 *
 * @param inh An Inheritance statement
 * @param oldContent The whole content
 * @param indices The indices of the TaskLink
 * @param task The task
 * @param memory Reference to the memory
 */
static void transformProductImage(Inheritance inh, CompoundTerm oldContent, short[] indices, DerivationContext nal) {
    final Memory memory = nal.mem();
    Term subject = inh.getSubject();
    Term predicate = inh.getPredicate();
    short index = indices[indices.length - 1];
    short side = indices[indices.length - 2];
    if (inh.equals(oldContent)) {
        if (subject instanceof CompoundTerm) {
            transformSubjectPI(index, (CompoundTerm) subject, predicate, nal);
        }
        if (predicate instanceof CompoundTerm) {
            transformPredicatePI(index, subject, (CompoundTerm) predicate, nal);
        }
        return;
    }
    Term compT = inh.term[side];
    if (!(compT instanceof CompoundTerm))
        return;
    CompoundTerm comp = (CompoundTerm) compT;
    if (comp instanceof Product) {
        if (side == 0) {
            subject = comp.term[index];
            predicate = ImageExt.make((Product) comp, inh.getPredicate(), index);
        } else {
            subject = ImageInt.make((Product) comp, inh.getSubject(), index);
            predicate = comp.term[index];
        }
    } else if ((comp instanceof ImageExt) && (side == 1)) {
        if (index == ((ImageExt) comp).relationIndex) {
            subject = Product.make(comp, inh.getSubject(), index);
            predicate = comp.term[index];
        } else {
            subject = comp.term[index];
            predicate = ImageExt.make((ImageExt) comp, inh.getSubject(), index);
        }
    } else if ((comp instanceof ImageInt) && (side == 0)) {
        if (index == ((ImageInt) comp).relationIndex) {
            subject = comp.term[index];
            predicate = Product.make(comp, inh.getPredicate(), index);
        } else {
            subject = ImageInt.make((ImageInt) comp, inh.getPredicate(), index);
            predicate = comp.term[index];
        }
    } else {
        return;
    }
    CompoundTerm newInh = null;
    if (predicate.equals(Term.SEQ_SPATIAL)) {
        newInh = (CompoundTerm) Conjunction.make(((CompoundTerm) subject).term, TemporalRules.ORDER_FORWARD, true);
    } else if (predicate.equals(Term.SEQ_TEMPORAL)) {
        newInh = (CompoundTerm) Conjunction.make(((CompoundTerm) subject).term, TemporalRules.ORDER_FORWARD, false);
    } else {
        newInh = Inheritance.make(subject, predicate);
    }
    if (newInh == null)
        return;
    CompoundTerm content = null;
    if (indices.length == 2) {
        content = newInh;
    } else if ((oldContent instanceof Statement) && (indices[0] == 1)) {
        content = Statement.make((Statement) oldContent, oldContent.term[0], newInh, oldContent.getTemporalOrder());
    } else {
        Term[] componentList;
        Term condition = oldContent.term[0];
        if (((oldContent instanceof Implication) || (oldContent instanceof Equivalence)) && (condition instanceof Conjunction)) {
            componentList = ((CompoundTerm) condition).cloneTerms();
            componentList[indices[1]] = newInh;
            Term newCond = Terms.term((CompoundTerm) condition, componentList);
            content = Statement.make((Statement) oldContent, newCond, ((Statement) oldContent).getPredicate(), oldContent.getTemporalOrder());
        } else {
            componentList = oldContent.cloneTerms();
            componentList[indices[0]] = newInh;
            if (oldContent instanceof Conjunction) {
                Term newContent = Terms.term(oldContent, componentList);
                if (!(newContent instanceof CompoundTerm))
                    return;
                content = (CompoundTerm) newContent;
            } else if ((oldContent instanceof Implication) || (oldContent instanceof Equivalence)) {
                content = Statement.make((Statement) oldContent, componentList[0], componentList[1], oldContent.getTemporalOrder());
            }
        }
    }
    if (content == null)
        return;
    Sentence sentence = nal.getCurrentTask().sentence;
    TruthValue truth = sentence.truth;
    BudgetValue budget;
    if (sentence.isQuestion() || sentence.isQuest()) {
        budget = BudgetFunctions.compoundBackward(content, nal);
    } else {
        budget = BudgetFunctions.compoundForward(truth, content, nal);
    }
    nal.singlePremiseTask(content, truth, budget);
}
Also used : CompoundTerm(nars.language.CompoundTerm) BudgetValue(nars.entity.BudgetValue) Memory(nars.storage.Memory) Statement(nars.language.Statement) Product(nars.language.Product) ImageInt(nars.language.ImageInt) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term) Implication(nars.language.Implication) Equivalence(nars.language.Equivalence) TruthValue(nars.entity.TruthValue) Conjunction(nars.language.Conjunction) ImageExt(nars.language.ImageExt) Sentence(nars.entity.Sentence)

Example 59 with TruthValue

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

the class StructuralRules method structuralDecompose2.

/**
 * {<(S*T) --> (P*T)>, S@(S*T)} |- <S --> P>
 *
 * @param statement The premise
 * @param nal Reference to the memory
 */
static void structuralDecompose2(Statement statement, int index, DerivationContext nal) {
    Term subj = statement.getSubject();
    Term pred = statement.getPredicate();
    if (subj.getClass() != pred.getClass()) {
        return;
    }
    if (!(subj instanceof Product) && !(subj instanceof SetExt) && !(subj instanceof SetInt)) {
        // no abduction on other compounds for now, but may change in the future
        return;
    }
    CompoundTerm sub = (CompoundTerm) subj;
    CompoundTerm pre = (CompoundTerm) pred;
    if (sub.size() != pre.size() || sub.size() <= index) {
        return;
    }
    Term t1 = sub.term[index];
    Term t2 = pre.term[index];
    Statement content;
    int order = statement.getTemporalOrder();
    if (switchOrder(sub, (short) index)) {
        content = Statement.make(statement, t2, t1, TemporalRules.reverseOrder(order));
    } else {
        content = Statement.make(statement, t1, t2, order);
    }
    if (content == null) {
        return;
    }
    Task task = nal.getCurrentTask();
    Sentence sentence = task.sentence;
    TruthValue truth = sentence.truth;
    BudgetValue budget;
    if (sentence.isQuestion() || sentence.isQuest()) {
        budget = BudgetFunctions.compoundBackward(content, nal);
    } else {
        budget = BudgetFunctions.compoundForward(truth, content, nal);
    }
    nal.singlePremiseTask(content, truth, budget);
}
Also used : CompoundTerm(nars.language.CompoundTerm) BudgetValue(nars.entity.BudgetValue) Task(nars.entity.Task) Statement(nars.language.Statement) TruthValue(nars.entity.TruthValue) SetExt(nars.language.SetExt) Product(nars.language.Product) SetInt(nars.language.SetInt) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term) Sentence(nars.entity.Sentence)

Example 60 with TruthValue

use of nars.entity.TruthValue 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)

Aggregations

TruthValue (nars.entity.TruthValue)64 BudgetValue (nars.entity.BudgetValue)52 Term (nars.language.Term)46 Sentence (nars.entity.Sentence)39 CompoundTerm (nars.language.CompoundTerm)36 Task (nars.entity.Task)34 Statement (nars.language.Statement)20 Stamp (nars.entity.Stamp)18 Conjunction (nars.language.Conjunction)18 Inheritance (nars.language.Inheritance)12 Interval (nars.language.Interval)10 Implication (nars.language.Implication)9 Product (nars.language.Product)7 Variable (nars.language.Variable)7 Concept (nars.entity.Concept)5 SetExt (nars.language.SetExt)5 SetInt (nars.language.SetInt)5 Operation (nars.operator.Operation)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4