af.model.hierarchies package

Submodules

af.model.hierarchies.BaseHierarchy module

class af.model.hierarchies.BaseHierarchy.BaseHierarchy(hierarchy_type='Generalizaton')[source]

Bases: object

Class that used as a model of Hierarchy. A hierarchy can be of a supression or generalization kind. The only difference between both kinds, is that the supression hierarchy transforms every value into the same supression value, and the generalization hierarchy transforms a value into the value that is one level up.

add_node(parent_node, leaf_node)[source]

Add a new node to the current hierarchy

Parameters:
  • parent_node – Node that acts as a parent of the node that is to be added to the hierarchy
  • leaf_node – New node to add
create_html_representation(parent_node=None, level=0, html_string=None)[source]
create_supression_node()[source]

Creates the basic supression node to be used on every hierarchy. A supression node is a GLGNode that has ‘******‘ as a value, and no parent

Return type:Supression Node
find_node(node_value, starting_node=None)[source]

Given a node value, find it’s corresponding Node

Parameters:
  • node_value (string) – Value of the node
  • starting_node – Node (None by default). Used for recursion and knowing where is the finding cursor located
Return type:

Node with the node_value

get_all_nodes_complete_transformation()[source]

For all the leaf nodes, get their complete list of possible dimensions on the GLG Graph

Return type:List of tuples containing all the possible transformations
get_generalization_level_representation(starting_node, generalization_level)[source]

Given a node, transform it to a certain generalization level

Parameters:
  • starting_node – Instance of a Node.
  • generalization_level (int) – Value of the level it is intended for the node to be generalized.
Return type:

The starting node generalization.

get_hierarchy_depth()[source]

Returns the hierarchy depth (Height)

Return type:Hierarchy depth count
get_leaf_node(leaf_node_value)[source]

Given a value that supposedly belongs to a leaf node, find the node and return it.

Parameters:leaf_node_value (string) – Value of the node
Return type:Node containing the leaf_node_value
get_node_depth(node)[source]

Given a node, get its depth; or in other words, how many levels it has upon him (including the root node)

Parameters:node – Node we want to check its depth
Return type:Node depth count
get_representation()[source]

Returns the hierarchy representation with the hierarchy type in the form of a dictionary

Parameters:node – Node (Default None) Used for recursion levels.
Return type:Dictionary representation of the hierarchy with the hierarchy type
hierarchy_representation(node=None)[source]

Returns the hierarchy representation in the form of a dictionary

Parameters:node – Node (Default None) Used for recursion levels.
Return type:Dictionary representation of the hierarchy
is_generalization_hierarchy()[source]
is_suppression_hierarchy()[source]
maintain_leaf_nodes(node, action='add')[source]

Every time we add or remove a leaf node, the leaf node cache list has to be maintained.

Parameters:
  • node – Node we want to add/remove
  • action (string) – Action we want to perform (add, remove)
populate_nodes(parent_node, nodes, attribute_type)[source]

This method is to be used every time a hierarchy is loaded, and the nodes are populated inside of it.

Parameters:
  • parent_node – Node indicating the current parent to which all the nodes are to be put below
  • nodes (dict) – Dictionary containing all the information about the nodes, its values and son nodes.
  • attribute_type – The type of the node value.
print_hierarchy(parent_node=None, level=0)[source]
static supression_node()[source]

Returns a supression node

Return type:Node
transform(data_value, lvl)[source]

Given a certain data value, and a level, look for it the node containing that value, and get the generalization level representation of the lvl

Parameters:
  • data_value (string) – Value of the Node
  • lvl (int) – Level inteded to generalize the node
Return type:

Value of the node that has been transformed to the generalization level.

transform_leaf_nodes(lvl=1)[source]

Transform all leaf nodes to a certain level.

Parameters:lvl (int) – Generalization level to which we want to take all leaf nodes.
Return type:List containing the values of all the transformed leaf nodes.
validate_hierarchy_depth()[source]

After a hierarchy has been populated, and before using it, it must be validated that it has a symmetrical depth

Return type:Boolean indicating if the hierarchy is valid or not.

af.model.hierarchies.Node module

class af.model.hierarchies.Node.Node(value, parent=None, nodes=None)[source]

Bases: object

Class node use in the hierarchies.

add_node(node)[source]

Add a new node as a son

Parameters:node – New node to be added into the nodes son list.
get_leaf_node(value)[source]

Given a value, look for the node associated with it among the leaf nodes.

Parameters:value – value of the node being looked for
Return type:Node with value looked
is_leaf()[source]

Checks if it is a leaf node or not, based on its leaf nodes

Return type:Boolean indicating if it is a leaf node or not.
is_root()[source]

Checks if it is a root node or not, based on its parent

Return type:Boolean indicating if it is a root node or not.
remove_node(node)[source]

Remove a node from the sons list

Parameters:node – Node to be removed

af.model.hierarchies.t_hierarchy module

Module contents