@Override public boolean check(ValidationContext ctx, ASTNode node) { // encoding only on some element if (node.isSetEncoding() && !(node.getType() == ASTNode.Type.FUNCTION_DELAY || node.getType() == ASTNode.Type.FUNCTION_RATE_OF || node.getType() == ASTNode.Type.NAME_TIME || node.getType() == ASTNode.Type.NAME_AVOGADRO)) { // TODO - who to recognize annotation and annotation-xml ? return false; } return true; } };
@Override public boolean check(ValidationContext ctx, ASTNode node) { // TODO - check allowed mathML elements if (node.getType().equals(ASTNode.Type.UNKNOWN)) { // TODO - have a proper message with the name of the offending element. return false; } return true; } };
/** * @param astNode */ private void compileFunctionElement(ASTNode astNode) { String functionName = astNode.getType().toString().substring(9).toLowerCase(); compileElement(functionName, astNode); }
/** * @param astNode */ private void compileLogicalOperator(ASTNode astNode) { String functionName = astNode.getType().toString().substring(8).toLowerCase(); compileElement(functionName, astNode); }
/** * @param astNode */ private void compileRelationalOperator(ASTNode astNode) { String functionName = astNode.getType().toString().substring(11).toLowerCase(); compileElement(functionName, astNode); }
@Override public boolean check(ValidationContext ctx, ASTNode node) { if (node.getType() == ASTNode.Type.FUNCTION_RATE_OF) { // check that the child of a rateOf is a ci element. if (node.getChildCount() > 0 && !(node.getChild(0).getType().equals(ASTNode.Type.NAME))) { return false; } } return true; }
@Override public boolean check(ValidationContext ctx, ASTNode node) { // TODO - ci is only allowed since L2V5/L3 // definitionURL only on some elements if (node.isSetDefinitionURL() && !(node.isSemantics() || node.isName() || node.getType() == ASTNode.Type.FUNCTION_DELAY || node.getType() == ASTNode.Type.FUNCTION_RATE_OF)) { return false; } return true; } };
/** * @param astNode */ private void compileConstantElement(ASTNode astNode) { String constantName = astNode.getType().toString().substring(9).toLowerCase(); if (constantName.equals("e")) { constantName = "exponentiale"; } try { writer.writeCharacters(indent); writer.writeEmptyElement(ASTNode.URI_MATHML_DEFINITION, constantName); writer.writeCharacters("\n"); } catch (XMLStreamException e) { e.printStackTrace(); } }
/** * @param astNode */ private void compileElement(ASTNode astNode) { compileElement(astNode.getType().toString().toLowerCase(), astNode); }
@Override public void setMath(ASTNode math) { if (!math.isLambda()) { if (!isReadingInProgress()) { throw new IllegalArgumentException(MessageFormat.format( ILLEGAL_ASTNODE_TYPE_MSG, ASTNode.Type.LAMBDA, math.getType())); } } super.setMath(math); }
@Override public boolean check(ValidationContext ctx, ASTNode node) { // In operators... if (node.isOperator() || set.contains(node.getType())) { // all children must be numbers for (ASTNode n : node.getChildren()) { if (ValidationTools.getDataType(n) != ValidationTools.DT_NUMBER) { return false; } } } return true; }
/** * Recursively checks if a node is of type FUNCTION_SELECTOR. If so, * add to the list of selector nodes. * * @param math * @param listOfNodes */ private void getSelectorNodes(ASTNode math, List<ASTNode> listOfNodes) { if (math.getType() == ASTNode.Type.FUNCTION_SELECTOR) { listOfNodes.add(math); } for (int i = 0; i < math.getChildCount(); ++i) { getSelectorNodes(math.getChild(i), listOfNodes); } }
/** * @param astNode */ private void compileVector(ASTNode astNode) { String functionName = astNode.getType().toString().toLowerCase(); List<ASTNode> args = astNode.getListOfNodes(); try { writer.writeCharacters(indent); writer.writeStartElement(ASTNode.URI_MATHML_DEFINITION, functionName); writer.writeCharacters("\n"); indent += " "; for (ASTNode arg : args) { compile(arg); } writeEndElement(); } catch (XMLStreamException e) { e.printStackTrace(); } }
/** * Creates brackets around the given ASTNode if it is not a simple number or String * or a function (meaning the method {@link ASTNode#isFunction()} returns true). * * @param node the {@link ASTNode} to compile to String * @return a String representing the given ASTNode * @throws SBMLException - if any error occurs while going through the ASTNode */ protected String checkArgumentBrackets(ASTNode node) throws SBMLException { String term = node.compile(this).toString(); if ((node.isNumber() || node.isString() || node.isFunction()) && (! (node.getType() == ASTNode.Type.FUNCTION_POWER || node.getType() == ASTNode.Type.FUNCTION_REM))) { return term; } // for node.isRelational() and node.isLogical(), we want to put brackets return term = brackets(term).toString(); }
/** * Creates brackets if needed. * * @param node * @return * @throws SBMLException */ protected String checkDenominatorBrackets(ASTNode node) throws SBMLException { if ((node.getType() == Type.POWER) && (node.getChildCount() > 1) && node.getRightChild().toString().equals("1")) { return checkDenominatorBrackets(node.getLeftChild()); } String term = node.compile(this).toString(); if (node.isSum() || node.isDifference() || node.isUMinus() || (node.getType() == Type.TIMES) || node.getType() == Type.DIVIDE || node.isRelational() || node.isLogical()) { term = brackets(term).toString(); } return term; }
@Override public boolean check(ValidationContext ctx, ASTNode node) { // do not check inside functionDefinition if (node.getParentSBMLObject() instanceof FunctionDefinition) { return true; } // If is piecewise... if (node.getType() == Type.FUNCTION_PIECEWISE) { // every second node must be a condition and therefore return a // boolean for (int i = 1; i < node.getNumChildren(); i += 2) { ASTNode child = node.getChild(i); if (ValidationTools.getDataType( child) != ValidationTools.DT_BOOLEAN) { // System.out.println("Node " + child.getType() + " was " + // ValidationTools.getDataType(child)); return false; } } } return true; } };
/** * Goes through the formula and identifies all global parameters that are * referenced by this rate equation. * * @return all global parameters that are referenced by this rate equation. */ public List<Parameter> findReferencedGlobalParameters() { ArrayList<Parameter> pList = new ArrayList<Parameter>(); if (getType().equals(ASTNode.Type.NAME) && (getVariable() instanceof Parameter) && (getParentSBMLObject().getModel().getParameter( getVariable().getId()) != null)) { pList.add((Parameter) getVariable()); } for (ASTNode child : getListOfNodes()) { pList.addAll(child.findReferencedGlobalParameters()); } return pList; }
/** * Creates a power {@link ASTNode}. * * @param basis the basis * @param exponent the exponent * @return a power {@link ASTNode}. */ public static ASTNode pow(ASTNode basis, ASTNode exponent) { if (!(exponent.isInteger() && exponent.getInteger() == 1) && !(exponent.getType() == Type.REAL && exponent.getReal() == 1d)) { if ((exponent.isInteger() && exponent.getInteger() == 0) || (exponent.getType() == Type.REAL && exponent.getReal() == 0d)) { basis = new ASTNode(1, basis.getParentSBMLObject()); } else { setParentSBMLObject(exponent, basis.getParentSBMLObject(), 0); basis.raiseByThePowerOf(exponent); } } return basis; }
@Override public boolean check(ValidationContext ctx, ASTNode node) { ASTNode.Type type = node.getType(); if (type == Type.FUNCTION) { // System.out.println("10219 - Found a FUNCTION " + " - " + node.getName()); Model m = node.getParentSBMLObject().getModel(); if (m != null) { FunctionDefinition fd = m.getFunctionDefinition(node.getName()); if (fd != null) { // TODO - for L3V2, we can have no bvar defined !! // System.out.println("10219 - " + node.getNumChildren() + " - " + fd.getArgumentCount()); return node.getNumChildren() == fd.getArgumentCount(); } else { // System.out.println("10219 - fd is null"); } } else { // System.out.println("10219 - Model is null"); } } return true; }
@Override public boolean check(ValidationContext ctx, ASTNode node) { // If is a function if (node.getType() == Type.FUNCTION) { Model m = node.getParentSBMLObject().getModel(); if (m != null) { FunctionDefinition f = m.getFunctionDefinition(node.getName()); if (f == null) { // TODO - for the second parameter, we should print something more complete so that the element could be identified easily ValidationConstraint.logError(ctx, CORE_10214, node.getParentSBMLObject(), ValidationTools.printASTNodeAsFormula(node.getParentSBMLObject().getMath()), node.getParentSBMLObject().getElementName(), node.getName()); return false; } } } return true; }