Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class CatalogueTree:
- def __init__(self):
- self.type = None
- self.child = None
- self.val = None # cateagory
- 10^6
- Product -> [Catagory1, Cator, Catory]
- Traversal
- Rule 1. -> category, subcategory. are ineligible
- Rule 2. ->
- Tree Travel #eligible prodcut
- from collections import defaultdict
- class ProductBuilder:
- def __init__(self):
- self.categoryToProducts = defaultdict(list)
- self.processCatalogue(root: CatalogueTree)
- self.AllProducts = self.categoryToProducts["Catalgoue"]
- # post order
- def processCatalogue(self, root: CatalogueTree):
- if (root.type == "PRODUCT"):
- return root.val
- productResult = []
- for child in root.child:
- temp = self.processCatalogue(child)
- productResult.extend(temp)
- # internal node
- if (root.type != "PRODUCT")
- self.categoryToProducts[root.val] = productResult
- # process the internal node now
- processCatalogue(root)
- class RuleProcessor:
- # Your old code in java has been preserved below.
- # import java.io.*;
- # import java.util.*;
- # import java.text.*;
- # import java.math.*;
- # import java.util.regex.*;
- # public class Solution {
- # static int addNumbers(int a, int b) {
- # return a+b;
- # }
- # public static void main(String args[] ) throws Exception {
- # Scanner in = new Scanner(System.in);
- # int num1, num2, sum;
- # num1 = in.nextInt();
- # num2 = in.nextInt();
- # sum = addNumbers(num1, num2);
- # System.out.println("The sum is " + sum);
- # }
- # }
- # Catalgoue
- # Cat Cat. Cat
- # | |
- # Prod1
- # Rule is for a Entity (product | catalog | category)
- # Customer Contenxt Product and [Rules]. -> list of products
- # Rule
- # Name
- # Entity product | catalog | category
- # Value product name
- # CUstomer Context
- # Billing CIty
- # Billing COuntyr
- # Billing state
- # Product
- # Node. child
- # Case
- # default Product = Sample space of all products
- # 1.) product
- # 2.) Catalgoue - > []
- # 3.) Category ->
- # C1
- # C2 C3
- # P1 p2,p3
- # C2 -> [P1]
- # C3 -> [P2, p3]
- # C1 -> [p1, p2, p3]
- # category1 -> [P1, P2, P3, p4]
- # category2 -> [P1, P2, P3,]
Advertisement
Advertisement