Search in sources :

Example 1 with SedMLSymbolFactory

use of org.jlibsedml.mathsymbols.SedMLSymbolFactory in project vcell by virtualcell.

the class SEDMLReader method getSedDocument.

/*
	 * returns a SedML model given an Element of xml for a complete model non -
	 * api method
	 */
public SedML getSedDocument(Element sedRoot) throws XMLException {
    SedML sedDoc = null;
    SymbolRegistry.getInstance().addSymbolFactory(new SedMLSymbolFactory());
    try {
        Namespace sedNS = sedRoot.getNamespace();
        String verStr = sedRoot.getAttributeValue(SEDMLTags.VERSION_TAG);
        String lvlStr = sedRoot.getAttributeValue(SEDMLTags.LEVEL_TAG);
        if (verStr != null && lvlStr != null) {
            int sedVersion = Integer.parseInt(verStr);
            int sedLevel = Integer.parseInt(lvlStr);
            sedDoc = new SedML(sedLevel, sedVersion, sedNS);
        } else {
            sedDoc = new SedML(sedNS);
        }
        // Get additional namespaces if mentioned : mathml, sbml, etc.
        List additionalNamespaces = sedRoot.getAdditionalNamespaces();
        sedDoc.setAdditionalNamespaces(additionalNamespaces);
        // notes and annotations
        addNotesAndAnnotation(sedDoc, sedRoot);
        Iterator<Element> elementsIter = null;
        // models
        Element el = sedRoot.getChild(SEDMLTags.MODELS, sedNS);
        if (el != null) {
            List elementsList = el.getChildren();
            elementsIter = elementsList.iterator();
            while (elementsIter.hasNext()) {
                Element modelElement = elementsIter.next();
                if (modelElement.getName().equals(SEDMLTags.MODEL_TAG)) {
                    sedDoc.addModel(getModel(modelElement));
                }
            }
        }
        // simulations
        el = sedRoot.getChild(SEDMLTags.SIMS, sedNS);
        if (el != null) {
            List elementsList = el.getChildren();
            elementsIter = elementsList.iterator();
            while (elementsIter.hasNext()) {
                Element simElement = elementsIter.next();
                sedDoc.addSimulation(getSimulation(simElement));
            }
        }
        el = sedRoot.getChild(SEDMLTags.TASKS, sedNS);
        if (el != null) {
            List elementsList = el.getChildren();
            elementsIter = elementsList.iterator();
            while (elementsIter.hasNext()) {
                Element taskElement = elementsIter.next();
                if (taskElement.getName().equals(SEDMLTags.TASK_TAG)) {
                    sedDoc.addTask(getTask(taskElement));
                } else if (taskElement.getName().equals(SEDMLTags.REPEATED_TASK_TAG)) {
                    sedDoc.addTask(getRepeatedTask(taskElement));
                }
            }
        }
        el = sedRoot.getChild(SEDMLTags.DATAGENERATORS, sedNS);
        if (el != null) {
            List elementsList = el.getChildren();
            elementsIter = elementsList.iterator();
            while (elementsIter.hasNext()) {
                Element dataGenElement = elementsIter.next();
                if (dataGenElement.getName().equals(SEDMLTags.DATAGENERATOR_TAG)) {
                    sedDoc.addDataGenerator(getDataGenerator(dataGenElement));
                }
            }
        }
        el = sedRoot.getChild(SEDMLTags.OUTPUTS, sedNS);
        if (el != null) {
            List elementsList = el.getChildren();
            elementsIter = elementsList.iterator();
            while (elementsIter.hasNext()) {
                Element outputElement = elementsIter.next();
                if (outputElement.getName().equals(SEDMLTags.OUTPUT_P2D) || outputElement.getName().equals(SEDMLTags.OUTPUT_P3D) || outputElement.getName().equals(SEDMLTags.OUTPUT_REPORT)) {
                    sedDoc.addOutput(getOutput(outputElement));
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace(System.out);
        throw new XMLException("Error loading sed-ml document : " + e.getMessage());
    // return sedDoc;
    }
    return sedDoc;
}
Also used : SedMLSymbolFactory(org.jlibsedml.mathsymbols.SedMLSymbolFactory) Element(org.jdom.Element) ArrayList(java.util.ArrayList) List(java.util.List) Namespace(org.jdom.Namespace) DataConversionException(org.jdom.DataConversionException) IOException(java.io.IOException) JDOMException(org.jdom.JDOMException)

Example 2 with SedMLSymbolFactory

use of org.jlibsedml.mathsymbols.SedMLSymbolFactory in project vcell by virtualcell.

the class Libsedml method MathMLXMLToText.

/**
 * Converts a string representation of a MathML XML structure to a C-style
 * string.
 *
 * @param mathml
 *            A <code>string</code> of MathML
 * @return A <code>String</code> of C style math syntax, or an error string
 *         if it could not be converted.
 */
public static String MathMLXMLToText(String mathml) {
    SymbolRegistry.getInstance().addSymbolFactory(new SedMLSymbolFactory());
    String text = MathMLReader.MathMLXMLToText(mathml);
    if (hasExtraSurroundingParentheses(text)) {
        return text.substring(1, text.length() - 1);
    } else {
        return text;
    }
}
Also used : SedMLSymbolFactory(org.jlibsedml.mathsymbols.SedMLSymbolFactory)

Aggregations

SedMLSymbolFactory (org.jlibsedml.mathsymbols.SedMLSymbolFactory)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 DataConversionException (org.jdom.DataConversionException)1 Element (org.jdom.Element)1 JDOMException (org.jdom.JDOMException)1 Namespace (org.jdom.Namespace)1