Convert Amazon23 metadata to amazon18-style: - title - description (list → str) - features - categories - brand/store - details (flattened) - images (hi_res list)
(asin2meta, item2index)
| 388 | |
| 389 | |
| 390 | def build_item_features_amazon23(asin2meta, item2index): |
| 391 | """ |
| 392 | Convert Amazon23 metadata to amazon18-style: |
| 393 | - title |
| 394 | - description (list → str) |
| 395 | - features |
| 396 | - categories |
| 397 | - brand/store |
| 398 | - details (flattened) |
| 399 | - images (hi_res list) |
| 400 | """ |
| 401 | |
| 402 | item2feature = {} |
| 403 | |
| 404 | for asin, idx in item2index.items(): |
| 405 | m = asin2meta.get(asin, {}) |
| 406 | |
| 407 | title = clean_text(m.get("title", "")) |
| 408 | |
| 409 | # description: list → single string |
| 410 | desc = m.get("description", []) |
| 411 | if isinstance(desc, list): |
| 412 | desc = " ".join([clean_text(d) for d in desc]) |
| 413 | else: |
| 414 | desc = clean_text(desc) |
| 415 | |
| 416 | # features: list |
| 417 | feats = m.get("features", []) |
| 418 | feats = " ".join([clean_text(f) for f in feats]) if isinstance(feats, list) else clean_text(str(feats)) |
| 419 | |
| 420 | # categories: list of strings → join |
| 421 | cats = m.get("categories", []) |
| 422 | if isinstance(cats, list): |
| 423 | cats = ", ".join([clean_text(c) for c in cats]) |
| 424 | else: |
| 425 | cats = clean_text(str(cats)) |
| 426 | |
| 427 | # brand/store |
| 428 | brand = clean_text(m.get("store", "")) |
| 429 | details = m.get("details", {}) |
| 430 | |
| 431 | # images: extract hi_res if exists |
| 432 | images = m.get("images", []) |
| 433 | image_urls = [] |
| 434 | for img in images: |
| 435 | if isinstance(img, dict): |
| 436 | if "hi_res" in img: |
| 437 | image_urls.append(img["hi_res"]) |
| 438 | elif "large" in img: |
| 439 | image_urls.append(img["large"]) |
| 440 | elif "thumb" in img: |
| 441 | image_urls.append(img["thumb"]) |
| 442 | |
| 443 | item2feature[idx] = { |
| 444 | "title": title, |
| 445 | "description": desc, |
| 446 | "features": feats, |
| 447 | "categories": cats, |