Estrazione delle caratteristiche: Aggregazione delle proprietà dei componenti
Questo articolo spiega come estraiamo e aggreghiamo le caratteristiche dalla struttura SKU per creare specifiche complete del prodotto.
Il problema: calcolare le caratteristiche del prodotto
Un SKU di prodotto come Treo-N100-8-256-2H-W6-11P è composto da 7 parti:
-
Chassis: Treo
-
Board: N100 (processore Intel N100)
-
RAM: 8GB
-
Flash: 256GB
-
Adapter: 2H (2 porte HDMI)
-
WiFi: W6 (WiFi 6)
-
OS: 11P (Windows 11 Pro)
Ogni parte fornisce caratteristiche. Dobbiamo aggregare tutte le caratteristiche per mostrare specifiche complete del prodotto.
La soluzione: aggregazione ricorsiva delle caratteristiche
Attraversiamo ricorsivamente la struttura SKU, raccogliendo le caratteristiche da ogni parte e dai suoi costituenti.
Passo 1: dividere lo SKU in parti
part_ids = sku.split("-") # ['Treo', 'N100', '8', '256', '2H', 'W6', '11P']
categories = [Categories.CHASSIS, Categories.BOARD, Categories.RAM, ...]
parts = list(zip(categories, part_ids))
Passo 2: trovare le caratteristiche per ogni parte
Per ogni parte, cerchiamo i suoi dati in productdb.json:
def find_features(category, partid):
part_data = productdb.get(category, {}).get(partid, {})
features = {}
# ... (implementation details omitted)
Passo 3: aggregare tutte le caratteristiche
all_features = {}
for category, part_id in parts:
all_features.update(find_features(category, part_id))
Passo 4: formattare e raggruppare per intestazione
Le caratteristiche sono raggruppate per intestazione usando feature_sequence:
feature_sequence = {
"Processor Model": {"Unit": "", "Heading": "Processing"},
"Cores": {"Unit": "", "Heading": "Processing"},
# ... (implementation details omitted)
Per ogni caratteristica in all_features, noi:
- Cerchiamo la sua intestazione in
feature_sequence - Formattiamo il valore con l'unità (se non in modalità raw)
- Raggruppiamo sotto l'intestazione
features = {}
for feature, details in feature_sequence.items():
if feature in all_features:
# ... (implementation details omitted)
Passo 5: aggiungere caratteristiche calcolate
Alcune caratteristiche sono calcolate, non fornite dalle parti:
Weight: peso netto e lordo dalle dimensioni
weight_dims = get_from_sku_weight_dimensions(sku)
if weight_dims["net_weight"] and weight_dims["gross_weight"]:
net_kg = weight_dims["net_weight"] / 1000
gross_kg = weight_dims["gross_weight"] / 1000
features["Physical"]["Net and Gross Weight"] = f"{net_kg:.2f}kg, {gross_kg:.2f}kg"
Struttura di feature_sequence
Il dizionario feature_sequence definisce:
-
Nome della caratteristica: chiave nel campo "provides" di productdb
-
Unità: aggiunta al valore (es. "GHz", "GB", "Watts")
-
Intestazione: nome del gruppo per la visualizzazione
Intestazioni
Le caratteristiche sono raggruppate in 9 intestazioni:
Processing:
-
Generation, Series, Processor Brand, Processor Model
-
Cores, Max Frequency, Cache
-
Main Memory, SSD Storage
Display:
-
Screen Size, Resolution, Brightness, Viewing Angle, Camera
-
HDMI, HDMI 2.0, DisplayPort, VGA
Audio:
-
Speakers, Speaker Out, Mic In
-
Front Speaker Out, Front Mic In
Connectivity:
-
USB 3.2 Gen 2, USB 3.2 Gen 1, USB 3.0, USB 2.0, USB C
-
microSD Slot, Serial Port, Parallel Port, RS485 Port
Networking:
- Ethernet, Wireless Networking
Power:
- DC Voltage, DC Current, Power Input, Power Consumption, Cable Length
Environmental:
- Operating Temperature, Operating Humidity, Certifications
Physical:
-
Form Factor, Thermal Design, Stand
-
Dimensions, Packing Dimensions, Weight
-
Housing Material, Housing Finish, Housing Colour
-
Kensington Lock
Accessories:
- Keyboard and Mouse, VESA Mount
Operating System:
- Operating System, OS Features
Esempio di aggregazione ricorsiva
Considera una board con costituenti:
{
"N100": {
"provides": {
# ... (implementation details omitted)
La parte RAM fornisce:
{
"4": {
"provides": {
"Main Memory": 4
}
}
}
Aggregazione:
- Inizia con la board N100
- Aggiungi le caratteristiche della board:
{"Processor Model": "Intel N100", "Cores": 4, "Max Frequency": 3.4} - Trova ricorsivamente le caratteristiche della RAM:
{"Main Memory": 4} - Moltiplica per la quantità (1):
{"Main Memory": 4} - Unisci:
{"Processor Model": "Intel N100", "Cores": 4, "Max Frequency": 3.4, "Main Memory": 4}
Moltiplicazione delle caratteristiche numeriche
Quando un costituente ha quantità > 1, le caratteristiche numeriche sono moltiplicate:
Esempio: board con 2 moduli RAM
{
"constituents": [
{
"Category": "RAM",
"PartID": "4",
"qty": 2
}
]
}
Risultato: Main Memory = 4 × 2 = 8 GB
Gestione delle caratteristiche non numeriche
Per le caratteristiche non numeriche (stringhe), viene mantenuto l'ultimo valore:
Esempio: adattatori multipli
{
"constituents": [
{"Category": "ADAPTER", "PartID": "2H", "qty": 1},
{"Category": "ADAPTER", "PartID": "1D", "qty": 1}
]
}
Entrambi forniscono {"HDMI": "2"} e {"DisplayPort": "1"}. L'aggregazione li unisce.
Output raw vs formattato
La funzione product_features supporta due modalità:
Formattato (predefinito):
features = product_features("Treo-N100-8-256-2H-W6-11P")
# {"Processing": {"Cores": "4", "Max Frequency": "3.4 GHz", "Main Memory": "8 GB"}}
Raw (per gli embeddings):
features = product_features("Treo-N100-8-256-2H-W6-11P", raw=True)
# {"Processing": {"Cores": "4", "Max Frequency": "3.4", "Main Memory": "8"}}
La modalità raw omette le unità per un testo più pulito negli embeddings.
Filtrare le facet
Non tutte le caratteristiche sono usate per filtrare. Escludiamo:
-
OS Features: troppo specifiche
-
Dimensions: non utili per il filtraggio
-
Weight: non utili per il filtraggio
-
Cache: troppo tecniche
EXCLUDE_FACETS = {"OS Features", "Dimensions", "Weight", "Cache"}
facets_by_heading = {}
# ... (implementation details omitted)
Questo genera FACETS_FOR_FILTERING usato in filter extraction.
Debugging delle caratteristiche non utilizzate
La funzione registra le caratteristiche presenti in productdb ma non in feature_sequence:
unused_features = [
(feature, str(value))
for feature, value in all_features.items()
if feature not in feature_sequence
]
.currentapp.log.debug(unused_features)
Questo aiuta a identificare definizioni di caratteristiche mancanti.
Integrazione con la pipeline
L'estrazione delle caratteristiche è usata in tutto il sistema:
Pagine prodotto
Visualizza le caratteristiche raggruppate per intestazione:
features = product_features(sku)
# Render in template with headings
Embeddings
Estrai le caratteristiche per source data embedding:
features = product_features(sku, raw=True)
# Include in product description for embedding
Filtraggio
Genera opzioni di filtro dalle caratteristiche:
facets = FACETS_FOR_FILTERING
# Use in filter extraction and query pages
Schede tecniche
Visualizza le caratteristiche nelle schede tecniche PDF:
features = product_features(sku)
# Render in datasheet template
Riferimenti
Concetti tecnici
-
Recursion - Wikipedia
-
Tree traversal - Wikipedia
Articoli correlati
-
SKU Structure - Architettura dei componenti separati da trattini
-
SKU productdb - Fonte unica di verità per i prodotti
-
Source Data Embedding - Usare le caratteristiche negli embeddings
-
Filter Extraction - Usare le caratteristiche per il filtraggio
Riepilogo
L'estrazione delle caratteristiche aggrega le proprietà dei componenti nelle specifiche del prodotto:
Processo:
-
Dividi lo SKU in parti (7 componenti)
-
Trova ricorsivamente le caratteristiche per ogni parte
-
Aggrega le caratteristiche (moltiplica le numeriche per la quantità)
-
Formatta con unità (GHz, GB, Watts)
-
Raggruppa per intestazione (Processing, Display, Connectivity, ecc.)
-
Aggiungi caratteristiche calcolate (peso dalle dimensioni)
Output:
-
Formattato: "4 Cores, 3.4 GHz, 8 GB RAM"
-
Raw: "4, 3.4, 8" (per embeddings)
-
Raggruppato: 9 intestazioni con caratteristiche
Vantaggi:
-
Aggregazione automatica (nessun inserimento manuale)
-
Formattazione coerente (unità da feature_sequence)
-
Composizione ricorsiva (le parti possono avere costituenti)
-
Output flessibile (formattato o raw)
Questo consente la generazione automatica delle specifiche di prodotto dalla sola struttura SKU.