dynetmlparsingutilities

dynetmlparsingutils.check_contained_types(iterable, iterable_name, allowable_types)[source]

Helper function for validating that an iterable object only contains allowed types.

Parameters:
  • iterable (tuple|list) – the tuple or list to be evaluated
  • iterable_name (str|unicode) – the name of the iterable
  • allowable_types – the types the iterable can be.
dynetmlparsingutils.check_key(var, var_name, used_map, map_name, check_if_in_map=True)[source]

Helper function for checking if a key is in a map

Parameters:
  • var – the variable which needs to be checked
  • var_name (str|unicode) – the name of the variable
  • used_map – the map
  • map_name (str|unicode) – the name of the map
  • check_if_in_map (bool) – if True, verify that var is in map. If False, check if var is not in map
dynetmlparsingutils.check_type(var, var_name, allowable_types)[source]

Helper function for checking a variable’s type

Parameters:
  • var – the variable which needs its type checked
  • var_name (str|unicode) – the name of the variable
  • allowable_types – a type or tuple of types that var can be
dynetmlparsingutils.format_prop(prop_str, prop_type='')[source]

A method for converting properties to appropriate formats. Currently just covers dates (bools handled elsewhere)

Parameters:
  • prop_str (str|unicode) – a property to be converted
  • prop_type (str|unicode) – str or unicode specifying the type of property
Returns:

a property value that has been converted to the appropriate type.

Return type:

bool|float|datetime|str|unicode

dynetmlparsingutils.get_nodeclass_dict(nodes_tag, prop_inclusion_test=None, nodeclass_inclusion_test=None)[source]
Parameters:
  • nodes_tag (lxml._Element) – An lxml._Element extracted from the <nodes> tag in a DynetML file
  • prop_inclusion_test (lambda) – Test for whether a node property should be included
  • nodeclass_inclusion_test (lambda) – Test for whether a nodeclass should be included
Returns:

A dictionary defining a nodeclass

Return type:

Collections.defaultdict(dict)

dynetmlparsingutils.get_nodeset_tuple(nodeclass_tag, property_inclusion_test=None)[source]
Parameters:
  • nodeclass_tag – An lxml._Element extracted from the <nodeclass> tag in a DyNetML file
  • property_inclusion_test (lambda) – Test for whether a node property should be included
Returns:

dict, Collections.defaultdict(node_tuple)

dynetmlparsingutils.get_properties_tag(properties_dict)[source]

Reads in a dictionary of properties and converts it to a properties tag

Parameters:properties_dict – a dictionary of properties
Returns:A <properties> tag
Return type:lxml._Element
dynetmlparsingutils.get_property_identities_dict(property_identities_tag, inclusion_test=None)[source]

Reads in a propertyIdentities tag and converts it to a dictionary of property identities

Parameters:
  • property_identities_tag (lxml._Element) – a tag containing propertyIdentities, or None
  • inclusion_test (lambda) – a test for whether or not to include a particular property. Defaults to including all.
Returns:

A dictionary of property identities, or an empty dictionary

Return type:

dict

dynetmlparsingutils.get_property_identities_tag(property_identities_dict)[source]

Reads a dictionary of Property Identities and converts it to a propertyIdentities tag

Parameters:property_identities_dict (dict) – a dictionary containing propertyIndentity values
Returns:a propertyIdentities tag
Return type:lxml._Element
dynetmlparsingutils.node_tree()[source]
Returns:The default dict that define
Return type:defaultdict(nodeclass_dict)
dynetmlparsingutils.node_tuple()[source]
Returns:The tuple that defines a node
Return type:tuple_(dict, dict)
dynetmlparsingutils.nodeclass_dict()[source]
Returns:The defaultdict that defines a nodeclass
Return type:defaultdict(nodeset_tuple)
dynetmlparsingutils.nodeset_tuple()[source]
Returns:The tuple that defines a nodeset
Return type:tuple_(dict, defaultdict(node_tuple))
dynetmlparsingutils.unformat_prop(prop)[source]

A method for un-formatting properties back to strings. Currently covers dates and bools.

Parameters:prop – a property storied in a properties dictionary, of unknown type.
Returns:the property value transformed to a string containing equivalent dynetml contents
Return type:unicode or str
dynetmlparsingutils.validate_and_get_inclusion_test(include_tuple, ignore_tuple)[source]

A method for validating variables and then returning an inclusion test

Parameters:
  • include_tuple (tuple) – A two element tuple, the first element is a list of strings, the second is the list’s name
  • ignore_tuple (tuple) – A two element tuple, the first element is a list of strings, the second is the list’s name
Returns:

a test for whether or not an item should be included

Return type:

lambda

Previous topic

MetaNetworkIGraph