Search in sources :

Example 51 with BudgetValue

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

the class StructuralRules method transformSetRelation.

/* -------------------- set transform -------------------- */
/**
 * {<S --> {P}>} |- <S <-> {P}>
 *
 * @param compound The set compound
 * @param statement The premise
 * @param side The location of the indicated term in the premise
 * @param nal Reference to the memory
 */
static void transformSetRelation(CompoundTerm compound, Statement statement, short side, DerivationContext nal) {
    if (compound.size() > 1) {
        return;
    }
    if (statement instanceof Inheritance) {
        if (((compound instanceof SetExt) && (side == 0)) || ((compound instanceof SetInt) && (side == 1))) {
            return;
        }
    }
    Term sub = statement.getSubject();
    Term pre = statement.getPredicate();
    Statement content;
    if (statement instanceof Inheritance) {
        content = Similarity.make(sub, pre);
    } else {
        if (((compound instanceof SetExt) && (side == 0)) || ((compound instanceof SetInt) && (side == 1))) {
            content = Inheritance.make(pre, sub);
        } else {
            content = Inheritance.make(sub, pre);
        }
    }
    if (content == null) {
        return;
    }
    Task task = nal.getCurrentTask();
    Sentence sentence = task.sentence;
    TruthValue truth = sentence.truth;
    BudgetValue budget;
    if (sentence.isJudgment()) {
        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) Statement(nars.language.Statement) TruthValue(nars.entity.TruthValue) Inheritance(nars.language.Inheritance) SetExt(nars.language.SetExt) SetInt(nars.language.SetInt) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term) Sentence(nars.entity.Sentence)

Example 52 with BudgetValue

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

the class StructuralRules method structuralStatement.

/**
 * Common final operations of the above two methods
 *
 * @param subject The subject of the new task
 * @param predicate The predicate of the new task
 * @param truth The truth value of the new task
 * @param nal Reference to the memory
 */
private static void structuralStatement(Term subject, Term predicate, int order, TruthValue truth, DerivationContext nal) {
    Task task = nal.getCurrentTask();
    Term oldContent = task.getTerm();
    if (oldContent instanceof Statement) {
        Statement content = Statement.make((Statement) oldContent, subject, predicate, order);
        if (content != null) {
            BudgetValue budget = BudgetFunctions.compoundForward(truth, content, nal);
            nal.singlePremiseTask(content, truth, budget);
        }
    }
}
Also used : BudgetValue(nars.entity.BudgetValue) Task(nars.entity.Task) Statement(nars.language.Statement) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term)

Example 53 with BudgetValue

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

the class StructuralRules method structuralCompose2.

/* -------------------- transform between compounds and term -------------------- */
/**
 * {<S --> P>, S@(S&T)} |- <(S&T) --> (P&T)> {<S --> P>, S@(M-S)} |- <(M-P)
 * --> (M-S)>
 *
 * @param compound The compound term
 * @param index The location of the indicated term in the compound
 * @param statement The premise
 * @param side The location of the indicated term in the premise
 * @param nal Reference to the memory
 */
static void structuralCompose2(CompoundTerm compound, short index, Statement statement, short side, DerivationContext nal) {
    if (compound.equals(statement.term[side])) {
        return;
    }
    Term sub = statement.getSubject();
    Term pred = statement.getPredicate();
    List<Term> components = compound.asTermList();
    if (((side == 0) && components.contains(pred)) || ((side == 1) && components.contains(sub))) {
        return;
    }
    if (side == 0) {
        if (components.contains(sub)) {
            sub = compound;
            components.set(index, pred);
            pred = Terms.term(compound, components);
        }
    } else {
        if (components.contains(pred)) {
            components.set(index, sub);
            sub = Terms.term(compound, components);
            pred = compound;
        }
    }
    if ((sub == null) || (pred == null))
        return;
    Statement content;
    int order = statement.getTemporalOrder();
    if (switchOrder(compound, index)) {
        content = Statement.make(statement, pred, sub, TemporalRules.reverseOrder(order));
    } else {
        content = Statement.make(statement, sub, pred, order);
    }
    if (content == null)
        return;
    Sentence sentence = nal.getCurrentTask().sentence;
    TruthValue truth = TruthFunctions.deduction(sentence.truth, Parameters.reliance);
    BudgetValue budget = BudgetFunctions.compoundForward(truth, content, nal);
    nal.singlePremiseTask(content, truth, budget);
}
Also used : BudgetValue(nars.entity.BudgetValue) Statement(nars.language.Statement) TruthValue(nars.entity.TruthValue) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term) Sentence(nars.entity.Sentence)

Example 54 with BudgetValue

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

the class StructuralRules method transformPredicatePI.

/**
 * Equivalent transformation between products and images when the predicate
 * 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 transformPredicatePI(short index, Term subject, CompoundTerm predicate, DerivationContext nal) {
    TruthValue truth = nal.getCurrentTask().sentence.truth;
    BudgetValue budget;
    Inheritance inheritance;
    Term newSubj, newPred;
    if (predicate instanceof Product) {
        Product product = (Product) predicate;
        short i = index;
        /*for (short i = 0; i < product.size(); i++)*/
        {
            newSubj = ImageInt.make(product, subject, i);
            newPred = product.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);
            }
        }
    } else if (predicate instanceof ImageExt) {
        ImageExt image = (ImageExt) predicate;
        int relationIndex = image.relationIndex;
        for (short i = 0; i < image.size(); i++) {
            if (i == relationIndex) {
                newSubj = Product.make(image, subject, relationIndex);
                newPred = image.term[relationIndex];
            } else {
                newSubj = image.term[i];
                newPred = ImageExt.make(image, subject, i);
            }
            if (newSubj instanceof CompoundTerm && (newPred.equals(Term.SEQ_TEMPORAL) || newPred.equals(Term.SEQ_SPATIAL))) {
                Term seq = Conjunction.make(((CompoundTerm) newSubj).term, TemporalRules.ORDER_FORWARD, newPred.equals(Term.SEQ_SPATIAL));
                if (truth == null) {
                    budget = BudgetFunctions.compoundBackward(seq, nal);
                } else {
                    budget = BudgetFunctions.compoundForward(truth, seq, nal);
                }
                nal.singlePremiseTask(seq, truth, budget);
                return;
            }
            inheritance = Inheritance.make(newSubj, newPred);
            if (inheritance != null) {
                // jmv <<<<<
                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) CompoundTerm(nars.language.CompoundTerm) TruthValue(nars.entity.TruthValue) Inheritance(nars.language.Inheritance) Product(nars.language.Product) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term) ImageExt(nars.language.ImageExt)

Example 55 with BudgetValue

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