""" 正文字段检查 """ class ContentChecker(object): """ 正文检查 """ errors_tables = { "01": {"name": "正文长度异常", "code": "01", "rules": { "01": { "name": "低于200字", "code": "01", "checkFn": "lt200", }, }, }, "02": {"name": "中文占比异常", "code": "02", "rules": { "01": { "name": "中文字符占比低于30%", "code": "01", "checkFn": "chineseCharLt30", }, }, }, } def __init__(self): pass @staticmethod def lt200(content: str) -> bool: return len(content) < 200 @staticmethod def chineseCharLt30(content: str) -> bool: chinese_char_count = sum(list(map(lambda x: 1 if '\u4e00' <= x <= '\u9fef' else 0, content))) return float(chinese_char_count) / float(len(content)) < 0.3