use of org.encog.ml.tree.TreeNode 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));
}
use of org.encog.ml.tree.TreeNode 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);
}
Aggregations