gamingflexer commited on
Commit
8583535
·
1 Parent(s): 59e430b

Add utils.py file with category-related functions

Browse files
Files changed (1) hide show
  1. src/utils.py +27 -0
src/utils.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+
3
+ with open('Category-tree.json') as f:
4
+ cat_data = json.load(f)
5
+
6
+ candidate_labels = ['BEVERAGES', 'SNACKS & BRANDED FOODS', 'NOT FOUND', 'EGGS, MEAT & FISH',
7
+ 'FOODGRAINS, OIL & MASALA', 'PERSONAL CARE', 'CLEANING & HOUSEHOLD',
8
+ 'FRUITS & VEGETABLES', 'BAKERY, CAKES & DAIRY', 'MAKEUP', 'BABY CARE',
9
+ 'PET FOOD & ACCESSORIES', 'NON FMCG', 'TOBACCO', 'WELLNESS', 'ALCOHOLIC BEVERAGES']
10
+
11
+ def get_childs(parent):
12
+ catagories = []
13
+ for category in cat_data:
14
+ if category['name'] == parent:
15
+ for child in category['children']:
16
+ catagories.append(child['name'])
17
+ return catagories
18
+
19
+ def get_inner_child(to_find_parent,to_find_child):
20
+ catagories = []
21
+ for parent in cat_data:
22
+ if parent['name'] == to_find_parent:
23
+ for child in parent['children']:
24
+ if child['name'] == to_find_child:
25
+ for inner_child in child['children']:
26
+ catagories.append(inner_child['name'])
27
+ return catagories