@Override public ASTNodeValue getRateOf(ASTNode nameAST) { return new ASTNodeValue("rateOf(" + nameAST.getName() + ")", this); }
/** * Returns {@code true} if this node or one of its descendants contains some * identifier with the given id. This method can be used to scan a formula * for a specific parameter or species and detect whether this component is * used by this formula. This search is done using a DFS. * * @param id * the id of an SBML element. * @return {@code true} if this node or one of its descendants contains the * given id. */ public boolean refersTo(String id) { if (isString() && (getName() != null) && getName().equals(id)) { return true; } boolean childContains = false; for (ASTNode child : listOfNodes) { childContains |= child.refersTo(id); } return childContains; }
@Override public ASTNodeValue getRateOf(ASTNode nameAST) { StringBuffer value = new StringBuffer(); value.append(mathtt("rateOf")); value.append(brackets(nameAST.getName())); return new ASTNodeValue(value.toString(), this); }
/** * @param astNode */ private void compileCi(ASTNode astNode) { try { writer.writeCharacters(indent); writer.writeStartElement(ASTNode.URI_MATHML_DEFINITION, "ci"); // check if there are any plugins on the ASTNode if (astNode.getExtensionCount() > 0) { writePlugins(astNode); } writer.writeCharacters(" "); writer.writeCharacters(astNode.getName()); writer.writeCharacters(" "); writer.writeEndElement(); writer.writeCharacters("\n"); } catch (XMLStreamException e) { e.printStackTrace(); } }
/** * Returns a set of all the {@link NamedSBase} referenced on this node and * all his descendant. * * Just for testing purposes... * * @return a set of all the {@link NamedSBase} referenced on this node and * all his descendant. */ public Set<SBase> getReferencedNamedSBases() { Set<SBase> l = new HashSet<SBase>(); if (isString()) { if (getVariable() != null) { l.add(getVariable()); } else { logger.warn(MessageFormat.format( resourceBundle.getString("ASTNode.getReferencedNamedSBases"), getName())); } } for (ASTNode child : listOfNodes) { l.addAll(child.getReferencedNamedSBases()); } return l; }
/** * Get the argument named name to this {@link FunctionDefinition}. * * @param name * the exact name (case-sensitive) of the sought-after argument * @return the argument (bound variable) having the given name, or null if * no such argument exists. */ public ASTNode getArgument(String name) { ASTNode arg = null; for (int i = 0; i < getArgumentCount(); i++) { arg = getArgument(i); if (arg.isString() && arg.getName().equals(name)) { return arg; } } return null; }
private boolean checkStoichiometryMath(Model m, SpeciesReference ref, Set<String> definedSpecies) { if (ref.isSetStoichiometryMath() && ref.getStoichiometryMath().isSetMath()) { Queue<ASTNode> queue = new LinkedList<ASTNode>(); queue.offer(ref.getStoichiometryMath().getMath()); while (!queue.isEmpty()) { ASTNode node = queue.poll(); if (node.isName()) { String name = (node.getName() != null) ? node.getName() : ""; if (m.getSpecies(name) != null && !definedSpecies.contains(name)) { return false; } } queue.addAll(node.getListOfNodes()); } } return true; } };
@Override public boolean check(ValidationContext ctx, ASTNode node) { // If it's a name if (node.getType() == Type.NAME) { String id = node.getName(); MathContainer parent = node.getParentSBMLObject(); if (parent == null || parent instanceof FunctionDefinition) { return true; } Model m = parent.getModel(); // We have to go through all the ASTNode defined in the document and find places where // an invalid id is used, then if the id is one of any local parameter, we should fire the constraint. // So we need to test all ASTNode where the parent is NOT a KineticLaw. And make use of the Model find methods. if (m != null && (! (parent instanceof KineticLaw))) { SBase sbase = m.findUniqueSBase(id); // If the id doesn't match anything, it can be a localParameter if (sbase == null && (m.findLocalParameters(id).size() > 0)) { return false; } } } return true; }
/** * @param math * @param bvar * @param value */ private void recursiveReplaceDimensionId(ASTNode math, String bvar, ASTNode value) { for (int i = 0; i < math.getChildCount(); ++i) { if (math.getChild(i).isString() && math.getChild(i).getName().equals(bvar)) { math.replaceChild(i, value); } recursiveReplaceDimensionId(math.getChild(i), bvar, value); } }
/** * Replaces occurrences of a name within this ASTNode with the * name/value/formula represented by the second argument ASTNode, e.g., if * the formula in this ASTNode is x + y; bvar is x and arg is an ASTNode * representing the real value 3 ReplaceArgument substitutes 3 for x within * this ASTNode. * * @param bvar * a string representing the variable name to be substituted * @param arg * an ASTNode representing the name/value/formula to substitute */ public void replaceArgument(String bvar, ASTNode arg) { int n = 0; for (ASTNode child : listOfNodes) { if (child.isString() && child.getName().equals(bvar)) { replaceChild(n, arg.clone()); } else if (child.getChildCount() > 0) { child.replaceArgument(bvar, arg); } n++; } }
/** * Replaces dimension id with the appropriate integer value. * * @param math * @param id * @param index */ private static void recursiveReplaceDimensionId(ASTNode math, String id, int index) { if (math.getChildCount() == 0) { if (math.isString() && math.getName().equals(id)) { math.setValue(index); } return; } for (int i = 0; i < math.getChildCount(); ++i) { recursiveReplaceDimensionId(math.getChild(i), id, index); } }
/** * @param node * @param value */ private void updateASTNodeName(ASTNode node, int value) { if (node.isVector()) { for (int i = 0; i < node.getChildCount(); ++i) { ASTNode child = node.getChild(i); updateASTNodeName(child, value); } } else if (node.isName()) { node.setName("_" + String.valueOf(value) + node.getName()); } else { node.setName("unknown"); } }
@Override public ASTNodeValue selector(List<ASTNode> nodes) throws SBMLException { ASTNode object = nodes.get(0); ASTNode result; if (object.isVector()) { result = object; for (int i = 1; i < nodes.size(); ++i) { int index = (int) nodes.get(i).compile(this).toDouble(); result = result.getChild(index); } return result.compile(this); } else if (object.isVariable()) { compile(object.getVariable()); } else if (object.isString()) { compile(object.getName()); } return unknownValue(); }
@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; }
@Override public boolean check(ValidationContext ctx, ASTNode node) { if (node.getParentSBMLObject() == null) { // something is wrong with the ASTNode return true; } Model m = node.getParentSBMLObject().getModel(); if (m != null && node.isName()) { Compartment c = m.getCompartment(node.getName()); if (c != null && c.getSpatialDimensions() == 0) { return false; } } return true; }
@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 accepts(Object o) { if (o instanceof ASTNode) { ASTNode n = (ASTNode) o; if (n.getType() == ASTNode.Type.NAME) { CallableSBase var = n.getVariable(); if (var != null) { if (var instanceof Reaction) { reactionIdsSet.add(node.getName()); } else { String sid = var.getId(); Model m = var.getModel(); if (m.getAssignmentRuleByVariable(sid) != null) { findReactionLoops(m.getAssignmentRuleByVariable(sid).getMath(), reactionIdsSet, checkedReactionIdsSet); } else if (m.getInitialAssignmentBySymbol(sid) != null) { findReactionLoops(m.getInitialAssignmentBySymbol(sid).getMath(), reactionIdsSet, checkedReactionIdsSet); } } } } } return false; } });
@Override public boolean check(ValidationContext ctx, Reaction r) { Model m = r.getModel(); if (m != null && r.isSetKineticLaw() && r.getKineticLaw().isSetMath()) { Set<String> definedSpecies = ValidationTools.getDefinedSpecies(r); List<ASTNode> names = r.getKineticLaw().getMath().getListOfNodes( ValidationTools.FILTER_IS_NAME); for (ASTNode node : names) { String name = node.getName(); // Is a Species but not in list of defined species? if (m.getSpecies(name) != null && !definedSpecies.contains(name)) { ValidationConstraint.logError(ctx, CORE_21121, r, name, r.getId()); return false; } } } return true; } };
/** * @param node * @param value */ private void updateASTNodeName(ASTNode node, String value) { if (node.isVector()) { for (int i = 0; i < node.getChildCount(); ++i) { ASTNode child = node.getChild(i); updateASTNodeName(child, value); } } else if (node.isName()) { String appendName = node.getName(); while(model.findNamedSBase(value + appendName) != null) { appendName = "_" + appendName; } node.setName(value + appendName); } else { node.setName("unknown"); } }
name = nameAST.getName();