Package org.sbml.jsbml

Examples of org.sbml.jsbml.ASTNode


    defTerm.setResultLevel(0);

    FunctionTerm ft1 = new FunctionTerm();
    ft1.setResultLevel(1);

    ASTNode mathNode = null;
    try {
      mathNode = ASTNode.parseFormula("G0 > 2");
      ft1.setMath(mathNode);
    } catch (ParseException e) {
      e.printStackTrace();
    }

    tr_g1.addFunctionTerm(defTerm);
    tr_g1.addFunctionTerm(ft1);

    Input in4 = new Input("in4", g3, InputTransitionEffect.none);
    Output out2 = new Output("o2", g1, OutputTransitionEffect.assignmentLevel);

    Transition tr2 = qModel.createTransition("tr2", in4, out2);

    FunctionTerm ft2 = new FunctionTerm();

    mathNode = null;
    try {
      mathNode = ASTNode.parseFormula("7");
      ft2.setMath(mathNode);
      mathNode.setUnits("dimensionless");

      System.out.println(mathNode.toMathML());

    } catch (ParseException e) {
      e.printStackTrace();
    }
View Full Code Here


      logger.debug("processAttribute : !!!!!!!!! context is not an ASTNode ( " +
          contextObject.getClass());
      return;
    }
   
    ASTNode astNode = (ASTNode) contextObject;
   
    // System.out.println("MathMLStaxParser : processAttribute called");
    // System.out.println("MathMLStaxParser : processAttribute : element name = " + elementName + ", attribute name = " + attributeName +
    // ", value = " + value + ", prefix = " + prefix + ", " + isLastAttribute + ", " + contextObject);
   
    // Possible value : type, id, style, class, encoding, definitionURL ...
    if (attributeName.equals("type")) {
      astNode.setIsSetNumberType(true);
    }
    if (attributeName.equals("definitionURL")) {
      astNode.setDefinitionURL(value);
    }
   
    if (attributeName.equals("type") || attributeName.equals("definitionURL")) {
      astNode.setType(value);
      // System.out.println("MathMLStaxParser : processAttribute : astNode Type = " + astNode.getType());
    } else if (attributeName.equals("id")) {
      astNode.setId(value);
    } else if (attributeName.equals("style")) {
      astNode.setStyle(value);
    } else if (attributeName.equals("class")) {
      astNode.setClassName(value);
    } else if (attributeName.equals("encoding")) {
      astNode.setEncoding(value);
    }
   
   
  }
View Full Code Here

      logger.debug("processCharactersOf : !!!!!!!!! context is not an ASTNode ( " +
          contextObject.getClass() + " )!!!!!!!!!!");
      return;
    }
   
    ASTNode astNode = (ASTNode) contextObject;
   
    // System.out.println("MathMLStaxParser : processCharactersOf : context type : " + astNode.getType());

    FunctionDefinition functionDef = null;
   
    try {
      functionDef = astNode.getParentSBMLObject().getModel().getFunctionDefinition(characters.trim());
    } catch(NullPointerException e) {
      // TODO : this does not work when we do not set the model object when reading a mathML XML String by it's own.
      // It should not happen in theory but when reading only a mathML block, it is happening and
      // functionDefinition are not properly recognized
      logger.warn("WARNING : cannot recognize properly functionDefinition in mathML block !!!");
    }

    if (functionDef != null) {
      logger.debug("MathMLStaxParser : processCharactersOf : function found !!");
      astNode.setType(Type.FUNCTION);
    }

    if (astNode.isName() || astNode.isFunction()) {
      astNode.setName(characters.trim());
    } else if (astNode.isInteger()) {
      astNode.setValue(StringTools.parseSBMLInt(characters.trim()));
    } else if (astNode.isRational()) {
      if (elementName == null) {
        astNode.setValue(astNode.getNumerator(), StringTools.parseSBMLInt(characters.trim()));
      } else {
        astNode.setValue(StringTools.parseSBMLInt(characters.trim()), (int) 0);
      }
    } else if (astNode.getType().equals(Type.REAL_E)) {
      if (elementName == null) {
        astNode.setValue(astNode.getMantissa(), StringTools.parseSBMLInt(characters.trim()));
      } else {
        astNode.setValue(StringTools.parseSBMLDouble(characters.trim()), (int) 0);
      }
    } else if (astNode.isReal()) {
      astNode.setValue(Double.valueOf(characters.trim()));
    } else if (astNode.getType().equals(Type.FUNCTION_DELAY)) {
      astNode.setName(characters.trim());
    } else {
      logger.warn("processCharactersOf : !!!!!!!!! I don't know what to do with that : " +
          elementName + " !!!!!!!!!!");
    }
  }
View Full Code Here

        System.out.println("MathMLStaxParser : processEndElement : Exception " + e.getLocalizedMessage());       
      }
      return false;
     
    } else if (contextObject instanceof ASTNode) {
      ASTNode astNode = (ASTNode) contextObject;
     
      // add other type of ASTNode in the test ??
      if ((astNode.isFunction() || astNode.isOperator() || astNode.isRelational() ||
          astNode.isLogical()) && !elementName.equals("apply") && !elementName.equals("piecewise"))
      {
        logger.debug("processEndElement : stack stay the same. ASTNode type = " + astNode.getType());
        return false;
       
      }
    }
   
View Full Code Here

      // we do nothing
      return null;
    }
   
    MathContainer mathContainer = null;
    ASTNode parentASTNode = null;
    boolean setMath = false;
   
    if (contextObject instanceof MathContainer) {
      mathContainer = (MathContainer) contextObject;
      if (mathContainer.getMath() == null) {
        setMath = true;
      } else {
        // because normal operator are written <operator/> in mathML and so the parent ASTNode is not any more the contextObject
        parentASTNode = mathContainer.getMath();
        // System.out.println("MathMLStaxParser : processStartElement parent type : " + parentASTNode.getType());
      }
    } else if (contextObject instanceof ASTNode) {
     
      parentASTNode = ((ASTNode) contextObject);
      mathContainer = parentASTNode.getParentSBMLObject();
      // System.out.println("MathMLStaxParser : processStartElement parent type : " + parentASTNode.getType());
    } else {
      // Should never happen
      logger.debug("processStartElement : !!!!!!!!!!! Should not have been here !!!!!!!!!!!");
      logger.debug("processStartElement : contextObject.classname = " + contextObject.getClass().getName());
      return null;
    }
   
    ASTNode astNode = new ASTNode(mathContainer);
    astNode.setType(elementName);
   
    if (setMath) {
      mathContainer.setMath(astNode);
    } else {
      parentASTNode.addChild(astNode);
View Full Code Here

    FormulaParser parser;

    for (int i = 0; i < testCases.length; i++) {
      System.out.printf("%d.\treading:\t%s\n", i, testCases[i]);
      parser = new FormulaParser(new StringReader(testCases[i]));
      ASTNode node;
      try {
        node = parser.parse();
        System.out.printf("%d.\tLaTeX:\t%s\n", i, node.toLaTeX());

        JDialog d = new JDialog();
        d.setTitle("Node output");
        d.setModal(true);
        d.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
View Full Code Here

    int level = 3;
    int version = 1;
    SBMLDocument doc = new SBMLDocument(level, 1);
    Model m = doc.createModel("id");
    FunctionDefinition fd = m.createFunctionDefinition("fd");
    ASTNode math = new ASTNode(Type.LAMBDA, fd);
    math.addChild(new ASTNode("x", fd));
    ASTNode pieces = ASTNode.piecewise(new ASTNode(3, fd), ASTNode.lt("x",
        ASTNode.abs(Double.NEGATIVE_INFINITY, fd)), ASTNode.times(
        new ASTNode(5.3, fd), ASTNode.log(new ASTNode(8, fd))));
    pieces = ASTNode.times(pieces, ASTNode.root(new ASTNode(2, fd),
        new ASTNode(16, fd)));
    math.addChild(pieces);
    fd.setMath(math);
    System.out.println(math.toMathML());
   
    Species species = m.createSpecies("spec");
    Reaction r = m.createReaction("r");
    r.addReactant(new SpeciesReference(species));
    KineticLaw kl = new KineticLaw(level, version);
    math = new ASTNode(fd, kl);
    math.addChild(new ASTNode(species, kl));
    math = ASTNode.times(math, new ASTNode(3.7, 8, kl));
    kl.setMath(math);
    r.setKineticLaw(kl);
   
    System.out.println(math.toMathML());
View Full Code Here

    k2.setConstant(false);
   
    Event event = model.createEvent("test_event");
   
    Trigger trigger = event.createTrigger();
    trigger.setMath(ASTNode.geq(new ASTNode(ASTNode.Type.NAME_TIME),
        new ASTNode(10)));
   
    EventAssignment assignment1 = event.createEventAssignment();
    assignment1.setVariable(k1);
    assignment1.setMath(new ASTNode(34));
   
    EventAssignment assignment2 = event.createEventAssignment();
    assignment2.setVariable(k2);
    assignment2.setMath(new ASTNode(k1));
   
    new SBMLWriter().write(doc, System.out);
  }
View Full Code Here

        // "lambda(2)",
        // "lambda(x, x+2)",
        "1" };

    for (String formula : formulae) {
      ASTNode testNode = ASTNode.parseFormula(formula);

      System.out.println("===================");
      System.out.printf("[IN]:\t%s\n", formula);
      System.out.printf("[OUT]:\t%s\n", testNode.toFormula());
      System.out.printf("[LTX]:\t%s\n", testNode.toLaTeX());

//      AssignmentRule as = new AssignmentRule(2, 4);
      Model m = new Model(2, 4);
      FunctionDefinition fd = new FunctionDefinition("f", 2, 4);
      m.addFunctionDefinition(fd);
View Full Code Here

public class MathMLSpecialTest {

  public static void main(String[] args) {

    ASTNode formula_base = new ASTNode(Double.NaN);

    try {
      System.out.println("Test mathML Special numbers\n");
      System.out.println("Build ASTNode by hand\n");

      System.out.println("\nNaN formula = " + formula_base.toFormula());
      System.out.println("NaN formula = " + formula_base.toMathML());
      System.out.println("NaN formula = " + formula_base.toLaTeX());
      System.out.println("NaN formula = " + formula_base.toString());

      formula_base = new ASTNode(Double.POSITIVE_INFINITY);

      System.out.println("\nInfinity formula = "
          + formula_base.toFormula());
      System.out.println("Infinity formula = " + formula_base.toMathML());
      System.out.println("Infinity formula = " + formula_base.toLaTeX());
      System.out.println("Infinity formula = " + formula_base.toString());

      formula_base = new ASTNode(Double.NEGATIVE_INFINITY);

      System.out.println("\n-Infinity formula = "
          + formula_base.toFormula());
      System.out
          .println("-Infinity formula = " + formula_base.toMathML());
      System.out.println("-Infinity formula = " + formula_base.toLaTeX());
      System.out
          .println("-Infinity formula = " + formula_base.toString());

      System.out.println("\n\nBuild ASTNode by formula\n\n");

      formula_base = ASTNode.parseFormula("NaN");

      System.out.println("\nNaN formula = " + formula_base.toFormula());
      System.out.println("NaN formula = " + formula_base.toMathML());
      System.out.println("NaN formula = " + formula_base.toLaTeX());
      System.out.println("NaN formula = " + formula_base.toString());

      formula_base = ASTNode.parseFormula("Infinity");

      System.out.println("\nInfinity formula = "
          + formula_base.toFormula());
      System.out.println("Infinity formula = " + formula_base.toMathML());
      System.out.println("Infinity formula = " + formula_base.toLaTeX());
      System.out.println("Infinity formula = " + formula_base.toString());

      formula_base = ASTNode.parseFormula("-Infinity");

      System.out.println("\n-Infinity formula = "
          + formula_base.toFormula());
      System.out
          .println("-Infinity formula = " + formula_base.toMathML());
      System.out.println("-Infinity formula = " + formula_base.toLaTeX());
      System.out
          .println("-Infinity formula = " + formula_base.toString());

      System.out.println("\n\nBuild ASTNode by mathML\n\n");

      formula_base = JSBML.readMathMLFromString("<math xmlns=\"http://www.w3.org/1998/Math/MathML\"> \n"
              + "  <notanumber/>\n" + "</math>\n");

      System.out.println("\nNaN formula = " + formula_base.toFormula());
      System.out.println("NaN formula = " + formula_base.toMathML());
      System.out.println("NaN formula = " + formula_base.toLaTeX());
      System.out.println("NaN formula = " + formula_base.toString());

      formula_base = JSBML.readMathMLFromString("<math xmlns=\"http://www.w3.org/1998/Math/MathML\"> \n"
              + "  <infinity/>\n" + "</math>\n");

      System.out.println("\nInfinity formula = "
          + formula_base.toFormula());
      System.out.println("Infinity formula = " + formula_base.toMathML());
      System.out.println("Infinity formula = " + formula_base.toLaTeX());
      System.out.println("Infinity formula = " + formula_base.toString());

      formula_base = JSBML.readMathMLFromString("<math xmlns=\"http://www.w3.org/1998/Math/MathML\"> \n"
              + "  <apply>/n    <minus/>\n    <infinity/>\n  </apply>/n"
              + "</math>\n");

      System.out.println("\n-Infinity formula = "
          + formula_base.toFormula());
      System.out.println("-Infinity formula = " + formula_base.toMathML());
      System.out.println("-Infinity formula = " + formula_base.toLaTeX());
      System.out
          .println("-Infinity formula = " + formula_base.toString());

      // Testing pi
      System.out.println("\n\nBuild ASTNode by hand\n");
      formula_base = new ASTNode(Math.PI);     
     
      System.out.println("\npi formula = " + formula_base.toFormula());
      System.out.println("pi formula = " + formula_base.toMathML());
      System.out.println("pi formula = " + formula_base.toLaTeX());
      System.out.println("pi formula = " + formula_base.toString());

      System.out.println("\n\nBuild ASTNode by formula\n\n");

      formula_base = ASTNode.parseFormula("pi");

      System.out.println("\npi formula = " + formula_base.toFormula());
      System.out.println("pi formula = " + formula_base.toMathML());
      System.out.println("pi formula = " + formula_base.toLaTeX());
      System.out.println("pi formula = " + formula_base.toString());

      System.out.println("\n\nBuild ASTNode by mathML\n\n");

      formula_base = JSBML
          .readMathMLFromString("<math xmlns=\"http://www.w3.org/1998/Math/MathML\"> \n"
              + "  <pi/>\n"
              + "</math>\n");

      System.out.println("\npi formula = " + formula_base.toFormula());
      System.out.println("pi formula = " + formula_base.toMathML());
      System.out.println("pi formula = " + formula_base.toLaTeX());
      System.out.println("pi formula = " + formula_base.toString());

      // Testing exponentiale
      System.out.println("Build ASTNode by hand, number\n");
      formula_base = new ASTNode(Math.E);     
     
      System.out.println("\ne formula = " + formula_base.toFormula());
      System.out.println("e formula = " + formula_base.toMathML());
      System.out.println("e formula = " + formula_base.toLaTeX());
      System.out.println("e formula = " + formula_base.toString());


      System.out.println("\nBuild ASTNode by hand, type CONSTANT_E\n");
     
      formula_base = new ASTNode(ASTNode.Type.CONSTANT_E);     
     
      System.out.println("\ne formula = " + formula_base.toFormula());
      System.out.println("e formula = " + formula_base.toMathML());
      System.out.println("e formula = " + formula_base.toLaTeX());
      System.out.println("e formula = " + formula_base.toString());


      System.out.println("\n\nBuild ASTNode by formula, e\n\n");

      formula_base = ASTNode.parseFormula("e");

      System.out.println("\ne formula = " + formula_base.toFormula());
      System.out.println("e formula = " + formula_base.toMathML());
      System.out.println("e formula = " + formula_base.toLaTeX());
      System.out.println("e formula = " + formula_base.toString());

      System.out.println("\n\nBuild ASTNode by formula, exponentiale\n\n");

      formula_base = ASTNode.parseFormula("exponentiale");

      System.out.println("\ne formula = " + formula_base.toFormula());
      System.out.println("e formula = " + formula_base.toMathML());
      System.out.println("e formula = " + formula_base.toLaTeX());
      System.out.println("e formula = " + formula_base.toString());

      System.out.println("\n\nBuild ASTNode by mathML\n\n");

      formula_base = JSBML
          .readMathMLFromString("<math xmlns=\"http://www.w3.org/1998/Math/MathML\"> \n"
              + "  <exponentiale/>\n"
              + "</math>\n");

      System.out.println("\ne formula = " + formula_base.toFormula());
      System.out.println("e formula = " + formula_base.toMathML());
      System.out.println("e formula = " + formula_base.toLaTeX());
      System.out.println("e formula = " + formula_base.toString());

     
    } catch (SBMLException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
View Full Code Here

TOP

Related Classes of org.sbml.jsbml.ASTNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.