Search in sources :

Example 86 with Term

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

the class RuleTables method conditionalDedIndWithVar.

/**
 * Conditional deduction or induction, with variable unification
 *
 * @param conditional The premise that is an Implication with a Conjunction
 * as condition
 * @param index The location of the shared term in the condition
 * @param statement The second premise that is a statement
 * @param side The location of the shared term in the statement
 * @param nal Reference to the memory
 */
private static void conditionalDedIndWithVar(Sentence conditionalSentence, Implication conditional, short index, Statement statement, short side, DerivationContext nal) {
    if (!(conditional.getSubject() instanceof CompoundTerm))
        return;
    CompoundTerm condition = (CompoundTerm) conditional.getSubject();
    if (condition instanceof Conjunction) {
        // conditionalDedIndWithVar
        for (Term t : condition.term) {
            // does not support the case where
            if (t instanceof Variable) {
                // (this can happen since we have # due to image transform,
                return;
            }
        // although not for other conjunctions)
        }
    }
    Term component = condition.term[index];
    Term component2 = null;
    if (statement instanceof Inheritance) {
        component2 = statement;
        side = -1;
    } else if (statement instanceof Implication) {
        component2 = statement.term[side];
    }
    if (component2 != null) {
        Term[] u = new Term[] { conditional, statement };
        if (Variables.unify(VAR_INDEPENDENT, component, component2, u)) {
            conditional = (Implication) u[0];
            statement = (Statement) u[1];
            SyllogisticRules.conditionalDedInd(conditionalSentence, conditional, index, statement, side, nal);
        }
    }
}
Also used : CompoundTerm(nars.language.CompoundTerm) Variable(nars.language.Variable) Inheritance(nars.language.Inheritance) Conjunction(nars.language.Conjunction) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term) Implication(nars.language.Implication)

Example 87 with Term

use of nars.language.Term 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 88 with Term

use of nars.language.Term 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 89 with Term

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

the class RuleTables method transformTask.

/* ----- inference with one TaskLink only ----- */
/**
 * The TaskLink is of type TRANSFORM, and the conclusion is an equivalent
 * transformation
 *
 * @param tLink The task link
 * @param nal Reference to the memory
 */
public static void transformTask(TaskLink tLink, DerivationContext nal) {
    CompoundTerm content = (CompoundTerm) nal.getCurrentTask().getTerm();
    short[] indices = tLink.index;
    Term inh = null;
    if ((indices.length == 2) || (content instanceof Inheritance)) {
        // <(*, term, #) --> #>
        inh = content;
    } else if (indices.length == 3) {
        // <<(*, term, #) --> #> ==> #>
        inh = content.term[indices[0]];
    } else if (indices.length == 4) {
        // <(&&, <(*, term, #) --> #>, #) ==> #>
        Term component = content.term[indices[0]];
        if ((component instanceof Conjunction) && (((content instanceof Implication) && (indices[0] == 0)) || (content instanceof Equivalence))) {
            Term[] cterms = ((CompoundTerm) component).term;
            if (indices[1] < cterms.length - 1) {
                inh = cterms[indices[1]];
            } else {
                return;
            }
        } else {
            return;
        }
    }
    if (inh instanceof Inheritance) {
        StructuralRules.transformProductImage((Inheritance) inh, content, indices, nal);
    }
}
Also used : CompoundTerm(nars.language.CompoundTerm) Equivalence(nars.language.Equivalence) Inheritance(nars.language.Inheritance) Conjunction(nars.language.Conjunction) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term) Implication(nars.language.Implication)

Example 90 with Term

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

the class RuleTables method goalFromQuestion.

private static void goalFromQuestion(final Task task, final Term taskTerm, final DerivationContext nal) {
    if (task.sentence.punctuation == Symbols.QUESTION_MARK && (taskTerm instanceof Implication || taskTerm instanceof Equivalence)) {
        // <a =/> b>? |- a!
        Term goalterm = null;
        Term goalterm2 = null;
        if (taskTerm instanceof Implication) {
            Implication imp = (Implication) taskTerm;
            if (imp.getTemporalOrder() != TemporalRules.ORDER_BACKWARD || imp.getTemporalOrder() == TemporalRules.ORDER_CONCURRENT) {
                if (!Parameters.CURIOSITY_FOR_OPERATOR_ONLY || imp.getSubject() instanceof Operation) {
                    goalterm = imp.getSubject();
                }
                if (goalterm instanceof Variable && goalterm.hasVarQuery() && (!Parameters.CURIOSITY_FOR_OPERATOR_ONLY || imp.getPredicate() instanceof Operation)) {
                    // overwrite, it is a how question, in case of <?how =/> b> it is b! which is desired
                    goalterm = imp.getPredicate();
                }
            } else if (imp.getTemporalOrder() == TemporalRules.ORDER_BACKWARD) {
                if (!Parameters.CURIOSITY_FOR_OPERATOR_ONLY || imp.getPredicate() instanceof Operation) {
                    goalterm = imp.getPredicate();
                }
                if (goalterm instanceof Variable && goalterm.hasVarQuery() && (!Parameters.CURIOSITY_FOR_OPERATOR_ONLY || imp.getSubject() instanceof Operation)) {
                    // overwrite, it is a how question, in case of <?how =/> b> it is b! which is desired
                    goalterm = imp.getSubject();
                }
            }
        } else if (taskTerm instanceof Equivalence) {
            Equivalence qu = (Equivalence) taskTerm;
            if (qu.getTemporalOrder() == TemporalRules.ORDER_FORWARD || qu.getTemporalOrder() == TemporalRules.ORDER_CONCURRENT) {
                if (!Parameters.CURIOSITY_FOR_OPERATOR_ONLY || qu.getSubject() instanceof Operation) {
                    goalterm = qu.getSubject();
                }
                if (!Parameters.CURIOSITY_FOR_OPERATOR_ONLY || qu.getPredicate() instanceof Operation) {
                    goalterm2 = qu.getPredicate();
                }
            }
        }
        TruthValue truth = new TruthValue(1.0f, Parameters.DEFAULT_GOAL_CONFIDENCE * Parameters.CURIOSITY_DESIRE_CONFIDENCE_MUL);
        if (goalterm != null && !(goalterm instanceof Variable) && goalterm instanceof CompoundTerm) {
            goalterm = ((CompoundTerm) goalterm).transformIndependentVariableToDependentVar((CompoundTerm) goalterm);
            Sentence sent = new Sentence(goalterm, Symbols.GOAL_MARK, truth, new Stamp(task.sentence.stamp, nal.memory.time()));
            nal.singlePremiseTask(sent, new BudgetValue(task.getPriority() * Parameters.CURIOSITY_DESIRE_PRIORITY_MUL, task.getDurability() * Parameters.CURIOSITY_DESIRE_DURABILITY_MUL, BudgetFunctions.truthToQuality(truth)));
        }
        if (goalterm2 != null && !(goalterm2 instanceof Variable) && goalterm2 instanceof CompoundTerm) {
            goalterm2 = ((CompoundTerm) goalterm).transformIndependentVariableToDependentVar((CompoundTerm) goalterm2);
            Sentence sent = new Sentence(goalterm2, Symbols.GOAL_MARK, truth.clone(), new Stamp(task.sentence.stamp, nal.memory.time()));
            nal.singlePremiseTask(sent, new BudgetValue(task.getPriority() * Parameters.CURIOSITY_DESIRE_PRIORITY_MUL, task.getDurability() * Parameters.CURIOSITY_DESIRE_DURABILITY_MUL, BudgetFunctions.truthToQuality(truth)));
        }
    }
}
Also used : CompoundTerm(nars.language.CompoundTerm) BudgetValue(nars.entity.BudgetValue) Variable(nars.language.Variable) Equivalence(nars.language.Equivalence) Stamp(nars.entity.Stamp) TruthValue(nars.entity.TruthValue) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term) Operation(nars.operator.Operation) 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