Search in sources :

Example 11 with Product

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

the class StructuralRules method structuralDecompose2.

/**
 * {<(S*T) --> (P*T)>, S@(S*T)} |- <S --> P>
 *
 * @param statement The premise
 * @param nal Reference to the memory
 */
static void structuralDecompose2(Statement statement, int index, DerivationContext nal) {
    Term subj = statement.getSubject();
    Term pred = statement.getPredicate();
    if (subj.getClass() != pred.getClass()) {
        return;
    }
    if (!(subj instanceof Product) && !(subj instanceof SetExt) && !(subj instanceof SetInt)) {
        // no abduction on other compounds for now, but may change in the future
        return;
    }
    CompoundTerm sub = (CompoundTerm) subj;
    CompoundTerm pre = (CompoundTerm) pred;
    if (sub.size() != pre.size() || sub.size() <= index) {
        return;
    }
    Term t1 = sub.term[index];
    Term t2 = pre.term[index];
    Statement content;
    int order = statement.getTemporalOrder();
    if (switchOrder(sub, (short) index)) {
        content = Statement.make(statement, t2, t1, TemporalRules.reverseOrder(order));
    } else {
        content = Statement.make(statement, t1, t2, order);
    }
    if (content == null) {
        return;
    }
    Task task = nal.getCurrentTask();
    Sentence sentence = task.sentence;
    TruthValue truth = sentence.truth;
    BudgetValue budget;
    if (sentence.isQuestion() || sentence.isQuest()) {
        budget = BudgetFunctions.compoundBackward(content, nal);
    } else {
        budget = BudgetFunctions.compoundForward(truth, content, nal);
    }
    nal.singlePremiseTask(content, truth, budget);
}
Also used : CompoundTerm(nars.language.CompoundTerm) BudgetValue(nars.entity.BudgetValue) Task(nars.entity.Task) Statement(nars.language.Statement) TruthValue(nars.entity.TruthValue) SetExt(nars.language.SetExt) Product(nars.language.Product) SetInt(nars.language.SetInt) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term) Sentence(nars.entity.Sentence)

Example 12 with Product

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

the class MathExpression method getTerms.

public static Term getTerms(List<TreeNode> children) {
    if (children.size() == 1)
        return getTerm(children.get(0));
    Term[] c = new Term[children.size()];
    int j = 0;
    for (TreeNode t : children) {
        c[j++] = getTerm(t);
    }
    return new Product(c);
}
Also used : TreeNode(org.encog.ml.tree.TreeNode) Product(nars.language.Product) Term(nars.language.Term)

Aggregations

Product (nars.language.Product)12 Term (nars.language.Term)11 BudgetValue (nars.entity.BudgetValue)7 TruthValue (nars.entity.TruthValue)7 CompoundTerm (nars.language.CompoundTerm)6 Sentence (nars.entity.Sentence)5 Inheritance (nars.language.Inheritance)5 Task (nars.entity.Task)4 Conjunction (nars.language.Conjunction)3 Interval (nars.language.Interval)3 Statement (nars.language.Statement)3 Memory (nars.storage.Memory)3 Stamp (nars.entity.Stamp)2 ImageExt (nars.language.ImageExt)2 ImageInt (nars.language.ImageInt)2 Implication (nars.language.Implication)2 SetExt (nars.language.SetExt)2 ExpressionValue (org.encog.ml.prg.expvalue.ExpressionValue)2 TreeNode (org.encog.ml.tree.TreeNode)2 ArrayList (java.util.ArrayList)1