use of org.encog.ml.prg.expvalue.ExpressionValue 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.prg.expvalue.ExpressionValue 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);
}
Aggregations