Advertisement
nirajs

service now

Feb 15th, 2024
12
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1.  
  2.  
  3.  
  4. class CatalogueTree:
  5. def __init__(self):
  6. self.type = None
  7. self.child = None
  8. self.val = None # cateagory
  9.  
  10. 10^6
  11. Product -> [Catagory1, Cator, Catory]
  12.  
  13.  
  14. Traversal
  15.  
  16. Rule 1. -> category, subcategory. are ineligible
  17. Rule 2. ->
  18.  
  19.  
  20. Tree Travel #eligible prodcut
  21.  
  22.  
  23. from collections import defaultdict
  24.  
  25. class ProductBuilder:
  26.  
  27. def __init__(self):
  28. self.categoryToProducts = defaultdict(list)
  29. self.processCatalogue(root: CatalogueTree)
  30. self.AllProducts = self.categoryToProducts["Catalgoue"]
  31.  
  32.  
  33. # post order
  34. def processCatalogue(self, root: CatalogueTree):
  35.  
  36. if (root.type == "PRODUCT"):
  37. return root.val
  38.  
  39. productResult = []
  40. for child in root.child:
  41. temp = self.processCatalogue(child)
  42. productResult.extend(temp)
  43.  
  44. # internal node
  45. if (root.type != "PRODUCT")
  46. self.categoryToProducts[root.val] = productResult
  47.  
  48. # process the internal node now
  49. processCatalogue(root)
  50.  
  51.  
  52.  
  53. class RuleProcessor:
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65. # Your old code in java has been preserved below.
  66. # import java.io.*;
  67. # import java.util.*;
  68. # import java.text.*;
  69. # import java.math.*;
  70. # import java.util.regex.*;
  71.  
  72. # public class Solution {
  73.  
  74. # static int addNumbers(int a, int b) {
  75. # return a+b;
  76. # }
  77.  
  78. # public static void main(String args[] ) throws Exception {
  79. # Scanner in = new Scanner(System.in);
  80. # int num1, num2, sum;
  81. # num1 = in.nextInt();
  82. # num2 = in.nextInt();
  83.  
  84. # sum = addNumbers(num1, num2);
  85. # System.out.println("The sum is " + sum);
  86. # }
  87. # }
  88.  
  89.  
  90. # Catalgoue
  91. # Cat Cat. Cat
  92. # | |
  93. # Prod1
  94.  
  95.  
  96. # Rule is for a Entity (product | catalog | category)
  97.  
  98. # Customer Contenxt Product and [Rules]. -> list of products
  99.  
  100.  
  101.  
  102. # Rule
  103. # Name
  104. # Entity product | catalog | category
  105. # Value product name
  106.  
  107. # CUstomer Context
  108. # Billing CIty
  109. # Billing COuntyr
  110. # Billing state
  111. # Product
  112. # Node. child
  113.  
  114.  
  115.  
  116. # Case
  117.  
  118. # default Product = Sample space of all products
  119. # 1.) product
  120.  
  121. # 2.) Catalgoue - > []
  122.  
  123. # 3.) Category ->
  124.  
  125.  
  126.  
  127.  
  128. # C1
  129. # C2 C3
  130. # P1 p2,p3
  131.  
  132. # C2 -> [P1]
  133. # C3 -> [P2, p3]
  134. # C1 -> [p1, p2, p3]
  135.  
  136.  
  137.  
  138. # category1 -> [P1, P2, P3, p4]
  139. # category2 -> [P1, P2, P3,]
  140.  
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement