MCPcopy Create free account
hub / github.com/AkaliKong/MiniOneRec / load_metadata_amazon23

Function load_metadata_amazon23

data/amazon23_data_process.py:94–141  ·  view source on GitHub ↗
(metadata_file)

Source from the content-addressed store, hash-verified

92 return reviews
93
94def load_metadata_amazon23(metadata_file):
95
96 if not os.path.exists(metadata_file):
97 print(f"[ERROR] Metadata file not found: {metadata_file}")
98 return {}, {}
99
100 print(f"Loading Amazon23 metadata from: {metadata_file}")
101
102 asin2meta = {}
103 asin2title = {}
104
105 with open(metadata_file, "r", encoding="utf-8") as f:
106 for line in tqdm(f, desc="Reading metadata"):
107 try:
108 m = json.loads(line.strip())
109
110 # Amazon 23 metadata may not have "asin", only "parent_asin"
111 asin = m.get("parent_asin", None)
112
113 if asin is None:
114 # skip items with no valid id
115 print("wrong!")
116 continue
117
118 title = clean_text(m.get("title", ""))
119
120 asin2meta[asin] = {
121 "title": title,
122 "main_category": m.get("main_category", ""),
123 "features": m.get("features", []),
124 "description": m.get("description", []),
125 "price": m.get("price", None),
126 "images": m.get("images", []),
127 "categories": m.get("categories", []),
128 "details": m.get("details", {}),
129 "store": m.get("store", ""),
130 "brand": m.get("store", ""),
131 "parent_asin": m.get("parent_asin", "")
132 }
133
134 if len(title) > 0:
135 asin2title[asin] = title
136
137 except Exception:
138 continue
139
140 print(f"[INFO] Loaded {len(asin2meta)} metadata entries, {len(asin2title)} titles")
141 return asin2meta, asin2title
142
143def k_core_filter_amazon23(reviews, asin2title, K=5, start_timestamp=None, end_timestamp=None):
144 """

Callers 1

mainFunction · 0.85

Calls 1

clean_textFunction · 0.70

Tested by

no test coverage detected