Search in sources :

Example 21 with Statement

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

the class LocalRules method convertedJudgment.

/**
 * Convert judgment into different relation
 * <p>
 * called in MatchingRules
 *
 * @param budget The budget value of the new task
 * @param truth The truth value of the new task
 * @param nal Reference to the memory
 */
private static void convertedJudgment(final TruthValue newTruth, final BudgetValue newBudget, final DerivationContext nal) {
    Statement content = (Statement) nal.getCurrentTask().getTerm();
    Statement beliefContent = (Statement) nal.getCurrentBelief().term;
    int order = TemporalRules.reverseOrder(beliefContent.getTemporalOrder());
    final Term subjT = content.getSubject();
    final Term predT = content.getPredicate();
    final Term subjB = beliefContent.getSubject();
    final Term predB = beliefContent.getPredicate();
    Term otherTerm;
    if (subjT.hasVarQuery()) {
        otherTerm = (predT.equals(subjB)) ? predB : subjB;
        content = Statement.make(content, otherTerm, predT, order);
    }
    if (predT.hasVarQuery()) {
        otherTerm = (subjT.equals(subjB)) ? predB : subjB;
        content = Statement.make(content, subjT, otherTerm, order);
    }
    if (content == null) {
        return;
    }
    nal.singlePremiseTask(content, Symbols.JUDGMENT_MARK, newTruth, newBudget);
}
Also used : Statement(nars.language.Statement) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term)

Example 22 with Statement

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

the class LocalRules method inferToAsym.

/**
 * {<S <-> P>, <P --> S>} |- <S --> P> Produce an Inheritance/Implication
 * from a Similarity/Equivalence and a reversed Inheritance/Implication
 *
 * @param asym The asymmetric premise
 * @param sym The symmetric premise
 * @param nal Reference to the memory
 */
private static void inferToAsym(Sentence asym, Sentence sym, DerivationContext nal) {
    Statement statement = (Statement) asym.term;
    Term sub = statement.getPredicate();
    Term pre = statement.getSubject();
    Statement content = Statement.make(statement, sub, pre, statement.getTemporalOrder());
    if (content == null)
        return;
    TruthValue truth = TruthFunctions.reduceConjunction(sym.truth, asym.truth);
    BudgetValue budget = BudgetFunctions.forward(truth, nal);
    nal.doublePremiseTask(content, truth, budget, false, false);
}
Also used : BudgetValue(nars.entity.BudgetValue) Statement(nars.language.Statement) TruthValue(nars.entity.TruthValue) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term)

Example 23 with Statement

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

the class RuleTables method asymmetricAsymmetric.

/**
 * Syllogistic rules whose both premises are on the same asymmetric relation
 *
 * @param taskSentence The taskSentence in the task
 * @param belief The judgment in the belief
 * @param figure The location of the shared term
 * @param nal Reference to the memory
 */
private static void asymmetricAsymmetric(final Sentence taskSentence, final Sentence belief, int figure, final DerivationContext nal) {
    Statement taskStatement = (Statement) taskSentence.term;
    Statement beliefStatement = (Statement) belief.term;
    Term t1, t2;
    Term[] u = new Term[] { taskStatement, beliefStatement };
    switch(figure) {
        case // induction
        11:
            if (Variables.unify(VAR_INDEPENDENT, taskStatement.getSubject(), beliefStatement.getSubject(), u)) {
                taskStatement = (Statement) u[0];
                beliefStatement = (Statement) u[1];
                if (taskStatement.equals(beliefStatement)) {
                    return;
                }
                t1 = beliefStatement.getPredicate();
                t2 = taskStatement.getPredicate();
                SyllogisticRules.abdIndCom(t1, t2, taskSentence, belief, figure, nal);
                CompositionalRules.composeCompound(taskStatement, beliefStatement, 0, nal);
                // if(taskSentence.getOccurenceTime()==Stamp.ETERNAL && belief.getOccurenceTime()==Stamp.ETERNAL)
                // introVarImage(taskContent, beliefContent, index, memory);
                CompositionalRules.introVarOuter(taskStatement, beliefStatement, 0, nal);
                CompositionalRules.eliminateVariableOfConditionAbductive(figure, taskSentence, belief, nal);
            }
            break;
        case // deduction
        12:
            if (Variables.unify(VAR_INDEPENDENT, taskStatement.getSubject(), beliefStatement.getPredicate(), u)) {
                taskStatement = (Statement) u[0];
                beliefStatement = (Statement) u[1];
                if (taskStatement.equals(beliefStatement)) {
                    return;
                }
                t1 = beliefStatement.getSubject();
                t2 = taskStatement.getPredicate();
                if (Variables.unify(VAR_QUERY, t1, t2, new Term[] { taskStatement, beliefStatement })) {
                    LocalRules.matchReverse(nal);
                } else {
                    SyllogisticRules.dedExe(t1, t2, taskSentence, belief, nal);
                }
            }
            break;
        case // exemplification
        21:
            if (Variables.unify(VAR_INDEPENDENT, taskStatement.getPredicate(), beliefStatement.getSubject(), u)) {
                taskStatement = (Statement) u[0];
                beliefStatement = (Statement) u[1];
                if (taskStatement.equals(beliefStatement)) {
                    return;
                }
                t1 = taskStatement.getSubject();
                t2 = beliefStatement.getPredicate();
                if (Variables.unify(VAR_QUERY, t1, t2, new Term[] { taskStatement, beliefStatement })) {
                    LocalRules.matchReverse(nal);
                } else {
                    SyllogisticRules.dedExe(t1, t2, taskSentence, belief, nal);
                }
            }
            break;
        case // abduction
        22:
            if (Variables.unify(VAR_INDEPENDENT, taskStatement.getPredicate(), beliefStatement.getPredicate(), u)) {
                taskStatement = (Statement) u[0];
                beliefStatement = (Statement) u[1];
                if (taskStatement.equals(beliefStatement)) {
                    return;
                }
                t1 = taskStatement.getSubject();
                t2 = beliefStatement.getSubject();
                if (!SyllogisticRules.conditionalAbd(t1, t2, taskStatement, beliefStatement, nal)) {
                    // if conditional abduction, skip the following
                    SyllogisticRules.abdIndCom(t1, t2, taskSentence, belief, figure, nal);
                    CompositionalRules.composeCompound(taskStatement, beliefStatement, 1, nal);
                    // introVarImage(taskContent, beliefContent, index, memory);
                    CompositionalRules.introVarOuter(taskStatement, beliefStatement, 1, nal);
                }
                CompositionalRules.eliminateVariableOfConditionAbductive(figure, taskSentence, belief, nal);
            }
            break;
        default:
    }
}
Also used : Statement(nars.language.Statement) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term)

Example 24 with Statement

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

the class RuleTables method symmetricSymmetric.

/**
 * Syllogistic rules whose both premises are on the same symmetric relation
 *
 * @param belief The premise that comes from a belief
 * @param taskSentence The premise that comes from a task
 * @param figure The location of the shared term
 * @param nal Reference to the memory
 */
private static void symmetricSymmetric(final Sentence belief, final Sentence taskSentence, int figure, final DerivationContext nal) {
    Statement s1 = (Statement) belief.term;
    Statement s2 = (Statement) taskSentence.term;
    // parameters for unify()
    Term ut1, ut2;
    // parameters for resemblance()
    Term rt1, rt2;
    switch(figure) {
        case 11:
            ut1 = s1.getSubject();
            ut2 = s2.getSubject();
            rt1 = s1.getPredicate();
            rt2 = s2.getPredicate();
            break;
        case 12:
            ut1 = s1.getSubject();
            ut2 = s2.getPredicate();
            rt1 = s1.getPredicate();
            rt2 = s2.getSubject();
            break;
        case 21:
            ut1 = s1.getPredicate();
            ut2 = s2.getSubject();
            rt1 = s1.getSubject();
            rt2 = s2.getPredicate();
            break;
        case 22:
            ut1 = s1.getPredicate();
            ut2 = s2.getPredicate();
            rt1 = s1.getSubject();
            rt2 = s2.getSubject();
            break;
        default:
            throw new RuntimeException("Invalid figure: " + figure);
    }
    Term[] u = new Term[] { s1, s2 };
    if (Variables.unify(VAR_INDEPENDENT, ut1, ut2, u)) {
        // recalculate rt1, rt2 from above:
        switch(figure) {
            case 11:
                rt1 = s1.getPredicate();
                rt2 = s2.getPredicate();
                break;
            case 12:
                rt1 = s1.getPredicate();
                rt2 = s2.getSubject();
                break;
            case 21:
                rt1 = s1.getSubject();
                rt2 = s2.getPredicate();
                break;
            case 22:
                rt1 = s1.getSubject();
                rt2 = s2.getSubject();
                break;
        }
        SyllogisticRules.resemblance(rt1, rt2, belief, taskSentence, figure, nal);
        CompositionalRules.eliminateVariableOfConditionAbductive(figure, taskSentence, belief, nal);
    }
}
Also used : Statement(nars.language.Statement) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term)

Example 25 with Statement

use of nars.language.Statement 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)

Aggregations

Statement (nars.language.Statement)32 CompoundTerm (nars.language.CompoundTerm)29 Term (nars.language.Term)28 BudgetValue (nars.entity.BudgetValue)21 TruthValue (nars.entity.TruthValue)20 Sentence (nars.entity.Sentence)13 Task (nars.entity.Task)10 Conjunction (nars.language.Conjunction)9 Inheritance (nars.language.Inheritance)9 Implication (nars.language.Implication)6 Equivalence (nars.language.Equivalence)5 Interval (nars.language.Interval)4 SetExt (nars.language.SetExt)4 SetInt (nars.language.SetInt)4 HashMap (java.util.HashMap)3 TruthFunctions.reduceConjunction (nars.inference.TruthFunctions.reduceConjunction)3 ImageExt (nars.language.ImageExt)3 ImageInt (nars.language.ImageInt)3 Product (nars.language.Product)3 Similarity (nars.language.Similarity)3