use of org.jmathml.ASTRootNode in project vcell by virtualcell.
the class SEDMLReader method getSetValueContent.
private SetValue getSetValueContent(SetValue c, Element element) throws DataConversionException {
List<Element> children = element.getChildren();
Iterator<Element> iChildren = children.iterator();
while (iChildren.hasNext()) {
Element eChild = (Element) iChildren.next();
if (eChild.getName().equals(SEDMLTags.CHANGE_ATTR_MATH)) {
ASTNode math = (ASTRootNode) new MathMLReader().parseMathML(eChild);
c.setMath(math);
} else if (eChild.getName().equals(SEDMLTags.DATAGEN_ATTR_VARS_LIST)) {
List<Element> lVariables = eChild.getChildren();
Iterator<Element> iVariables = lVariables.iterator();
while (iVariables.hasNext()) {
Element eVariable = (Element) iVariables.next();
if (eVariable.getName().equals(SEDMLTags.DATAGEN_ATTR_VARIABLE)) {
c.addVariable(createVariable(eVariable, true));
}
}
} else if (eChild.getName().equals(SEDMLTags.DATAGEN_ATTR_PARAMS_LIST)) {
List<Element> lParameters = eChild.getChildren();
Iterator<Element> iParameters = lParameters.iterator();
while (iParameters.hasNext()) {
Element eParameter = (Element) iParameters.next();
if (eParameter.getName().equals(SEDMLTags.DATAGEN_ATTR_PARAMETER)) {
c.addParameter(createParameter(eParameter));
}
}
} else {
log.warn("Unexpected " + eChild);
}
}
return c;
}
use of org.jmathml.ASTRootNode in project vcell by virtualcell.
the class Libsedml method parseFormulaString.
/**
* Convenience method to parse free text math into an ASTNode. The style of
* math is a C-style syntax, e.g.,<br/>
* . The parsing supports standard arithmetical operations and function
* calls. E.g.,
*
* <ul>
* <li>4 + 2
* <li>sin(pi / 2) // or any other trig function
* <li>log(9,81) // = 2
* <li>root(4,81) //=3
* <li>exp(t)
* </ul>
* <p>
* In addition, the strings <code>pi</code>, <code>NaN</code>,
* <code>infinity</code> and <code>exponentiale</code> are translated into
* constants.
* </p>
*
* Functions not supported by this library ( see ASTFunctionType for
* supported functions ) will be parsed into a function call, which will not
* be evaluable. E.g., <br/>
*
* <pre>
* myfunction(a, b)
* </pre>
*
* can be turned into an ASTNode, but will not be evaluable, unless a symbol
* definition class is supplied. (See the
* <code>org.jlibsedml.mathsymbols</code> package for how the SED-ML
* aggregate functions are supported).
*
* @param math
* A <code>String</code> of math.
* @return An {@link ASTNode}. This will be an {@link ASTRootNode} with the
* math nodes as children. E.g., the string
*
* <pre>
* 2 * (4 / 5)
* </pre>
* will return the structure:
* <pre>
* ASTRootNode
* ASTimes
* ASTCn(2)
* ASTDivide
* ASTCn(4)
* ASTCn(5)
* </pre>
*
* If <code>math</code> is null or empty, returns <code>null</code>.
* @throws RuntimeException
* if mathString cannot be parsed due to incorrect syntax.
*/
public static ASTNode parseFormulaString(String math) {
if (math == null || math.length() == 0) {
return null;
}
ASTRootNode rc = new ASTRootNode();
new TextToASTNodeMathParser2().parseString(math, rc);
return rc;
}
use of org.jmathml.ASTRootNode in project vcell by virtualcell.
the class SEDMLReader method addFunctionalRangeLists.
private void addFunctionalRangeLists(Range r, Element element) throws DataConversionException {
String childName = null;
List<Element> children = element.getChildren();
Iterator<Element> iChildren = children.iterator();
while (iChildren.hasNext()) {
Element eChild = (Element) iChildren.next();
childName = eChild.getName();
if (eChild.getName().equals(SEDMLTags.FUNCTIONAL_RANGE_VAR_LIST)) {
addFunctionalRangeVariable(r, eChild);
} else if (eChild.getName().equals(SEDMLTags.FUNCTIONAL_RANGE_PAR_LIST)) {
addFunctionalRangeParameter(r, eChild);
} else if (eChild.getName().equals(SEDMLTags.FUNCTION_MATH_TAG)) {
ASTNode math = (ASTRootNode) new MathMLReader().parseMathML(eChild);
log.debug("r " + math.toString());
((FunctionalRange) r).setMath(math);
} else {
log.warn("Unexpected " + eChild);
}
}
}
use of org.jmathml.ASTRootNode in project vcell by virtualcell.
the class SEDMLReader method getChange.
Change getChange(Element aChange) throws DataConversionException {
Change rc = null;
if (aChange.getName().equals(SEDMLTags.CHANGE_ATTRIBUTE)) {
rc = new ChangeAttribute(new XPathTarget(aChange.getAttributeValue(SEDMLTags.CHANGE_ATTR_TARGET)), aChange.getAttributeValue(SEDMLTags.CHANGE_ATTR_NEWVALUE));
} else if (aChange.getName().equals(SEDMLTags.CHANGE_XML) || aChange.getName().equals(SEDMLTags.ADD_XML)) {
Iterator<Element> changeChildren = aChange.getChildren().iterator();
while (changeChildren.hasNext()) {
Element el = (Element) changeChildren.next();
if (el.getName().equals(SEDMLTags.NEW_XML)) {
List<Element> xml = getNewXML(el);
NewXML newxml = new NewXML(xml);
if (aChange.getName().equals(SEDMLTags.CHANGE_XML))
rc = new ChangeXML(new XPathTarget(aChange.getAttributeValue(SEDMLTags.CHANGE_ATTR_TARGET)), newxml);
else
rc = new AddXML(new XPathTarget(aChange.getAttributeValue(SEDMLTags.CHANGE_ATTR_TARGET)), newxml);
}
}
} else if (aChange.getName().equals(SEDMLTags.REMOVE_XML)) {
rc = new RemoveXML(new XPathTarget(aChange.getAttributeValue(SEDMLTags.CHANGE_ATTR_TARGET)));
} else if (aChange.getName().equals(SEDMLTags.COMPUTE_CHANGE)) {
ASTRootNode math = null;
Element toAdd = null;
List<Variable> vars = new ArrayList<Variable>();
List<Parameter> params = new ArrayList<Parameter>();
Iterator<Element> changeChildren = aChange.getChildren().iterator();
while (changeChildren.hasNext()) {
Element el = (Element) changeChildren.next();
if (el.getName().equals(SEDMLTags.CHANGE_ATTR_MATH)) {
math = (ASTRootNode) new MathMLReader().parseMathML(el);
} else if (el.getName().equals(SEDMLTags.DATAGEN_ATTR_VARS_LIST)) {
List<Element> lVariables = el.getChildren();
Iterator<Element> iVariables = lVariables.iterator();
while (iVariables.hasNext()) {
Element eVariable = (Element) iVariables.next();
if (eVariable.getName().equals(SEDMLTags.DATAGEN_ATTR_VARIABLE)) {
vars.add(createVariable(eVariable, true));
}
}
} else if (el.getName().equals(SEDMLTags.DATAGEN_ATTR_PARAMS_LIST)) {
List<Element> lParameters = el.getChildren();
Iterator<Element> iParameters = lParameters.iterator();
while (iParameters.hasNext()) {
Element eParameter = (Element) iParameters.next();
if (eParameter.getName().equals(SEDMLTags.DATAGEN_ATTR_PARAMETER)) {
params.add(createParameter(eParameter));
}
}
}
// TODO: variable and parameter need to be also
// loaded here
}
ComputeChange cc = new ComputeChange(new XPathTarget(aChange.getAttributeValue(SEDMLTags.CHANGE_ATTR_TARGET)), math);
cc.setListOfParameters(params);
cc.setListOfVariables(vars);
rc = cc;
}
addNotesAndAnnotation(rc, aChange);
return rc;
}
Aggregations