Search in sources :

Example 1 with ProgramNode

use of org.encog.ml.prg.ProgramNode 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)

Aggregations

Product (nars.language.Product)1 ProgramNode (org.encog.ml.prg.ProgramNode)1 ExpressionValue (org.encog.ml.prg.expvalue.ExpressionValue)1 TreeNode (org.encog.ml.tree.TreeNode)1