Package org.sbml.jsbml

Examples of org.sbml.jsbml.ASTNode


  @SuppressWarnings("deprecation")
  @Test
public void test_ASTNode_replaceChild()
  {
    ASTNode node = new  ASTNode();
    ASTNode c1 = new  ASTNode(Type.NAME);
    ASTNode c2 = new  ASTNode(Type.NAME);
    ASTNode c3 = new  ASTNode(Type.NAME);
    ASTNode newc = new  ASTNode(Type.NAME);

    node.setType(ASTNode.Type.LOGICAL_AND);
    c1.setName( "a");
    c2.setName( "b");
    c3.setName( "c");
    node.addChild(c1);
    node.addChild(c2);
    node.addChild(c3);
    assertTrue( node.getNumChildren() == 3 );
    assertTrue(JSBML.formulaToString(node).equals( "a and b and c"));
    newc.setName( "d");
    node.replaceChild(0,newc);
    assertTrue( node.getNumChildren() == 3 );
    assertTrue(JSBML.formulaToString(node).equals( "d and b and c"));

    try {
View Full Code Here


  }

  @Test
  public void test_ASTNode_setCharacter()
  {
    ASTNode node = new  ASTNode(Type.NAME);
    node.setName( "foo");
    assertTrue( node.getType() == ASTNode.Type.NAME );
    // assertTrue( node.getCharacter() == '\0' );
    assertTrue(node.getName().equals( "foo"));
    // assertTrue( node.getInteger() == 0 );
    // assertTrue( node.getReal() == 0 );
    // assertTrue( node.getExponent() == 0 );
    // assertTrue( node.getDenominator() == 1 );
   
    node.setCharacter( '+');
    assertTrue( node.getType() == ASTNode.Type.PLUS );
    assertTrue( node.getCharacter() ==  '+'       );
    // assertTrue( node.getName() == null );
    // assertTrue( node.getInteger() == 0 );
    // assertTrue( node.getReal() == 0 );
    // assertTrue( node.getExponent() == 0 );
    // assertTrue( node.getDenominator() == 1 );

    node.setCharacter( '-');
    assertTrue( node.getType() == ASTNode.Type.MINUS );
    assertTrue( node.getCharacter() ==  '-'        );

    node.setCharacter( '*');
    assertTrue( node.getType() == ASTNode.Type.TIMES );
    assertTrue( node.getCharacter() ==  '*'        );

    node.setCharacter( '/');
    assertTrue( node.getType() == ASTNode.Type.DIVIDE );
    assertTrue( node.getCharacter() ==  '/'         );

    node.setCharacter( '^');
    assertTrue( node.getType() == ASTNode.Type.POWER );
    assertTrue( node.getCharacter() ==  '^'        );

    node.setCharacter( '$');
    assertTrue( node.getType() == ASTNode.Type.UNKNOWN );
    // assertTrue( node.getCharacter() ==  '$'          );  // Exception thrown

    node = null;
  }
View Full Code Here

  }

  @Test
  public void test_ASTNode_setInteger()
  {
    ASTNode node = new  ASTNode(Type.NAME);
    node.setName( "foo");
    assertTrue( node.getType() == ASTNode.Type.NAME );
    assertTrue(node.getName().equals( "foo"));
    // assertTrue( node.getCharacter() == '\0' );
    // assertTrue( node.getInteger() == 0 );
    // assertTrue( node.getReal() == 0 );
    // assertTrue( node.getExponent() == 0 );
    // assertTrue( node.getDenominator() == 1 );
   
    node.setValue(3.2);
   
    assertTrue( node.getType() == ASTNode.Type.REAL );
    // assertTrue( node.getInteger() == 0 );
    // assertTrue( node.getName() == null );
    // assertTrue( node.getCharacter() == '\0' );
    assertTrue( node.getReal() == 3.2 );
    assertTrue( node.getExponent() == 0 );
    // assertTrue( node.getDenominator() == 1 );
   
    node.setValue(321);
   
    assertTrue( node.getType() == ASTNode.Type.INTEGER );
    assertTrue( node.getInteger() == 321 );
    // assertTrue( node.getName() == null );
    // assertTrue( node.getCharacter() == '\0' );
    assertTrue( node.getReal() == 321 );
    // assertTrue( node.getExponent() == 0 );
    // assertTrue( node.getDenominator() == 1 );
    node = null;
  }
View Full Code Here

  @Test
  public void test_ASTNode_setName()
  {
    String name =  "foo";;
    ASTNode node = new  ASTNode();
    assertTrue( node.getType() == ASTNode.Type.UNKNOWN );
    node.setName(name);
    assertTrue( node.getType() == ASTNode.Type.NAME );
    assertTrue( node.getName().equals(name));
    // assertTrue( node.getCharacter() == '\0' );
    // assertTrue( node.getInteger() == 0 );
    // assertTrue( node.getReal() == 0 );
    // assertTrue( node.getExponent() == 0 );
    // assertTrue( node.getDenominator() == 1 );

    node.setName(null);
    assertTrue( node.getType() == ASTNode.Type.NAME );

    assertTrue(node.getName() == null);
   
    node.setType(ASTNode.Type.FUNCTION_COS);
    assertTrue( node.getType() == ASTNode.Type.FUNCTION_COS );
    assertTrue(node.getName().equals( "cos"));
    assertTrue( node.getCharacter() == '\0' );
    assertTrue( node.getInteger() == 0 );
    assertTrue( node.getReal() == 0 );
    assertTrue( node.getExponent() == 0 );
    assertTrue( node.getDenominator() == 1 );
    node.setType(ASTNode.Type.PLUS);
    node.setName(name);
    assertTrue( node.getType() == ASTNode.Type.NAME );
    assertTrue(node.getName().equals(name));
    assertTrue( node.getCharacter() ==  '+'         );
    assertTrue( node.getInteger() == 0 );
    assertTrue( node.getReal() == 0 );
    assertTrue( node.getExponent() == 0 );
    assertTrue( node.getDenominator() == 1 );
    node = null;
  }
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

    else if (contextObject instanceof Annotation) {
      Annotation annotation = (Annotation) contextObject;
      isAttributeRead = annotation.readAttribute(attributeName, prefix,
          value);
    } else if (contextObject instanceof ASTNode) {
      ASTNode astNode = (ASTNode) contextObject;
     
      try {
        astNode.setUnits(value);
        isAttributeRead = true;
      } catch (IllegalArgumentException e) {
        // TODO: Write from which element the error is coming from: astNode.getParentSBMLObject();
        log4jLogger.info(e.getMessage());
        // Log the error to the ErrorLog object ??
View Full Code Here

//        new ASTNode(10)));
    trigger.setMath(ASTNode.parseFormula("time >= 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

   * org.sbml.jsbml.ASTNodeCompiler#function(org.sbml.jsbml.FunctionDefinition
   * , org.sbml.jsbml.ASTNodeValue[])
   */
  public ASTNodeValue function(FunctionDefinition function, List<ASTNode> args)
      throws SBMLException {
    ASTNode lambda = function.getMath();
    HashMap<String, ASTNodeValue> argValues = new HashMap<String, ASTNodeValue>();
    for (int i = 0; i < args.size(); i++) {
      argValues.put(lambda.getChild(i).compile(this).toString(), args
          .get(i).compile(this));

    }
    try {
      this.namesToUnits = argValues;
      ASTNodeValue value = lambda.getRightChild().compile(this);
      this.namesToUnits.clear();
      return value;
    } catch (SBMLException e) {
      return new ASTNodeValue(this);
    }
View Full Code Here

     
      int nbChildren = astNode.getChildCount();
     
      if (nbChildren > 1) {       
        for (int i = 0; i < nbChildren - 1; i++ ) {
          ASTNode arg = astNode.getChild(i);
          compileBvar(arg);
        }
      }

      compile(astNode.getRightChild());
View Full Code Here

    }
  }

  public static void main(String[] args) {
   
    ASTNode formula_base = new ASTNode(Double.NaN);
   
    System.out.println(formula_base.toMathML());
    try {
      System.out.println(formula_base.toFormula());
    } catch (SBMLException e) {
      e.printStackTrace();
    }
   
    double x = 0.0050;
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.