Search in sources :

Example 16 with Inheritance

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

the class RuleTables method syllogisms.

/* ----- syllogistic inferences ----- */
/**
 * Meta-table of syllogistic rules, indexed by the content classes of the
 * taskSentence and the belief
 *
 * @param tLink The link to task
 * @param bLink The link to belief
 * @param taskTerm The content of task
 * @param beliefTerm The content of belief
 * @param nal Reference to the memory
 */
private static void syllogisms(TaskLink tLink, TermLink bLink, Term taskTerm, Term beliefTerm, DerivationContext nal) {
    Sentence taskSentence = nal.getCurrentTask().sentence;
    Sentence belief = nal.getCurrentBelief();
    int figure;
    if (taskTerm instanceof Inheritance) {
        if (beliefTerm instanceof Inheritance) {
            figure = indexToFigure(tLink, bLink);
            asymmetricAsymmetric(taskSentence, belief, figure, nal);
        } else if (beliefTerm instanceof Similarity) {
            figure = indexToFigure(tLink, bLink);
            asymmetricSymmetric(taskSentence, belief, figure, nal);
        } else {
            detachmentWithVar(belief, taskSentence, bLink.getIndex(0), nal);
        }
    } else if (taskTerm instanceof Similarity) {
        if (beliefTerm instanceof Inheritance) {
            figure = indexToFigure(bLink, tLink);
            asymmetricSymmetric(belief, taskSentence, figure, nal);
        } else if (beliefTerm instanceof Similarity) {
            figure = indexToFigure(bLink, tLink);
            symmetricSymmetric(belief, taskSentence, figure, nal);
        } else if (beliefTerm instanceof Implication) {
            // Bridge to higher order statements:
            figure = indexToFigure(tLink, bLink);
            asymmetricSymmetric(belief, taskSentence, figure, nal);
        } else if (beliefTerm instanceof Equivalence) {
            // Bridge to higher order statements:
            figure = indexToFigure(tLink, bLink);
            symmetricSymmetric(belief, taskSentence, figure, nal);
        }
    } else if (taskTerm instanceof Implication) {
        if (beliefTerm instanceof Implication) {
            figure = indexToFigure(tLink, bLink);
            asymmetricAsymmetric(taskSentence, belief, figure, nal);
        } else if (beliefTerm instanceof Equivalence) {
            figure = indexToFigure(tLink, bLink);
            asymmetricSymmetric(taskSentence, belief, figure, nal);
        } else if (beliefTerm instanceof Inheritance) {
            detachmentWithVar(taskSentence, belief, tLink.getIndex(0), nal);
        } else if (beliefTerm instanceof Similarity) {
            // Bridge to higher order statements:
            figure = indexToFigure(tLink, bLink);
            asymmetricSymmetric(taskSentence, belief, figure, nal);
        }
    } else if (taskTerm instanceof Equivalence) {
        if (beliefTerm instanceof Implication) {
            figure = indexToFigure(bLink, tLink);
            asymmetricSymmetric(belief, taskSentence, figure, nal);
        } else if (beliefTerm instanceof Equivalence) {
            figure = indexToFigure(bLink, tLink);
            symmetricSymmetric(belief, taskSentence, figure, nal);
        } else if (beliefTerm instanceof Inheritance) {
            detachmentWithVar(taskSentence, belief, tLink.getIndex(0), nal);
        } else if (beliefTerm instanceof Similarity) {
            // Bridge to higher order statements:
            figure = indexToFigure(tLink, bLink);
            symmetricSymmetric(belief, taskSentence, figure, nal);
        }
    }
}
Also used : Similarity(nars.language.Similarity) Equivalence(nars.language.Equivalence) Inheritance(nars.language.Inheritance) Sentence(nars.entity.Sentence) Implication(nars.language.Implication)

Example 17 with Inheritance

use of nars.language.Inheritance 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 18 with Inheritance

use of nars.language.Inheritance 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 19 with Inheritance

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

Aggregations

Inheritance (nars.language.Inheritance)19 Term (nars.language.Term)18 CompoundTerm (nars.language.CompoundTerm)15 TruthValue (nars.entity.TruthValue)12 BudgetValue (nars.entity.BudgetValue)11 Statement (nars.language.Statement)9 Sentence (nars.entity.Sentence)8 Task (nars.entity.Task)8 Conjunction (nars.language.Conjunction)6 Implication (nars.language.Implication)6 Product (nars.language.Product)5 SetExt (nars.language.SetExt)4 Similarity (nars.language.Similarity)4 Variable (nars.language.Variable)4 Stamp (nars.entity.Stamp)3 Equivalence (nars.language.Equivalence)3 ImageExt (nars.language.ImageExt)3 ImageInt (nars.language.ImageInt)3 Interval (nars.language.Interval)3 SetInt (nars.language.SetInt)3