UnitDefinition assignmentDerivedUnit = ValidationTools.getDerivedUnitDefinition(ctx, assignment); UnitDefinition varDerivedUnit = ValidationTools.getDerivedUnitDefinition(ctx, var); varDerivedUnit = varDerivedUnit.clone().convertToSIUnits(); boolean equivalent = areEquivalent(assignmentDerivedUnit, varDerivedUnit);
@Override public boolean check(ValidationContext ctx, SBase sb) { if (sb.isSetId()) { return SyntaxChecker.isValidId(sb.getId(), ctx.getLevel(), ctx.getVersion()); } // checking in the invalid user object String invalidId = ValidationTools.checkInvalidAttribute(ctx, (AbstractTreeNode) sb, "id"); if (invalidId != null) { return false; } if (ctx.getLevel() == 1) { invalidId = ValidationTools.checkInvalidAttribute(ctx, (AbstractTreeNode) sb, "name"); if (invalidId != null) { return false; } } return true; } };
@Override public boolean check(ValidationContext ctx, AssignmentRule ar) { return ValidationTools.containsMathOnlyPredefinedFunctions( ar.getMath()); } };
@Override public boolean check(ValidationContext ctx, MathContainer mc) { if (mc.isSetMath()) { // ASTNode must return a number if (mc instanceof KineticLaw || mc instanceof StoichiometryMath || mc instanceof SimpleSpeciesReference || mc instanceof InitialAssignment || mc instanceof Delay || mc instanceof EventAssignment || mc instanceof Rule) { return ValidationTools.getDataType(mc.getMath()) == ValidationTools.DT_NUMBER; } } return true; } };
UnitDefinition extendUnits = ValidationTools.getDerivedExtendUnitDefinition(m); UnitDefinition speciesUnits = s != null ? ValidationTools.getDerivedSubstanceUnitDefinition(s) : null;
@Override public boolean check(ValidationContext ctx, Reaction r) { Model m = r.getModel(); if (m != null) { Set<String> definedSpecies = ValidationTools.getDefinedSpecies(r); if (r.isSetListOfProducts()) { for (SpeciesReference ref : r.getListOfProducts()) { if (!checkStoichiometryMath(m, ref, definedSpecies)) { return false; } } } if (r.isSetListOfReactants()) { for (SpeciesReference ref : r.getListOfReactants()) { if (!checkStoichiometryMath(m, ref, definedSpecies)) { return false; } } } } return true; }
@Override public boolean check(ValidationContext ctx, ASTNode node) { // Only allowed on numbers if (node.isSetUnits()) { return node.isNumber(); } if (node.isSetUserObjects() && node.getUserObject(JSBML.UNKNOWN_XML) != null) { String invalidUnits = ValidationTools.checkUnknowndAttribute(ctx, node, "units"); if (invalidUnits != null) { return false; } } if (node.getParentSBMLObject() != null && node.getParentSBMLObject().getUserObject(JSBML.UNKNOWN_XML) != null) { // System.out.println(node.getParentSBMLObject().getUserObject(JSBML.UNKNOWN_XML)); // TODO - put this test on the MathContainer only to avoid getting it several times String invalidUnits = ValidationTools.checkUnknowndAttribute(ctx, (AbstractTreeNode) node.getParentSBMLObject(), "units"); if (invalidUnits != null) { return false; } } return true; } };
boolean isUnitsValid = ValidationTools.checkUnit(ctx, m, m.getSubstanceUnits()); boolean isUnitsValid = ValidationTools.checkUnit(ctx, m, m.getVolumeUnits()); boolean isUnitsValid = ValidationTools.checkUnit(ctx, m, m.getAreaUnits()); boolean isUnitsValid = ValidationTools.checkUnit(ctx, m, m.getLengthUnits()); boolean isUnitsValid = ValidationTools.checkUnit(ctx, m, m.getTimeUnits()); boolean isUnitsValid = ValidationTools.checkUnit(ctx, m, m.getExtentUnits());
String invalidUnits = ValidationTools.checkUnknownUnitSyntax(ctx, m, TreeNodeChangeEvent.substanceUnits); String invalidUnits = ValidationTools.checkUnknownUnitSyntax(ctx, m, TreeNodeChangeEvent.volumeUnits); String invalidUnits = ValidationTools.checkUnknownUnitSyntax(ctx, m, TreeNodeChangeEvent.areaUnits); String invalidUnits = ValidationTools.checkUnknownUnitSyntax(ctx, m, TreeNodeChangeEvent.lengthUnits); String invalidUnits = ValidationTools.checkUnknownUnitSyntax(ctx, m, TreeNodeChangeEvent.timeUnits); String invalidUnits = ValidationTools.checkUnknownUnitSyntax(ctx, m, TreeNodeChangeEvent.extentUnits);
@Override public boolean check(ValidationContext ctx, Trigger t) { if (t.isSetMath()) { boolean isValid = ValidationTools.getDataType(t.getMath()) == ValidationTools.DT_BOOLEAN; // in SBML L3V2, number as equivalent to boolean if (!isValid && ctx.getLevelAndVersion().compareTo(3, 2) >= 0) { isValid = ValidationTools.getDataType(t.getMath()) == ValidationTools.DT_NUMBER; } return isValid; } return true; } };
@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; } };
UnitDefinition klDerivedUnit = ValidationTools.getDerivedUnitDefinition(ctx, kl).clone().convertToSIUnits(); expectedUnit.convertToSIUnits(); return areEquivalent(klDerivedUnit, expectedUnit);
@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; }
@Override public boolean check(ValidationContext ctx, UnitDefinition ud) { if (!ud.isSetId()) { // checking in the invalid user object String invalidId = ValidationTools.checkInvalidAttribute(ctx, ud, "id"); if (invalidId != null && SyntaxChecker.isValidId(invalidId, ctx.getLevel(), ctx.getVersion())) { // If the id has a valid syntax, then it is a duplicated id. // TODO - create a nice error message return false; } if (ctx.getLevel() == 1) { invalidId = ValidationTools.checkInvalidAttribute(ctx, ud, "name"); if (invalidId != null && SyntaxChecker.isValidId(invalidId, ctx.getLevel(), ctx.getVersion())) { return false; } } } return true; } };
@Override public boolean check(ValidationContext ctx, KineticLaw kl) { return ValidationTools.containsMathOnlyPredefinedFunctions(kl.getMath()); } };
@Override public boolean check(ValidationContext ctx, ASTNode node) { // In comparator... if (node.isRelational() && node.getChildCount() > 0) { byte dt = ValidationTools.getDataType(node.getChild(0)); // all children must have same Type for (int i = 1; i < node.getNumChildren(); i++) { if (dt != ValidationTools.getDataType(node.getChild(i))) { return false; } } } return true; } };
@Override public boolean check(ValidationContext ctx, SBase sb) { if (sb instanceof UniqueSId && sb.getPackageName().equals("core")) { // TODO - Each package will have a different error number if (!sb.isSetId()) { // checking in the invalid user object String invalidId = ValidationTools.checkInvalidAttribute(ctx, (AbstractTreeNode) sb, "id"); if (invalidId != null && SyntaxChecker.isValidId(invalidId, ctx.getLevel(), ctx.getVersion())) { // If the id has a valid syntax, then it is a duplicated id. // TODO - create a nice error message return false; } if (ctx.getLevel() == 1) { invalidId = ValidationTools.checkInvalidAttribute(ctx, (AbstractTreeNode) sb, "name"); if (invalidId != null && SyntaxChecker.isValidId(invalidId, ctx.getLevel(), ctx.getVersion())) { return false; } } } } return true; } };
@Override public boolean check(ValidationContext ctx, ASTNode node) { // If is piecewise... if (node.isPiecewise() && node.getNumChildren() > 0) { byte dt = ValidationTools.getDataType(node.getLeftChild()); if (dt == ValidationTools.DT_STRING) { return false; } // all children must have same Type for (int i = 0; i < node.getNumChildren(); i += 2) { if (dt != ValidationTools.getDataType(node.getChild(i))) { return false; } } } return true; } };
@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; } };
byte dt = getDataType(node.getChild(0)); if (getDataType(node.getChild(i)) != dt) { return DT_UNKNOWN; return ValidationTools.getDataType(fd.getBody());