def write_optional_lo_rule(self): number = len(self.opt_child_lo_elem) if number > 1: obj = 'objects' pred = 'these' i = 0 elements = '{}'.format(strFunctions.get_element_name( self.opt_child_lo_elem[i])) for i in range(1, number-1): elements += ', {}'.format(strFunctions.get_element_name( self.opt_child_lo_elem[i])) elements += ' and {}'.format(strFunctions.get_element_name( self.opt_child_lo_elem[i+1])) else: obj = 'object' pred = 'this' elements = '{}'.format(strFunctions.get_element_name( self.opt_child_lo_elem[0])) text = 'The {0} sub{1} on {2} {3} object is optional, but if ' \ 'present, {4} container {1} must not be empty.'\ .format(elements, obj, self.indef, self.formatted_name, pred) ref = '{}, {}.'\ .format(self.pkg_ref, strFunctions.wrap_section(self.name)) sev = 'ERROR' return dict({'number': self.number, 'text': text, 'reference': ref, 'severity': sev})
def write_package_object_rule(self): if len(self.reqd_elem) == 0 and len(self.opt_elem) == 0: return reqd = self.parse_required_elements(self.reqd_elem) opt = self.parse_optional_elements(self.opt_elem) no_other_statement = 'No other elements from the SBML Level 3 {} ' \ 'namespaces are permitted on {} {} object. '\ .format(self.fullname, self.indef, self.formatted_name) if len(opt) == 0 and len(reqd) > 0: text = '{} {} object must contain {}. {}'\ .format(self.indef_u, self.formatted_name, reqd, no_other_statement) elif len(reqd) == 0 and len(opt) > 0: text = '{} {} object may contain {}. {}'\ .format(self.indef_u, self.formatted_name, opt, no_other_statement) else: text = '{} {} object must contain {}, and may contain {}. {}'\ .format(self.indef_u, self.formatted_name, reqd, opt, no_other_statement) ref = '{}, {}.'\ .format(self.pkg_ref, strFunctions.wrap_section(self.name)) sev = 'ERROR' return dict({'number': self.number, 'text': text, 'reference': ref, 'severity': sev})
def write_core_subobject_rule(self, lo_child=None): if lo_child is None: text = '{0} {1} object may have the optional SBML Level~3 ' \ 'Core subobjects for notes and annotations. No other ' \ 'elements from the SBML Level 3 Core namespaces are ' \ 'permitted on {2} {1}.'\ .format(self.indef_u, self.formatted_name, self.indef) ref = 'SBML Level~3 Version~1 Core, Section~3.2.' sev = 'ERROR' else: if 'type' in lo_child: loname = strFunctions.get_element_name(lo_child) element = lo_child['element'] else: # we are in a plugin so have different fields loname = strFunctions.cap_list_of_name(lo_child['name']) element = lo_child['name'] text = 'Apart from the general notes and annotations subobjects ' \ 'permitted on all SBML objects, a {} container object ' \ 'may only contain \{} objects.'\ .format(loname, element) ref = '{}, {}.'\ .format(self.pkg_ref, strFunctions.wrap_section(self.name)) sev = 'ERROR' return dict({'number': self.number, 'text': text, 'reference': ref, 'severity': sev})
def write_core_attribute_rule(self, lo_child=None): if lo_child is None: text = '{0} {1} object may have the optional SBML Level~3 ' \ 'Core attributes {2} and {3}. No other attributes from the ' \ 'SBML Level 3 Core namespaces are permitted on {4} {1}.'\ .format(self.indef_u, self.formatted_name, strFunctions.wrap_token('metaid'), strFunctions.wrap_token('sboTerm'), self.indef) ref = 'SBML Level~3 Version~1 Core, Section~3.2.' sev = 'ERROR' else: text = 'A {0} object may have the optional SBML Level~3 ' \ 'Core attributes {1} and {2}. No other attributes from the ' \ 'SBML Level 3 Core namespaces are permitted on a {0} object.'\ .format(strFunctions.get_element_name(lo_child), strFunctions.wrap_token('metaid'), strFunctions.wrap_token('sboTerm')) ref = '{}, {}.'\ .format(self.pkg_ref, strFunctions.wrap_section(self.name)) sev = 'ERROR' return dict({'number': self.number, 'text': text, 'reference': ref, 'severity': sev})
def write_file(self): BaseFile.BaseFile.write_file(self) self.write_line('\\section{Package syntax and semantics}') self.skip_line() self.write_line('In this section, we define the syntax and ' 'semantics of the {} for ' '\\sbmlthreecore. We expound on the various data ' 'types and constructs defined in this package, ' 'then in {}, we provide complete ' 'examples of using the constructs in example ' 'SBML models.'.format(self.full_pkg_command, strFunctions.wrap_section( 'examples', False))) self.skip_line() self.write_namespace_section() self.write_primitive_data_types() for i in range(0, len(self.plugins)): self.write_body_for_extended_class(self.plugins[i]) for i in range(0, len(self.sbml_classes)): # hack for render if self.sbml_classes[i]['name'] != 'RelAbsVector': self.write_body_for_class(self.sbml_classes[i])
def write_attribute_type_rule(self, attribute): att_type = attribute['type'] name = strFunctions.wrap_token(attribute['texname'], self.package) if att_type == 'SId': return elif att_type == 'SIdRef': ref_name = strFunctions.upper_first(attribute['name']) # hack for render if ref_name == 'StartHead' or ref_name == 'EndHead': ref_name = 'LineEnding' text = 'The value of the attribute {} of {} {} object must be ' \ 'the identifier of an existing \{} object defined in the ' \ 'enclosing \Model object.'\ .format(name, self.indef, self.formatted_name, ref_name) elif att_type == 'string': text = 'The attribute {} on {} {} must have a value of data ' \ 'type {}.'\ .format(name, self.indef, self.formatted_name, strFunctions.wrap_token('string')) elif att_type == 'int' or att_type == 'uint': text = 'The attribute {} on {} {} must have a value of data ' \ 'type {}.'\ .format(name, self.indef, self.formatted_name, strFunctions.wrap_token('integer')) elif att_type == 'double': text = 'The attribute {} on {} {} must have a value of data ' \ 'type {}.'\ .format(name, self.indef, self.formatted_name, strFunctions.wrap_token('double')) elif att_type == 'boolean' or att_type == 'bool': text = 'The attribute {} on {} {} must have a value of data ' \ 'type {}.'\ .format(name, self.indef, self.formatted_name, strFunctions.wrap_token('boolean')) elif att_type == 'enum': enum_name = strFunctions.texify(attribute['element']) enums = attribute['parent']['root']['enums'] enum_values = self.parse_enum_values(attribute['element'], enums) text = 'The value of the attribute {0} of {1} {2} object must ' \ 'conform to the syntax of SBML data type {3} and ' \ 'may only take on the allowed values of {3} defined ' \ 'in SBML; that is the value must be one of the ' \ 'following {4}.'.format(name, self.indef, self.formatted_name, strFunctions.wrap_enum(enum_name), enum_values) elif att_type == 'array': text = 'The value of the attribute {} of {} {} object must ' \ 'be an array of values of type {}.'\ .format(name, self.indef, self.formatted_name, strFunctions.wrap_token(attribute['element'])) elif att_type == 'element' and attribute['element'] == 'RelAbsVector': text = 'The value of the attribute {0} of {1} {2} object must ' \ 'conform to the syntax of SBML data type \\RelAbsVector ' \ 'i.e. a string encoding optionally an absolute number ' \ 'followed by an optional relative number followed ' \ 'by a \\% sign. Adding spaces between the ' \ 'coordinates is encouraged, but not required.'\ .format(name, self.indef, self.formatted_name) else: text = 'FIX ME: Encountered an unknown attribute type {} in ' \ 'ValidationRulesForClass:write_attribute_type_rule'\ .format(att_type) ref = '{}, {}.'\ .format(self.pkg_ref, strFunctions.wrap_section(self.name)) sev = 'ERROR' return dict({'number': self.number, 'text': text, 'reference': ref, 'severity': sev})