[create_mapping_for_normalization]将大量同义词转换为映射表,如 ibm,国际商业机器公司,ibm中国 转换为 {'国际商业及其公司':'ibm', 'ibm中国':'ibm'} #dict
✓ Published0🌍 Public
SShawn91
Last edited May 13, 2019
Created on May 13, 2019
This example shows a Python utility that converts a plain-text list of synonym groups into a normalization mapping dictionary, e.g., turning "ibm,国际商业机器公司,ibm中国" into `{'国际商业及其公司':'ibm', 'ibm中国':'ibm'}`. The function `create_mapping_for_normalization` reads either a file path or a list, splits each line by a configurable separator, and uses a `key` function to designate the standard term among each group. It optionally skips duplicate words to avoid overwriting existing mappings. The included test demonstrates the process with sample data containing company names in multiple languages. The code relies solely on Python’s standard library, using built-in file I/O and data structures.
AI-generated description