Search in sources :

Example 21 with BudgetValue

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

the class StructuralRules method transformSubjectPI.

/**
 * Equivalent transformation between products and images when the subject is
 * a compound {<(*, 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 subject The subject term
 * @param predicate The predicate term
 * @param nal Reference to the memory
 */
private static void transformSubjectPI(short index, CompoundTerm subject, Term predicate, DerivationContext nal) {
    TruthValue truth = nal.getCurrentTask().sentence.truth;
    BudgetValue budget;
    Inheritance inheritance;
    Term newSubj, newPred;
    if (subject instanceof Product) {
        Product product = (Product) subject;
        short i = index;
        /*for (short i = 0; i < product.size(); i++)*/
        {
            newSubj = product.term[i];
            newPred = ImageExt.make(product, predicate, i);
            if (!(newSubj instanceof Interval)) {
                // no intervals as subjects
                inheritance = Inheritance.make(newSubj, newPred);
                if (inheritance != null) {
                    if (truth == null) {
                        budget = BudgetFunctions.compoundBackward(inheritance, nal);
                    } else {
                        budget = BudgetFunctions.compoundForward(truth, inheritance, nal);
                    }
                    nal.singlePremiseTask(inheritance, truth, budget);
                }
            }
        }
    } else if (subject instanceof ImageInt) {
        ImageInt image = (ImageInt) subject;
        int relationIndex = image.relationIndex;
        for (short i = 0; i < image.size(); i++) {
            if (i == relationIndex) {
                newSubj = image.term[relationIndex];
                newPred = Product.make(image, predicate, relationIndex);
            } else {
                newSubj = ImageInt.make(image, predicate, i);
                newPred = image.term[i];
            }
            inheritance = Inheritance.make(newSubj, newPred);
            if (inheritance != null) {
                if (truth == null) {
                    budget = BudgetFunctions.compoundBackward(inheritance, nal);
                } else {
                    budget = BudgetFunctions.compoundForward(truth, inheritance, nal);
                }
                nal.singlePremiseTask(inheritance, truth, budget);
            }
        }
    }
}
Also used : BudgetValue(nars.entity.BudgetValue) TruthValue(nars.entity.TruthValue) Inheritance(nars.language.Inheritance) Product(nars.language.Product) ImageInt(nars.language.ImageInt) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term) Interval(nars.language.Interval)

Example 22 with BudgetValue

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

the class StructuralRules method groupSequence.

/* --------------- Group sequence left and right --------------- */
/**
 * {(#,A,B,C,D,E), C@(#,A,B,C,D,E)} |- (#,(#,A,B),C,D,E), (#,A,B,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 groupSequence(CompoundTerm compound, Term component, boolean compoundTask, int index, DerivationContext nal) {
    if (compound instanceof Conjunction) {
        Conjunction conjCompound = (Conjunction) compound;
        if (conjCompound.getTemporalOrder() == TemporalRules.ORDER_FORWARD) {
            boolean hasLeft = index > 1;
            boolean hasRight = index < compound.size() - 2;
            if (hasLeft) {
                // if index-1 it would have length 1, no group
                int minIndex = Memory.randomNumber.nextInt(index - 1);
                Term[] newTermLeft = new Term[(index - minIndex)];
                System.arraycopy(conjCompound.term, minIndex, newTermLeft, minIndex - minIndex, index - minIndex);
                Term contLeft = Conjunction.make(newTermLeft, conjCompound.getTemporalOrder(), conjCompound.getIsSpatial());
                Term[] totalLeft = new Term[conjCompound.size() - newTermLeft.length + 1];
                // 1. add left of min index
                int k = 0;
                for (int i = 0; i < minIndex; i++) {
                    totalLeft[k++] = conjCompound.term[i];
                }
                // add formed group
                totalLeft[k] = contLeft;
                k += newTermLeft.length - 1;
                // and add what is after
                for (int i = index; i < conjCompound.size(); i++) {
                    totalLeft[k++] = conjCompound.term[i];
                }
                Term cont1 = Conjunction.make(totalLeft, conjCompound.getTemporalOrder(), conjCompound.getIsSpatial());
                if (cont1 instanceof Conjunction && totalLeft.length != conjCompound.size()) {
                    TruthValue truth = nal.getCurrentTask().sentence.truth.clone();
                    BudgetValue budget = BudgetFunctions.forward(truth, nal);
                    nal.singlePremiseTask(cont1, truth, budget);
                }
            }
            if (hasRight) {
                int maxIndex = compound.term.length - 1 - (Memory.randomNumber.nextInt(1 + (compound.term.length - 1) - (index + 2)));
                Term[] newTermRight = new Term[maxIndex - index];
                System.arraycopy(conjCompound.term, index + 1, newTermRight, index + 1 - (index + 1), maxIndex + 1 - (index + 1));
                Term contRight = Conjunction.make(newTermRight, conjCompound.getTemporalOrder(), conjCompound.getIsSpatial());
                Term[] totalRight = new Term[conjCompound.size() - newTermRight.length + 1];
                // 2. add left of index
                int k = 0;
                for (int i = 0; i <= index; i++) {
                    totalRight[k++] = conjCompound.term[i];
                }
                // add formed group
                totalRight[k] = contRight;
                k += newTermRight.length - 1 - 1;
                // and add what is after
                for (int i = maxIndex + 1; i < conjCompound.size(); i++) {
                    totalRight[k++] = conjCompound.term[i];
                }
                Term cont2 = Conjunction.make(totalRight, conjCompound.getTemporalOrder(), conjCompound.getIsSpatial());
                if (cont2 instanceof Conjunction && totalRight.length != conjCompound.size()) {
                    TruthValue truth = nal.getCurrentTask().sentence.truth.clone();
                    BudgetValue budget = BudgetFunctions.forward(truth, nal);
                    nal.singlePremiseTask(cont2, 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 23 with BudgetValue

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

the class StructuralRules method transformNegation.

/* --------------- Negation related rules --------------- */
/**
 * {A, A@(--, A)} |- (--, A)
 *
 * @param content The premise
 * @param nal Reference to the memory
 */
public static void transformNegation(CompoundTerm content, DerivationContext nal) {
    Task task = nal.getCurrentTask();
    Sentence sentence = task.sentence;
    TruthValue truth = sentence.truth;
    BudgetValue budget;
    if (sentence.isJudgment() || sentence.isGoal()) {
        truth = TruthFunctions.negation(truth);
        budget = BudgetFunctions.compoundForward(truth, content, nal);
    } else {
        budget = BudgetFunctions.compoundBackward(content, nal);
    }
    nal.singlePremiseTask(content, truth, budget);
}
Also used : BudgetValue(nars.entity.BudgetValue) Task(nars.entity.Task) TruthValue(nars.entity.TruthValue) Sentence(nars.entity.Sentence)

Example 24 with BudgetValue

use of nars.entity.BudgetValue 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 25 with BudgetValue

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

Aggregations

BudgetValue (nars.entity.BudgetValue)66 TruthValue (nars.entity.TruthValue)52 Term (nars.language.Term)48 Sentence (nars.entity.Sentence)39 Task (nars.entity.Task)36 CompoundTerm (nars.language.CompoundTerm)34 Stamp (nars.entity.Stamp)22 Statement (nars.language.Statement)21 Conjunction (nars.language.Conjunction)18 Inheritance (nars.language.Inheritance)11 Interval (nars.language.Interval)9 Implication (nars.language.Implication)8 Concept (nars.entity.Concept)7 Product (nars.language.Product)7 Variable (nars.language.Variable)6 Operation (nars.operator.Operation)5 Memory (nars.storage.Memory)5 HashMap (java.util.HashMap)4 TruthFunctions.reduceConjunction (nars.inference.TruthFunctions.reduceConjunction)4 Equivalence (nars.language.Equivalence)4