Search in sources :

Example 46 with Term

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

the class StructuralRules method seqToImage.

public static void seqToImage(Conjunction conj, int index, DerivationContext nal) {
    // extensional
    int side = 0;
    short[] indices = new short[] { (short) side, (short) index };
    Product subject = Product.make(conj.term);
    Term predicate = Term.SEQ_TEMPORAL;
    if (conj.isSpatial) {
        predicate = Term.SEQ_SPATIAL;
    }
    Inheritance inh = Inheritance.make(subject, predicate);
    StructuralRules.transformProductImage(inh, inh, indices, nal);
}
Also used : Inheritance(nars.language.Inheritance) Product(nars.language.Product) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term)

Example 47 with Term

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

the class StructuralRules method takeOutFromConjunction.

/* --------------- Take out from conjunction --------------- */
/**
 * {(&&,A,B,C), B@(&&,A,B,C)} |- (&&,A,C)
 * Works for all conjunctions
 * @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 void takeOutFromConjunction(CompoundTerm compound, Term component, boolean compoundTask, int index, DerivationContext nal) {
    if (compound instanceof Conjunction) {
        Conjunction conjCompound = (Conjunction) compound;
        Term[] newTerm = new Term[conjCompound.size() - 1];
        System.arraycopy(conjCompound.term, 0, newTerm, 0, index);
        System.arraycopy(conjCompound.term, index + 1, newTerm, index, newTerm.length - index);
        Term cont = Conjunction.make(newTerm, conjCompound.getTemporalOrder(), conjCompound.getIsSpatial());
        TruthValue truth = TruthFunctions.deduction(nal.getCurrentTask().sentence.truth, Parameters.reliance);
        BudgetValue budget = BudgetFunctions.forward(truth, nal);
        nal.singlePremiseTask(cont, truth, budget);
    }
}
Also used : BudgetValue(nars.entity.BudgetValue) TruthValue(nars.entity.TruthValue) Conjunction(nars.language.Conjunction) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term)

Example 48 with Term

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

the class StructuralRules method structuralCompose1.

/**
 * {<S --> P>, P@(P|Q)} |- <S --> (P|Q)>
 *
 * @param compound The compound term
 * @param index The location of the indicated term in the compound
 * @param statement The premise
 * @param nal Reference to the memory
 */
static void structuralCompose1(CompoundTerm compound, short index, Statement statement, DerivationContext nal) {
    if (!nal.getCurrentTask().sentence.isJudgment()) {
        // forward inference only
        return;
    }
    Term component = compound.term[index];
    Task task = nal.getCurrentTask();
    Sentence sentence = task.sentence;
    int order = sentence.getTemporalOrder();
    TruthValue truth = sentence.truth;
    final float reliance = Parameters.reliance;
    TruthValue truthDed = TruthFunctions.deduction(truth, reliance);
    TruthValue truthNDed = TruthFunctions.negation(TruthFunctions.deduction(truth, reliance));
    Term subj = statement.getSubject();
    Term pred = statement.getPredicate();
    if (component.equals(subj)) {
        if (compound instanceof IntersectionExt) {
            structuralStatement(compound, pred, order, truthDed, nal);
        } else if (compound instanceof IntersectionInt) {
        } else if ((compound instanceof DifferenceExt) && (index == 0)) {
            structuralStatement(compound, pred, order, truthDed, nal);
        } else if (compound instanceof DifferenceInt) {
            if (index == 0) {
            } else {
                structuralStatement(compound, pred, order, truthNDed, nal);
            }
        }
    } else if (component.equals(pred)) {
        if (compound instanceof IntersectionExt) {
        } else if (compound instanceof IntersectionInt) {
            structuralStatement(subj, compound, order, truthDed, nal);
        } else if (compound instanceof DifferenceExt) {
            if (index == 0) {
            } else {
                structuralStatement(subj, compound, order, truthNDed, nal);
            }
        } else if ((compound instanceof DifferenceInt) && (index == 0)) {
            structuralStatement(subj, compound, order, truthDed, nal);
        }
    }
}
Also used : Task(nars.entity.Task) IntersectionExt(nars.language.IntersectionExt) TruthValue(nars.entity.TruthValue) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term) DifferenceExt(nars.language.DifferenceExt) Sentence(nars.entity.Sentence) IntersectionInt(nars.language.IntersectionInt) DifferenceInt(nars.language.DifferenceInt)

Example 49 with Term

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

the class StructuralRules method splitConjunctionApart.

/* --------------- Split sequence apart --------------- */
/**
 * {(#,A,B,C,D,E), C@(#,A,B,C,D,E)} |- (#,A,B,C), (#,C,D,E)
 * Works for all conjunctions
 * @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 void splitConjunctionApart(CompoundTerm compound, Term component, boolean compoundTask, int index, DerivationContext nal) {
    if (compound instanceof Conjunction) {
        Conjunction conjCompound = (Conjunction) compound;
        Term[] newTermLeft = new Term[index + 1];
        Term[] newTermRight = new Term[conjCompound.size() - index];
        if (// since nothing was splitted
        newTermLeft.length == compound.size() || newTermRight.length == compound.size()) {
            return;
        }
        System.arraycopy(conjCompound.term, 0, newTermLeft, 0, newTermLeft.length);
        System.arraycopy(conjCompound.term, 0 + index, newTermRight, 0, newTermRight.length);
        Conjunction cont1 = (Conjunction) Conjunction.make(newTermLeft, conjCompound.getTemporalOrder(), conjCompound.getIsSpatial());
        Conjunction cont2 = (Conjunction) Conjunction.make(newTermRight, conjCompound.getTemporalOrder(), conjCompound.getIsSpatial());
        TruthValue truth = TruthFunctions.deduction(nal.getCurrentTask().sentence.truth, Parameters.reliance);
        BudgetValue budget = BudgetFunctions.forward(truth, nal);
        nal.singlePremiseTask(cont1, truth, budget);
        nal.singlePremiseTask(cont2, truth.clone(), budget.clone());
    }
}
Also used : BudgetValue(nars.entity.BudgetValue) TruthValue(nars.entity.TruthValue) Conjunction(nars.language.Conjunction) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term)

Example 50 with Term

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

the class SyllogisticRules method conditionalAbd.

/**
 * {<(&&, S2, S3) ==> P>, <(&&, S1, S3) ==> P>} |- <S1 ==> S2>
 *
 * @param cond1 The condition of the first premise
 * @param cond2 The condition of the second premise
 * @param taskContent The first premise
 * @param st2 The second premise
 * @param nal Reference to the memory
 * @return Whether there are derived tasks
 */
static boolean conditionalAbd(Term cond1, Term cond2, Statement st1, Statement st2, DerivationContext nal) {
    if (!(st1 instanceof Implication) || !(st2 instanceof Implication)) {
        return false;
    }
    if (!(cond1 instanceof Conjunction) && !(cond2 instanceof Conjunction)) {
        return false;
    }
    int order1 = st1.getTemporalOrder();
    int order2 = st2.getTemporalOrder();
    if (order1 != reverseOrder(order2)) {
        return false;
    }
    Term term1 = null;
    Term term2 = null;
    if (cond1 instanceof Conjunction) {
        term1 = reduceComponents((CompoundTerm) cond1, cond2, nal.mem());
    }
    if (cond2 instanceof Conjunction) {
        term2 = reduceComponents((CompoundTerm) cond2, cond1, nal.mem());
    }
    if ((term1 == null) && (term2 == null)) {
        return false;
    }
    Task task = nal.getCurrentTask();
    Sentence sentence = task.sentence;
    Sentence belief = nal.getCurrentBelief();
    TruthValue value1 = sentence.truth;
    TruthValue value2 = belief.truth;
    Term content;
    boolean keepOrder = Variables.hasSubstitute(Symbols.VAR_INDEPENDENT, st1, task.getTerm());
    TruthValue truth = null;
    BudgetValue budget;
    if (term1 != null) {
        if (term2 != null) {
            content = Statement.make(st2, term2, term1, st2.getTemporalOrder());
        } else {
            content = term1;
            if (content.hasVarIndep()) {
                return false;
            }
        }
        if (sentence.isQuestion() || sentence.isQuest()) {
            budget = BudgetFunctions.backwardWeak(value2, nal);
        } else {
            if (sentence.isGoal()) {
                if (keepOrder) {
                    truth = TruthFunctions.desireDed(value1, value2);
                } else {
                    truth = TruthFunctions.desireInd(value1, value2);
                }
            } else {
                // isJudgment
                truth = TruthFunctions.abduction(value2, value1);
            }
            budget = BudgetFunctions.forward(truth, nal);
        }
        nal.doublePremiseTask(content, truth, budget, false, false);
    }
    if (term2 != null) {
        if (term1 != null) {
            content = Statement.make(st1, term1, term2, st1.getTemporalOrder());
        } else {
            content = term2;
            if (content.hasVarIndep()) {
                return false;
            }
        }
        if (sentence.isQuestion() || sentence.isQuest()) {
            budget = BudgetFunctions.backwardWeak(value2, nal);
        } else {
            if (sentence.isGoal()) {
                if (keepOrder) {
                    truth = TruthFunctions.desireDed(value1, value2);
                } else {
                    truth = TruthFunctions.desireInd(value1, value2);
                }
            } else {
                // isJudgment
                truth = TruthFunctions.abduction(value1, value2);
            }
            budget = BudgetFunctions.forward(truth, nal);
        }
        nal.doublePremiseTask(content, truth, budget, false, false);
    }
    return true;
}
Also used : CompoundTerm(nars.language.CompoundTerm) BudgetValue(nars.entity.BudgetValue) Task(nars.entity.Task) TruthValue(nars.entity.TruthValue) Conjunction(nars.language.Conjunction) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term) Implication(nars.language.Implication) Sentence(nars.entity.Sentence)

Aggregations

Term (nars.language.Term)109 CompoundTerm (nars.language.CompoundTerm)66 BudgetValue (nars.entity.BudgetValue)48 TruthValue (nars.entity.TruthValue)46 Sentence (nars.entity.Sentence)40 Task (nars.entity.Task)37 Statement (nars.language.Statement)28 Conjunction (nars.language.Conjunction)20 Inheritance (nars.language.Inheritance)19 Stamp (nars.entity.Stamp)17 Concept (nars.entity.Concept)14 Implication (nars.language.Implication)13 Product (nars.language.Product)11 NAR (nars.main.NAR)9 Interval (nars.language.Interval)8 Test (org.junit.Test)8 HashMap (java.util.HashMap)7 SetExt (nars.language.SetExt)7 SetInt (nars.language.SetInt)7 Variable (nars.language.Variable)7