| 106 | return int(self.brand_dict.get(x, -1)) |
| 107 | |
| 108 | def gen_neg_hist(self, length): |
| 109 | if len(self.neg_hist_catch.get(length, [1])) == self.max_catch_num: |
| 110 | index = int(random.random()*self.max_catch_num) |
| 111 | return self.neg_hist_catch[length][index] |
| 112 | else: |
| 113 | #generate a new neg hist |
| 114 | neg_item_hist = [] |
| 115 | neg_cate_hist = [] |
| 116 | neg_shop_hist = [] |
| 117 | neg_node_hist = [] |
| 118 | neg_product_hist = [] |
| 119 | neg_brand_hist = [] |
| 120 | for i in range(length): |
| 121 | item_idx = int(random.random()*self.num_items) |
| 122 | neg_item = self.all_items[item_idx] |
| 123 | neg_cate = self.map_cate(self.item_info[neg_item][0]) |
| 124 | neg_cate_hist.append(neg_cate) |
| 125 | neg_shop = self.map_shop(self.item_info[neg_item][1]) |
| 126 | neg_shop_hist.append(neg_shop) |
| 127 | neg_node = self.map_node(self.item_info[neg_item][2]) |
| 128 | neg_node_hist.append(neg_node) |
| 129 | neg_product = self.map_product(self.item_info[neg_item][3]) |
| 130 | neg_product_hist.append(neg_product) |
| 131 | neg_brand = self.map_brand(self.item_info[neg_item][4]) |
| 132 | neg_brand_hist.append(neg_brand) |
| 133 | neg_item = self.map_item(self.all_items[item_idx])#map origin item to item_id |
| 134 | neg_item_hist.append(neg_item) |
| 135 | self.neg_hist_catch[length] = self.neg_hist_catch.get(length, []) # do not understand TODO |
| 136 | self.neg_hist_catch[length].append([neg_item_hist, neg_cate_hist, neg_shop_hist,\ |
| 137 | neg_node_hist, neg_product_hist, neg_brand_hist]) |
| 138 | return [neg_item_hist, neg_cate_hist, neg_shop_hist, neg_node_hist, neg_product_hist, neg_brand_hist] |
| 139 | |
| 140 | def gen_neg_hist3(self, length): |
| 141 | if len(self.neg_hist_catch.get(length, [1])) == self.max_catch_num: |