2.2 KiB
2.2 KiB
Device Mapper Usage
This tool builds a cross-platform lookup index from brands/*.md.
1) Build index
python3 tools/device_mapper.py build
Output file: dist/device_index.json
2) Query from command line
python3 tools/device_mapper.py find --name 'iPhone14,5' --brand Apple
python3 tools/device_mapper.py find --name 'M2102J2SC' --brand Xiaomi
python3 tools/device_mapper.py find --name 'L55M5-AD' --brand Xiaomi
3) JSON structure
records: normalized device recordsdevice_name: standard marketing namebrand: normalized brandmanufacturer_brand: manufacturer-level brand (e.g.Xiaomi)market_brand: market sub-brand (e.g.Xiaomi/Redmi/POCO)device_type:phone | tablet | wear | tv | otheraliases: all known searchable aliases
lookup: normalized alias -> candidaterecord.id[]brand_aliases: normalized brand aliases to filter by app-provided brandbrand_management: brand governance metadatamanufacturer_aliases: canonical brand aliases (华为/huawei/HUAWEI->HUAWEI)manufacturer_to_parent: child -> parent brand (e.g.OnePlus -> OPPO)parent_to_children: parent -> child brandsmarket_brand_aliases: sub-brand aliases (redmi->Redmi)stats: includes parent/manufacturer/market-level counts and Xiaomi combined + separated counts
4) App-side integration (iOS / Android / Harmony)
- Load
dist/device_index.jsoninto memory. - Normalize input
nameand optionalbrand. - Use
lookup[normalized_name]to fetch candidate records. - If
brandexists, normalize it bybrand_management:- manufacturer aliases (e.g.
华为/huawei/HUAWEI->HUAWEI) - market sub-brand aliases (e.g.
redmi->Redmi,xiaomi-> manufacturer-levelXiaomicombined)
- manufacturer aliases (e.g.
- Filter records by normalized manufacturer/market brand as needed.
- Return first candidate (or show all candidates when ambiguous).
Normalization rule should match this script:
- lower-case
- keep only
[0-9a-z\u4e00-\u9fff] - remove all spaces, hyphens, underscores and punctuation
5) Device type mapping
Supported categories:
phonetabletweartvother
Type inference uses keyword + source-file default fallback to reduce misses.