Search in sources :

Example 1 with MathMLReader

use of org.jmathml.MathMLReader in project vcell by virtualcell.

the class SEDMLExporter method getFormulaFromExpression.

// private String getKiSAOIdFromSimulation(SolverDescription solverDesc) {
// String kiSAOId = null;
// try {
// // Create KiSAOQueryMaker instance, which uses last version of kisao.owl ontology
// // (URL: http://biomodels.net/kisao/KISAO).
// net.biomodels.kisao.IKiSAOQueryMaker kisaoQuery = new net.biomodels.kisao.impl.KiSAOQueryMaker();
// String solverName = solverDesc.getShortDisplayLabel();
// String cvodeSolverName = SolverDescription.CVODE.getShortDisplayLabel();
// if (!solverName.equalsIgnoreCase(cvodeSolverName)) {
// Set<IRI> iriSet = kisaoQuery.searchByName(solverName);
// while (kiSAOId == null && iriSet != null && iriSet.iterator().hasNext()) {
// IRI iri = iriSet.iterator().next();
// kiSAOId = kisaoQuery.getId(iri);
// String kiSAOName = kisaoQuery.getName(iri);
// // System.out.printf("solver name : " + kiSAOName + " (" + kiSAOId + ")\n");
// }
// }
// // At this point, either the solver is CVODE or kiSAO id could not be found for non-CVODE solver
// // for now : if a match for solver name is not found in KiSAO, set it to CVODE
// if (kiSAOId == null) {
// IRI iri = kisaoQuery.searchByName(cvodeSolverName).iterator().next();
// kiSAOId = kisaoQuery.getId(iri);
// String kiSAOName = kisaoQuery.getName(iri);
// // System.out.printf("solver name : " + kiSAOName + " (" + kiSAOId + ")\n");
// }
// } catch (OWLOntologyCreationException e) {
// e.printStackTrace(System.err);
// }
// return kiSAOId;
// }
public static ASTNode getFormulaFromExpression(Expression expression) {
    // Convert expression into MathML string
    String expMathMLStr = null;
    try {
        expMathMLStr = cbit.vcell.parser.ExpressionMathMLPrinter.getMathML(expression, false);
    } catch (java.io.IOException e) {
        e.printStackTrace(System.out);
        throw new RuntimeException("Error converting expression to MathML string :" + e.getMessage());
    } catch (cbit.vcell.parser.ExpressionException e1) {
        e1.printStackTrace(System.out);
        throw new RuntimeException("Error converting expression to MathML string :" + e1.getMessage());
    }
    // Use libSBMl routines to convert MathML string to MathML document and a libSBML-readable formula string
    MathMLReader mmlr = new MathMLReader();
    ASTNode mathNode = null;
    try {
        mathNode = mmlr.parseMathMLFromString(expMathMLStr);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace(System.out);
        throw new RuntimeException("Error converting MathML string to ASTNode:" + e.getMessage());
    }
    return mathNode;
// return mathNode.deepCopy();
}
Also used : MathMLReader(org.jmathml.MathMLReader) ASTNode(org.jmathml.ASTNode) IOException(java.io.IOException) ExpressionException(cbit.vcell.parser.ExpressionException) IOException(java.io.IOException)

Aggregations

ExpressionException (cbit.vcell.parser.ExpressionException)1 IOException (java.io.IOException)1 ASTNode (org.jmathml.ASTNode)1 MathMLReader (org.jmathml.MathMLReader)1