Package schrodinger :: Package application :: Package combiglide :: Package packages :: Module classification_scheme :: Class Scheme
[hide private]
[frames] | no frames]

Class Scheme

Class that stores the structure of the classification scheme.

Instance Methods [hide private]
 
__init__(self, name, node_names_at_levels)
Create the node network.
_Class
getLowestCommonClass(self, items)
Given a collection of items, find the lowest common class in the hierarchy.
 
setClassPopulations(self)
Calculate and store the number of items in each class in the scheme.
list of str
getOrderedNodeNames(self)
Returns: List of node names in order required by registerItem().
_Class
registerItem(self, ordered_class_names, data=None)
Add an item to the classification scheme.
list of _Node
_createOrderedNodesAtLevel(self, ilevel, node_names)
Create nodes at level ilevel and add them to self.ordered_nodes.
 
_createOrderedNodes(self, node_names_at_levels)
Create nodes and self.ordered_nodes list.
 
_addClassRelatives(self, ordered_classes)
Add parents and children to the classes of a newly registered item.
list of list of _Class
_getClassesAtLevels(self, ordered_classes)
Given a flat list of classes, return a list of lists containing the same classes in sub-lists corresponding to the levels of the schme.
Static Methods [hide private]
 
_checkCardinalityOfLevels(node_names_at_levels)
Make sure first and last level have only a single node:
 
_addClassRelativesAtLevel(classes, children, parents)
Add the specified children and parents to the specified classes.
 
_addNodeRelatives(nodes_at_levels)
Add parents and children to all nodes at all levels.
 
_addNodeRelativesAtLevel(node_l, child_l, parent_l)
Add parents and children to all nodes at one level.
Instance Variables [hide private]
str name
Name of this Scheme (set by Scheme.__init__())
int nlevel
Number of levels in this Scheme (set by Scheme.__init__())
Method Details [hide private]

__init__(self, name, node_names_at_levels)
(Constructor)

 

Create the node network. The network is completely defined by the input parameter node_names_at_levels.

Parameters:
  • node_names_at_levels (list of list of str) - node names at all levels. The network that appears in the module docstring would be created by providing the value [ ['0'], ['1a','1b'], ['2'], ['3'] ].

    The indices of the sub-arrays in the top-level array correspond to the levels of the scheme. Thus, in this example, level 0 contains node '0', level 1 contains nodes '1a' and '1b", and so on.

getLowestCommonClass(self, items)

 

Given a collection of items, find the lowest common class in the hierarchy.

Parameters:
  • items (list, tuple or set) - Collection of items (classes at level 0)
Returns: _Class
Lowest common class

setClassPopulations(self)

 

Calculate and store the number of items in each class in the scheme. This should be called by the application after all items have been registered.

getOrderedNodeNames(self)

 
Returns: list of str
List of node names in order required by registerItem().

registerItem(self, ordered_class_names, data=None)

 

Add an item to the classification scheme.

Parameters:
  • ordered_class_names (list of str) - List of item's class names in the canonical node order. This is the order in which the corresponding node names appear in the unrolled node_names_at_levels parameter supplied to the __init__() function. For the scheme shown in the module-level docstring, a value might look like [ 'a', 'b', 'c', 'd', 'e' ], where the entries are the item's class names in nodes 0, 1a, 1b, 2 and 3, respectively.
  • data (anything) - Any data the user wishes to store with the item for later retrieval.
Returns: _Class
level-0 class of the item

_createOrderedNodesAtLevel(self, ilevel, node_names)

 

Create nodes at level ilevel and add them to self.ordered_nodes.

Parameters:
  • ilevel (int) - Level at which these nodes are to be added.
  • node_names (list of str) - Names of nodes to be created
Returns: list of _Node
List of nodes created

_createOrderedNodes(self, node_names_at_levels)

 

Create nodes and self.ordered_nodes list.

Parameters:
  • node_names_at_levels (list of list of str) - node names at all levels. Node names must be unique.

_checkCardinalityOfLevels(node_names_at_levels)
Static Method

 

Make sure first and last level have only a single node:

Parameters:
  • node_names_at_levels (list of list of str) - Node names at each level

_addClassRelatives(self, ordered_classes)

 

Add parents and children to the classes of a newly registered item.

Parameters:
  • ordered_classes (list of _Class) - List of classes for a newly registered item, which must be in 1:1 correspondence with self.ordered_nodes.

_addClassRelativesAtLevel(classes, children, parents)
Static Method

 

Add the specified children and parents to the specified classes.

Parameters:
  • classes (list of _Class) - List of classes whose relatives are to be added
  • children (list of _Class) - List of children of the classes in classes[]
  • parents (list of _Class) - List of parents of the classes in classes[]

_getClassesAtLevels(self, ordered_classes)

 

Given a flat list of classes, return a list of lists containing the same classes in sub-lists corresponding to the levels of the schme.

Parameters:
  • ordered_classes (list of _Class) - List of classes, one for each node in self.ordered_nodes
Returns: list of list of _Class
List of lists; list[i] is a list of classes at level i.

_addNodeRelatives(nodes_at_levels)
Static Method

 

Add parents and children to all nodes at all levels.

Parameters:
  • nodes_at_levels (list of list of _Node) - at each level, a list of Nodes

_addNodeRelativesAtLevel(node_l, child_l, parent_l)
Static Method

 

Add parents and children to all nodes at one level.

Parameters:
  • node_l (list of _Node) - a list of Nodes at the level in question
  • child_l (list of _Node) - a list of children of the Nodes in node_l
  • parent_l (list of _Node) - a list of parents of the Nodes in node_l