How do you distinguish punctuation, letters and combining marks?
category reports the two-letter Unicode general category for a character, enabling a breakdown of text composition.
Python example and interpretation
A period, a Han character and a combining accent have different categories. Removing marks can alter words in some languages, so choose filters for the task.
from unicodedata import category
[category(c) for c in ['.','中','\u0301']]Result ['Po', 'Lo', 'Mn']
中文
如何区分标点、字母和组合标记?
category 返回 Unicode 通用类别,两字符代码可用来分析文本的字符构成。
Python 算例与适用条件
句号、汉字、组合重音分别属于不同类别。按类别过滤前应考虑任务需求,删掉重音会改变部分语言的词义。
from unicodedata import category
[category(c) for c in ['.','中','\u0301']]结果 ['Po', 'Lo', 'Mn']