SustainabilityTaxonomy
- class taxonomy4good.sustainabilityTaxonomy.SustainabilityTaxonomy(root=None, version_name='Standard Taxonomy', version_num='0.1.0')[source]
This object is used to create different taxonomies based on required standards. Be it for internal reporting or external, various combinations of sustainability related words can be created by grouping those words under different categories (words), allowing for the creation of multiple reporting items with the needed granularity.
Feel free to play around with the provided Sustainability Lexicon to create your own Taxonomy and make sure you are not missing any word.
- compute_scores(start_root=None, root_score=True)[source]
Compute the weighted scores for the entire taxonomy4good
- Parameters:
root_score (bool) – decide whether to return the score of the root, default is true
start_root (SustainabilityItem) – root of taxonomy4good/substructure for which we want to compute the score (default: root of the entire taxonomy4good)
- Returns:
the weighted value/score of the root node (start_root)
- Return type:
float
- get_all_ids(start_root=None)[source]
Get ids of all the nodes in the current taxonomy4good (grouped by level)
- Parameters:
start_root (SustainabilityItem) – root item of the desired structure or substructure we wish to get ids from (default: root of the entire taxonomy4good)
- Returns:
all the terms of the taxonomy4good
- Return type:
numpy.array (int)
- get_items(start_root=None)[source]
Get all the items of the structure
- Parameters:
start_root (SustainabilityItem) – root item of the desired structure or substructure we wish to get items from (default: root of the entire taxonomy4good)
- Returns:
all the items of the taxonomy4good
- Return type:
numpy.array (SustainabilityItem)
- get_items_each_level(start_root=None)[source]
Get lists of items for each level of the taxonomy4good (grouped by level)
- Parameters:
start_root (SustainabilityItem) – starting node of subtree (default: root of taxonomy4good)
- Returns:
SustainabilityItem list for each level
- Return type:
numpy.array
- get_level_items(level)[source]
Get items of the specified level
- Parameters:
level (int) – desired level of the taxonomy4good we wish to extract items from
- Returns:
list of items in the specified level
- Return type:
numpy.array
- get_level_scores(level)[source]
Compute the weighted values/scores for the specified level
- Parameters:
level (int) – taxonomy4good level
- Returns:
names of level items and their respective weighted values
- Return type:
dict
- get_terms(start_root=None)[source]
Get all terms (names/lexicon) in the taxonomy4good
- Parameters:
start_root (SustainabilityItem) – root item of the desired structure or substructure we wish to get terms from (default: root of the entire taxonomy4good)
- Returns:
all the terms of the taxonomy4good
- Return type:
numpy.array (str)
- insert_items(items)[source]
Insert additional items (terms/lexicons) to this existing taxonomy4good
- Parameters:
items (list of SustainabilityItem) – terms to add in the taxonomy4good with their respective information
- items_to_dict(start_root=None)[source]
Convert the entire taxonomy4good to a dictionary (records) starting from start_root
- Parameters:
start_root (SustainabilityItem) – the root item of the taxonomy4good/substructured of which items are to be converted to dictionary (default: root of the overall taxonomy4good)
- Returns:
list of dictionary converted items (records)
- Return type:
list of dict
- items_to_json(filepath, start_root=None)[source]
Save current taxonomy4good/substructure items to a JSON file (records structure)
- Parameters:
filepath (str) – path where to save the resulting file
start_root (SustainabilityItem) – root item of the structure or substructure to be saved as JSON (default: root of the entire taxonomy4good)
- level(start_item=None)[source]
Compute the maximum depth/level of the taxonomy4good
- Parameters:
start_item (SustainabilityItem) – root item of the desired structure or substructure we wish to compute the depth/level
- Returns:
level of the taxonomy4good
- Return type:
int
- print_hierarchy(start_item=None, current_level=0, islast=False)[source]
Print the current hierarchy of the taxonomy4good with the respective values
- Parameters:
start_item (SustainabilityItem) – starting root of the taxonomy4good/substructure we wish to start from
current_level (int) – indicating the current level that is being printed
islast (bool) – indicating of item is last in the list of children
- remove_by_id(ids)[source]
Remove from the taxonomy4good items corresponding to the supplied ids
- Parameters:
ids (int | list of int) – ids corresponding to the items to be removed from the taxonomy4good
- remove_subtree(items=None)[source]
Remove the passed items along with their children from the taxonomy4good
- Parameters:
items (list of SustainabilityItems) – the items of subtrees/substructures to be removed
- search_by_id(ids)[source]
Search for items by their id
- Parameters:
ids (list int) – list of ids of the nodes to look for
- Returns:
items having the supplied ids
- Return type:
list of SustainabilityItem objects
- search_items_by_name(terms, start_root=None)[source]
Look for similar SustainabilityItems using a string partial match
- Parameters:
terms (list of str) – list of terms/names to search for
start_root (SustainabilityItem) – the root item of the taxonomy4good/substructured to be searched from (default: root of the overall taxonomy4good)
- Returns:
items having the name attributes partially similar to terms
- Return type:
numpy.array of SustainabilityItems
- search_similar_names(terms, start_root=None)[source]
Search for similar names/terms in the taxonomy4good using a string partial match
- Parameters:
terms (list of str) – list of terms/names to search for
start_root (SustainabilityItem) – the root item of the taxonomy4good/substructured to be searched from (default: root of the overall taxonomy4good)
- Returns:
terms partially similar to terms
- Return type:
numpy.array of str
- similar_items(sustainability_items)[source]
Gives the items under the same parent
- Parameters:
sustainability_items (list of SustainabilityItem) – list of items which items under the same parent are returned
- Returns:
list of child items under the parents of the specified items
- Return type:
list of SustainabilityItem lists
- similar_items_byid(ids)[source]
Gives the items under the same parent as items having the specified ids
- Parameters:
ids (list of int) – list of ids which items under the same parent of the items having the specified ids are returned
- Returns:
list of child items under the parents of the specified items
- Return type:
list of SustainabilityItem lists
- taxonomy_to_dict(start_root=None)[source]
Convert the entire taxonomy4good to a dictionary (structural hierarchy) starting from start_root
- Parameters:
start_root (SustainabilityItem) – the root item of the taxonomy4good/substructured to be converted to dictionary (default: root of the overall taxonomy4good)
- Returns:
dictionary version of the taxonomy4good
- Return type:
dict
- taxonomy_to_json(filepath, start_root=None)[source]
Save current taxonomy4good/substructure items to a JSON file (hierarchical structure)
- Parameters:
filepath (str) – path where to save the resulting file
start_root (SustainabilityItem) – root item of the structure or substructure to be saved as JSON (default: root of the entire taxonomy4good)
- to_csv(filepath, start_root=None)[source]
Save current taxonomy4good/substructure to a csv file
- Parameters:
filepath (str) – path where to save the resulting file
start_root (SustainabilityItem) – root item of the structure or substructure to be saved as csv (default: root of the entire taxonomy4good)
- to_dataframe(start_root=None)[source]
Convert the entire taxonomy4good to a DataFrame
- Parameters:
start_root (SustainabilityItem) – the root item of the taxonomy4good/substructure to be converted to a DataFrame (default: root of the overall taxonomy4good)
- Returns:
a dataframe version of the taxonomy4good
- Return type:
pd.DataFrame
- to_excel(filepath, start_root=None)[source]
Save current taxonomy4good/substructure to an Excel file
- Parameters:
filepath (str) – path where to save the resulting file
start_root (SustainabilityItem) – root item of the structure or substructure to be saved as Excel (default: root of the entire taxonomy4good)