All Downloads are FREE. Search and download functionalities are using the official Maven repository.

JSci.io.MathMLParser Maven / Gradle / Ivy

Go to download

JSci is a set of open source Java packages. The aim is to encapsulate scientific methods/principles in the most natural way possible. As such they should greatly aid the development of scientific based software. It offers: abstract math interfaces, linear algebra (support for various matrix and vector types), statistics (including probability distributions), wavelets, newtonian mechanics, chart/graph components (AWT and Swing), MathML DOM implementation, ... Note: some packages, like javax.comm, for the astro and instruments package aren't listed as dependencies (not available).

The newest version!
package JSci.io;

import java.util.Set;
import java.util.HashSet;
import JSci.maths.*;
import JSci.maths.matrices.*;
import JSci.maths.vectors.*;
import JSci.maths.fields.*;
import org.w3c.dom.*;
import org.w3c.dom.mathml.*;
import org.xml.sax.SAXNotRecognizedException;
import org.xml.sax.SAXNotSupportedException;
import org.apache.xerces.parsers.DOMParser;

/**
* The MathMLParser class will parse a MathML document into JSci objects.
* @version 0.9
* @author Mark Hale
*/
public final class MathMLParser extends DOMParser {
        /**
        * Constructs a MathMLParser.
        */
        public MathMLParser() {
                try {
                        setProperty("http://apache.org/xml/properties/dom/document-class-name", "JSci.mathml.MathMLDocumentImpl");
                } catch(SAXNotRecognizedException e) {
                        e.printStackTrace();
                } catch(SAXNotSupportedException e) {
                        e.printStackTrace();
                }
        }
        /**
        * Translates the document into JSci objects.
        */
        public Object[] translateToJSciObjects() {
                return translateToJSciObjects(getDocument().getDocumentElement());
        }
	public static Object[] translateToJSciObjects(Node root) {
                Translator translator=new JSciObjectTranslator();
                return translator.translate(root);
	}
        /**
        * Translates the document into JSci code.
        */
        public Object[] translateToJSciCode() {
                return translateToJSciCode(getDocument().getDocumentElement());
        }
	public static Object[] translateToJSciCode(Node root) {
                Translator translator=new JSciCodeTranslator();
                return translator.translate(root);
	}
        /**
        * Translator.
        */
        static abstract class Translator extends Object {
                public Translator() {}
                public Object[] translate(Node root) {
                        return parseMATH(root);
                }
                /**
                * Parses the <math> node.
                */
                private Object[] parseMATH(Node n) {
                        int len=0;
                        final NodeList nl=n.getChildNodes();
                        final Object objList[]=new Object[nl.getLength()];
                        Object obj;
                        for(int i=0;i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy