Search in sources :

Example 1 with Product

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

the class MathExpression method getTerm.

public static Term getTerm(TreeNode node) {
    CharSequence name = node instanceof ProgramNode ? ("\"" + Texts.escape(((ProgramNode) node).getName()) + '\"') : node.getClass().getSimpleName();
    List<TreeNode> children = node.getChildNodes();
    ExpressionValue[] data = null;
    ProgramNode p = (ProgramNode) node;
    data = p.getData();
    if ((children == null) || (children.isEmpty())) {
        if ((data == null) || (data.length == 0) || (p.isVariable())) {
            if (p.isVariable()) {
                long idx = data[0].toIntValue();
                String varname = p.getOwner().getVariables().getVariableName((int) idx);
                return Term.get(varname);
            }
            return Term.get(name);
        } else
            return getTerms(data);
    }
    if ((data != null) && (data.length > 0))
        return Inheritance.make(new Product(getTerms(children), getTerms(data)), Term.get(name));
    else
        return Inheritance.make(getTerms(children), Term.get(name));
}
Also used : ProgramNode(org.encog.ml.prg.ProgramNode) ExpressionValue(org.encog.ml.prg.expvalue.ExpressionValue) TreeNode(org.encog.ml.tree.TreeNode) Product(nars.language.Product)

Example 2 with Product

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

the class MathExpression method getTerms.

public static Term getTerms(ExpressionValue[] data) {
    if (data.length == 1)
        return getTerm(data[0]);
    Term[] c = new Term[data.length];
    int j = 0;
    for (ExpressionValue t : data) {
        c[j++] = getTerm(t);
    }
    return new Product(c);
}
Also used : ExpressionValue(org.encog.ml.prg.expvalue.ExpressionValue) Product(nars.language.Product) Term(nars.language.Term)

Example 3 with Product

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

the class InternalExperience method toTerm.

public static Term toTerm(final Sentence s, final Memory mem) {
    String opName;
    switch(s.punctuation) {
        case Symbols.JUDGMENT_MARK:
            opName = "^believe";
            if (!AllowWantBelieve) {
                return null;
            }
            break;
        case Symbols.GOAL_MARK:
            opName = "^want";
            if (!AllowWantBelieve) {
                return null;
            }
            break;
        case Symbols.QUESTION_MARK:
            opName = "^wonder";
            break;
        case Symbols.QUEST_MARK:
            opName = "^evaluate";
            break;
        default:
            return null;
    }
    Term opTerm = mem.getOperator(opName);
    Term[] arg = new Term[s.truth == null ? 2 : 3];
    arg[0] = Term.SELF;
    arg[1] = s.getTerm();
    if (s.truth != null) {
        arg[2] = s.projection(mem.time(), mem.time()).truth.toWordTerm();
    }
    // Operation.make ?
    Term operation = Inheritance.make(new Product(arg), opTerm);
    if (operation == null) {
        throw new RuntimeException("Unable to create Inheritance: " + opTerm + ", " + Arrays.toString(arg));
    }
    return operation;
}
Also used : Product(nars.language.Product) Term(nars.language.Term)

Example 4 with Product

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

the class StructuralRules method transformSubjectPI.

/**
 * Equivalent transformation between products and images when the subject 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 transformSubjectPI(short index, CompoundTerm subject, Term predicate, DerivationContext nal) {
    TruthValue truth = nal.getCurrentTask().sentence.truth;
    BudgetValue budget;
    Inheritance inheritance;
    Term newSubj, newPred;
    if (subject instanceof Product) {
        Product product = (Product) subject;
        short i = index;
        /*for (short i = 0; i < product.size(); i++)*/
        {
            newSubj = product.term[i];
            newPred = ImageExt.make(product, predicate, i);
            if (!(newSubj instanceof Interval)) {
                // no intervals as subjects
                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 (subject instanceof ImageInt) {
        ImageInt image = (ImageInt) subject;
        int relationIndex = image.relationIndex;
        for (short i = 0; i < image.size(); i++) {
            if (i == relationIndex) {
                newSubj = image.term[relationIndex];
                newPred = Product.make(image, predicate, relationIndex);
            } else {
                newSubj = ImageInt.make(image, predicate, i);
                newPred = image.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);
            }
        }
    }
}
Also used : BudgetValue(nars.entity.BudgetValue) TruthValue(nars.entity.TruthValue) Inheritance(nars.language.Inheritance) Product(nars.language.Product) ImageInt(nars.language.ImageInt) CompoundTerm(nars.language.CompoundTerm) Term(nars.language.Term) Interval(nars.language.Interval)

Example 5 with Product

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

the class StructuralRules method seqToImage.

public static void seqToImage(Conjunction conj, int index, DerivationContext nal) {
    // extensional
    int side = 0;
    short[] indices = new short[] { (short) side, (short) index };
    Product subject = Product.make(conj.term);
    Term predicate = Term.SEQ_TEMPORAL;
    if (conj.isSpatial) {
        predicate = Term.SEQ_SPATIAL;
    }
    Inheritance inh = Inheritance.make(subject, predicate);
    StructuralRules.transformProductImage(inh, inh, indices, nal);
}
Also used : Inheritance(nars.language.Inheritance) Product(nars.language.Product) CompoundTerm(nars.language.CompoundTerm) 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