Package org.sbml.jsbml

Examples of org.sbml.jsbml.ASTNode


    Model model = doc.createModel("test_model");
    Parameter p = model.createParameter("p1");
    p.setValue(1d);
    Event e = model.createEvent("e1");
    Priority prior = e.createPriority();
    prior.setMath(new ASTNode(1));
    Trigger t = e.createTrigger();
    t.setFormula("time == 1");
    EventAssignment ea = e.createEventAssignment(p, ASTNode
        .parseFormula("3"));
    e.addEventAssignment(ea);
View Full Code Here


    Compartment c = model.createCompartment("compartment");
    model.createSpecies("s1", c);
    model.createSpecies("s2", c);
    Event ev = model.createEvent();
    Trigger trigger = ev.createTrigger(false, true, ASTNode.parseFormula("3 >= 2"));
    trigger.setMath(ASTNode.geq(new ASTNode(ASTNode.Type.NAME_TIME),
        new ASTNode(10)));
    ev.createPriority(ASTNode.parseFormula("25"));
    ev.createDelay(ASTNode.parseFormula("2"));
    ev.createEventAssignment("s1", ASTNode.parseFormula("s2"));
    System.out.println("==================================");
    new SBMLWriter().write(doc, System.out);
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

      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) {
     
      logger.debug("WARNING : cannot recognize properly functionDefinition in mathML block !!!");
    }

    if (isFunctionDefinition)
    {
      logger.debug("MathMLStaxParser : processCharactersOf : function found !!");
     
      logger.debug("Model : " + astNode.getParentSBMLObject().getModel() + ", functionDef = " + functionDef);
     
      if (astNode.getParentSBMLObject().getModel() != null && functionDef == null)
      {
        logger.warn("Cannot recognize functionDefinition with id '" + characters.trim() + "'");
      }
     
      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

      isFunctionDefinition = false;
    }
    lastElementWasApply = false;
   
    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

   * @see org.sbml.jsbml.util.compilers.ASTNodeCompiler#times(java.util.List)
   */
  public ASTNodeValue times(List<ASTNode> nodes) throws SBMLException {
    Object n[] = new ASTNodeValue[nodes.size()];
    for (int i = 0; i < nodes.size(); i++) {
      ASTNode ast = nodes.get(i);
      n[i] = new ASTNodeValue(checkBrackets(ast).toString(), this);
    }
    return new ASTNodeValue(times(n).toString(), this);
  }
View Full Code Here

    }
    return t;
  }

  final public ASTNode parse() throws ParseException {
  ASTNode node = null;
    node = Expression();
    return node;
  }
View Full Code Here

    node = Expression();
    return node;
  }

  final private ASTNode Expression() throws ParseException {
  ASTNode value = null;
    value = TermLvl1();
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case 0:
      jj_consume_token(0);
      break;
View Full Code Here

    }
    return value;
  }

  final private ASTNode TermLvl3() throws ParseException {
  ASTNode rightChild;
  ASTNode leftChild;
  ASTNode node = null;
    leftChild = Primary();
    label_1:
    while (true) {
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case POWER:
      case FACTORIAL:
        ;
        break;
      default:
        jj_la1[2] = jj_gen;
        break label_1;
      }
      switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
      case POWER:
        jj_consume_token(POWER);
        rightChild = Primary();
      node = new ASTNode(Type.POWER);
      node.addChild(leftChild);
      node.addChild(rightChild);
      leftChild = node;
        break;
      case FACTORIAL:
        jj_consume_token(FACTORIAL);
      node = new ASTNode(Type.FUNCTION_FACTORIAL);
      node.addChild(leftChild);
      leftChild = node;
        break;
      default:
        jj_la1[3] = jj_gen;
        jj_consume_token(-1);
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.