diff --git a/dict/tags.json b/dict/tags.json index c12e45d..350f719 100644 --- a/dict/tags.json +++ b/dict/tags.json @@ -1,758 +1,561 @@ { - "version": 5, - "description": "标签词典 v5 — 完整重建,覆盖 9 大分类 + 11629 个相册标题", - "tags": { - "style": { - "label": "风格", - "color_bg": "#f0f9ff", - "color_fg": "#0284c7", - "words": [ - "sexy", - "wild", - "可爱", - "retro", - "韩系", - "街头", - "优雅", - "古典", - "潮流", - "甜美", - "温柔", - "日系", - "korean", - "fashion", - "sweet", - "民族", - "森系", - "异域", - "野性", - "清纯", - "pure", - "fresh", - "elegant", - "cute", - "vintage", - "japanese", - "冷艳", - "知性", - "俏皮", - "文艺", - "学院", - "时尚", - "复古", - "清新", - "简约", - "自然", - "运动" - ] - }, - "outfit": { - "label": "服装", - "color_bg": "#fdf2f8", - "color_fg": "#db2777", - "words": [ - "黑色礼服", - "女秘书", - "比基尼", - "兔女郎", - "泳装", - "泳衣", - "旗袍", - "制服", - "丝袜", - "内衣", - "文胸", - "包臀裙", - "紧身裙", - "超短裙", - "连衣裙", - "半身裙", - "短裙", - "丁字裤", - "长裙", - "牛仔裤", - "热裤", - "短裤", - "休闲裤", - "西装裤", - "T恤", - "衬衫", - "毛衣", - "针织衫", - "西装", - "外套", - "风衣", - "大衣", - "夹克", - "马甲", - "卫衣", - "蕾丝", - "吊带", - "抹胸", - "薄纱", - "镂空", - "开衩", - "一字肩", - "露背", - "露肩", - "深V", - "低胸", - "高开衩", - "学生服", - "水手服", - "护士服", - "女仆装", - "洛丽塔", - "和服", - "汉服", - "浴衣", - "校服", - "白衬衫", - "黑衬衫", - "白裙", - "黑裙", - "红裙", - "裹胸", - "吊带裙", - "修身", - "长靴", - "高跟鞋", - "凉鞋", - "运动鞋", - "帆布鞋", - "ol套装", - "工作服", - "空姐", - "警服", - "军装", - "黑丝", - "白丝", - "肉丝", - "网袜" - ] - }, - "scene": { - "label": "场景", - "color_bg": "#f0fdf4", - "color_fg": "#15803d", - "words": [ - "室内", - "户外", - "棚拍", - "外景", - "街景", - "夜景", - "日系", - "海边", - "海滩", - "沙滩", - "泳池", - "浴室", - "浴缸", - "厨房", - "客厅", - "卧室", - "阳台", - "花园", - "庭院", - "天台", - "楼顶", - "屋顶", - "咖啡厅", - "酒店", - "民宿", - "教室", - "图书馆", - "办公室", - "楼梯", - "电梯", - "草地", - "森林", - "树林", - "竹林", - "花丛", - "花海", - "公园", - "操场", - "马路", - "公路", - "天桥", - "隧道", - "床上", - "复古" - ] - }, - "body": { - "label": "身体", - "color_bg": "#fef3c7", - "color_fg": "#b45309", - "words": [ - "美腿", - "美胸", - "翘臀", - "玉足", - "美背", - "香肩", - "酥胸", - "纤腰", - "蛮腰", - "蜂腰", - "小蛮腰", - "事业线", - "锁骨", - "马甲线", - "腹肌", - "长腿", - "美足", - "白皙", - "肌肤", - "纹身", - "legs", - "breasts", - "ass", - "feet", - "back", - "shoulders", - "waist", - "skin", - "tattoo" - ] - }, - "mood": { - "label": "情绪", - "color_bg": "#faf5ff", - "color_fg": "#7c3aed", - "words": [ - "清纯", - "诱惑", - "唯美", - "清新", - "冷艳", - "妩媚", - "娇羞", - "俏皮", - "温柔", - "野性", - "冷傲", - "热情", - "慵懒", - "迷离", - "甜美", - "知性", - "可爱", - "pure", - "seductive", - "beautiful", - "fresh", - "cool", - "charming", - "shy", - "cute", - "gentle", - "wild", - "lazy", - "sweet", - "神秘", - "忧郁", - "伤感", - "快乐", - "开心", - "微笑", - "大笑", - "闭眼", - "凝视", - "魅惑", - "撩人", - "高冷", - "呆萌", - "天真", - "无辜", - "纯真" - ] - }, - "topic": { - "label": "主题", - "color_bg": "#f0f9ff", - "color_fg": "#0369a1", - "words": [ - "写真", - "私房", - "街拍", - "旅拍", - "婚纱照", - "艺术照", - "生活照", - "自拍", - "跟拍", - "约拍", - "商拍", - "cosplay", - "角色扮演", - "动漫", - "游戏", - "手办", - "周边", - "海报", - "壁纸", - "画集", - "图集", - "水着", - "竞泳", - "温泉", - "入浴", - "photoshoot", - "portrait", - "selfie", - "travel", - "wedding", - "Genshin" - ] - }, - "position": { - "label": "姿势", - "color_bg": "#fefce8", - "color_fg": "#a16207", - "words": [ - "站立", - "坐姿", - "躺姿", - "跪姿", - "趴姿", - "侧躺", - "侧卧", - "仰卧", - "俯卧", - "站姿", - "站", - "坐", - "躺", - "跪", - "趴", - "蹲", - "回眸", - "背影", - "正面", - "侧面", - "standing", - "sitting", - "lying", - "kneeling" - ] - }, - "location": { - "label": "地点", - "color_bg": "#f0fdfa", - "color_fg": "#0f766e", - "words": [ - "日本", - "韩国", - "中国", - "台湾", - "香港", - "泰国", - "越南", - "东京", - "首尔", - "北京", - "上海", - "广州", - "深圳", - "成都", - "重庆", - "三亚", - "厦门", - "丽江", - "大理", - "曼谷", - "芭提雅", - "普吉", - "济州", - "巴厘岛", - "马尔代夫", - "沙巴", - "塞班", - "苏梅岛", - "普吉岛", - "冲绳", - "京都", - "大阪", - "北海道", - "江浙沪", - "阳朔", - "japan", - "korea", - "china", - "thailand", - "tokyo", - "seoul", - "bangkok", - "phuket", - "bali" - ] - }, - "brand": { - "label": "品牌", - "color_bg": "#fff7ed", - "color_fg": "#c2410c", - "words": [ - "Victoria's Secret", - "Victorias Secret", - "VS", - "维密", - "维多利亚的秘密", - "La Perla", - "Agent Provocateur", - "CK", - "Calvin Klein", - "Nike", - "Adidas", - "Puma", - "Gucci", - "Prada", - "Chanel", - "Louis Vuitton", - "LV", - "Dior", - "Hermes", - "Shiseido", - "资生堂", - "Apple", - "Sony", - "Canon", - "Fantasy Factory", - "XiuRen", - "秀人", - "秀人网", - "XiuRen秀人网", - "爱蜜社", - "IMiss爱蜜社", - "IMISS", - "MiStar", - "尤蜜", - "YouMi", - "YouMi尤蜜", - "YOUMI尤蜜荟", - "尤蜜荟", - "美媛馆", - "魅妍社", - "语画界", - "XIAOYU语画界", - "XIAOYU", - "花漾", - "HuaYang", - "MFStar模特", - "MFStar模范学院", - "MFStar", - "TGOD推女神", - "TGOD", - "DKGirl御女郎", - "DKGirl", - "XINGYAN星颜社", - "XINGYAN", - "FEILIN嗲囡囡", - "FEILIN", - "Feiling", - "飞灵", - "CANDY糖果画报", - "CANDY", - "YouWu尤物馆", - "YouWu", - "尤物馆", - "UXING优星馆", - "UXING", - "RuiSG瑞丝馆", - "RuiSG", - "瑞丝馆", - "SIW斯文传媒", - "SIW", - "SLADY猎女神", - "SLADY", - "SSA丝社", - "SSA", - "SJA佳爷", - "SJA", - "TASHA系列", - "TASHA", - "Ugirls爱尤物", - "Ugirls", - "爱尤物", - "V Girls", - "VGIRL", - "VGIRLS", - "WingS影私荟", - "WING", - "YALAYI雅拉伊", - "YALAYI", - "ISHOW爱秀", - "ISHOW", - "BlueCake", - "MiiTao蜜桃社", - "MiiTao", - "蜜桃社", - "108TV", - "108酱", - "撸图", - "情欲萝莉", - "头条女神", - "尤果网", - "尤果圈", - "波萝社", - "BoLoli", - "星颜社", - "绯月樱", - "青豆客", - "Beautyleg", - "MFModel", - "LeiLei", - "Tristana", - "Pure Media", - "PureMedia", - "Victoria Secret", - "OnlyFans" - ] - } + "version": 4, + "description": "标签词典 v4 — 全量 keymap + stopwords(人物规则已融入 keymap)", + "metadata": { + "style": { "label": "风格", "color_bg": "#f0f9ff", "color_fg": "#0284c7" }, + "outfit": { "label": "服装", "color_bg": "#fdf2f8", "color_fg": "#db2777" }, + "scene": { "label": "场景", "color_bg": "#f0fdf4", "color_fg": "#15803d" }, + "body": { "label": "身体", "color_bg": "#fef3c7", "color_fg": "#b45309" }, + "mood": { "label": "情绪", "color_bg": "#faf5ff", "color_fg": "#7c3aed" }, + "topic": { "label": "主题", "color_bg": "#f0f9ff", "color_fg": "#0369a1" }, + "position": { "label": "姿势", "color_bg": "#fefce8", "color_fg": "#a16207" }, + "location": { "label": "地点", "color_bg": "#f0fdfa", "color_fg": "#0f766e" }, + "brand": { "label": "品牌/工作室", "color_bg": "#fff7ed", "color_fg": "#c2410c" }, + "person": { "label": "人物", "color_bg": "#ecfdf5", "color_fg": "#059669" } + }, + "keymap": { + "108TV": "brand", + "108酱": "brand", + "Adidas": "brand", + "Agent Provocateur": "brand", + "Apple": "brand", + "Av": "brand", + "Beautyleg": "brand", + "BlueCake": "brand", + "BoLoli": "brand", + "CK": "brand", + "Calvin Klein": "brand", + "CANDY": "brand", + "CANDY糖果画报": "brand", + "Canon": "brand", + "Chanel": "brand", + "DKGirl": "brand", + "DKGirl御女郎": "brand", + "Dior": "brand", + "FEILIN": "brand", + "FEILIN嗲囡囡": "brand", + "Fantasy Factory": "brand", + "FeiLin": "brand", + "Feiling": "brand", + "Gucci": "brand", + "Hermes": "brand", + "HuaYang": "brand", + "IMISS": "brand", + "IMiss": "brand", + "IMiss爱蜜社": "brand", + "ISHOW": "brand", + "ISHOW爱秀": "brand", + "La Perla": "brand", + "LeiLei": "brand", + "Louis Vuitton": "brand", + "MFModel": "brand", + "MFStar": "brand", + "MFStar模特": "brand", + "MFStar模范学院": "brand", + "MiiTao": "brand", + "MiiTao蜜桃社": "brand", + "MiStar": "brand", + "Nike": "brand", + "OnlyFans": "brand", + "Prada": "brand", + "Puma": "brand", + "Pure Media": "brand", + "PureMedia": "brand", + "RuiSG": "brand", + "RuiSG瑞丝馆": "brand", + "SIW": "brand", + "SIW斯文传媒": "brand", + "SJA": "brand", + "SJA佳爷": "brand", + "SLADY": "brand", + "SLADY猎女神": "brand", + "SSA": "brand", + "SSA丝社": "brand", + "Shiseido": "brand", + "Sony": "brand", + "TASHA": "brand", + "TASHA系列": "brand", + "TGOD": "brand", + "TGOD推女神": "brand", + "Tristana": "brand", + "UXING": "brand", + "UXING优星馆": "brand", + "Ugirls": "brand", + "Ugirls爱尤物": "brand", + "V Girls": "brand", + "VGIRL": "brand", + "VGIRLS": "brand", + "VS": "brand", + "Victoria Secret": "brand", + "Victoria's Secret": "brand", + "Victorias Secret": "brand", + "WING": "brand", + "WingS": "brand", + "WingS影私荟": "brand", + "XIAOYU": "brand", + "XIAOYU语画界": "brand", + "XINGYAN": "brand", + "XINGYAN星颜社": "brand", + "XiuRen": "brand", + "XiuRen秀人网": "brand", + "YALAYI": "brand", + "YALAYI雅拉伊": "brand", + "YOUMI尤蜜荟": "brand", + "YouMi": "brand", + "YouMi尤蜜": "brand", + "YouWu": "brand", + "YouWu尤物馆": "brand", + "爱尤物": "brand", + "爱蜜社": "brand", + "波萝社": "brand", + "飞灵": "brand", + "绯月樱": "brand", + "花洋": "brand", + "花漾": "brand", + "美媛馆": "brand", + "魅妍社": "brand", + "蜜桃社": "brand", + "撸图": "brand", + "情欲萝莉": "brand", + "青豆客": "brand", + "瑞丝馆": "brand", + "头条女神": "brand", + "推女神": "brand", + "星颜社": "brand", + "秀人": "brand", + "秀人网": "brand", + "语画界": "brand", + "尤果网": "brand", + "尤果圈": "brand", + "尤蜜": "brand", + "尤蜜荟": "brand", + "尤物馆": "brand", + "旗袍": "outfit", + "比基尼": "outfit", + "泳装": "outfit", + "泳衣": "outfit", + "制服": "outfit", + "丝袜": "outfit", + "内衣": "outfit", + "文胸": "outfit", + "包臀裙": "outfit", + "紧身裙": "outfit", + "超短裙": "outfit", + "连衣裙": "outfit", + "半身裙": "outfit", + "短裙": "outfit", + "丁字裤": "outfit", + "长裙": "outfit", + "牛仔裤": "outfit", + "热裤": "outfit", + "短裤": "outfit", + "休闲裤": "outfit", + "T恤": "outfit", + "衬衫": "outfit", + "毛衣": "outfit", + "针织衫": "outfit", + "西装": "outfit", + "外套": "outfit", + "风衣": "outfit", + "大衣": "outfit", + "马甲": "outfit", + "卫衣": "outfit", + "吊带": "outfit", + "抹胸": "outfit", + "露背": "outfit", + "透视": "outfit", + "蕾丝": "outfit", + "镂空": "outfit", + "开衩": "outfit", + "一字肩": "outfit", + "露肩": "outfit", + "深V": "outfit", + "低胸": "outfit", + "高开衩": "outfit", + "学生服": "outfit", + "水手服": "outfit", + "护士服": "outfit", + "女仆装": "outfit", + "洛丽塔": "outfit", + "和服": "outfit", + "汉服": "outfit", + "浴衣": "outfit", + "校服": "outfit", + "白衬衫": "outfit", + "黑衬衫": "outfit", + "白裙": "outfit", + "黑裙": "outfit", + "红裙": "outfit", + "裹胸": "outfit", + "吊带裙": "outfit", + "修身": "outfit", + "长靴": "outfit", + "高跟鞋": "outfit", + "凉鞋": "outfit", + "运动鞋": "outfit", + "ol套装": "outfit", + "工作服": "outfit", + "空姐": "outfit", + "警服": "outfit", + "军装": "outfit", + "黑丝": "outfit", + "白丝": "outfit", + "肉丝": "outfit", + "网袜": "outfit", + "bikini": "outfit", + "swimsuit": "outfit", + "stockings": "outfit", + "lingerie": "outfit", + "dress": "outfit", + "skirt": "outfit", + "jeans": "outfit", + "shirt": "outfit", + "coat": "outfit", + "heels": "outfit", + "室内": "scene", + "户外": "scene", + "棚拍": "scene", + "外景": "scene", + "街景": "scene", + "夜景": "scene", + "海边": "scene", + "海滩": "scene", + "沙滩": "scene", + "泳池": "scene", + "浴室": "scene", + "浴缸": "scene", + "厨房": "scene", + "客厅": "scene", + "卧室": "scene", + "阳台": "scene", + "花园": "scene", + "庭院": "scene", + "天台": "scene", + "楼顶": "scene", + "屋顶": "scene", + "咖啡厅": "scene", + "酒店": "scene", + "民宿": "scene", + "教室": "scene", + "图书馆": "scene", + "办公室": "scene", + "楼梯": "scene", + "电梯": "scene", + "草地": "scene", + "森林": "scene", + "树林": "scene", + "竹林": "scene", + "花丛": "scene", + "花海": "scene", + "公园": "scene", + "操场": "scene", + "马路": "scene", + "公路": "scene", + "天桥": "scene", + "隧道": "scene", + "床上": "scene", + "indoor": "scene", + "outdoor": "scene", + "street": "scene", + "beach": "scene", + "pool": "scene", + "bathroom": "scene", + "bedroom": "scene", + "kitchen": "scene", + "car": "scene", + "cafe": "scene", + "hotel": "scene", + "美腿": "body", + "美胸": "body", + "翘臀": "body", + "玉足": "body", + "美背": "body", + "香肩": "body", + "酥胸": "body", + "纤腰": "body", + "蛮腰": "body", + "蜂腰": "body", + "小蛮腰": "body", + "事业线": "body", + "锁骨": "body", + "马甲线": "body", + "腹肌": "body", + "长腿": "body", + "美足": "body", + "白皙": "body", + "肌肤": "body", + "纹身": "body", + "legs": "body", + "breasts": "body", + "ass": "body", + "feet": "body", + "back": "body", + "shoulders": "body", + "waist": "body", + "skin": "body", + "tattoo": "body", + "清纯": "mood", + "诱惑": "mood", + "唯美": "mood", + "清新": "mood", + "冷艳": "mood", + "妩媚": "mood", + "娇羞": "mood", + "俏皮": "mood", + "温柔": "mood", + "野性": "mood", + "冷傲": "mood", + "热情": "mood", + "慵懒": "mood", + "迷离": "mood", + "甜美": "mood", + "知性": "mood", + "可爱": "mood", + "神秘": "mood", + "忧郁": "mood", + "伤感": "mood", + "快乐": "mood", + "开心": "mood", + "微笑": "mood", + "大笑": "mood", + "闭眼": "mood", + "凝视": "mood", + "魅惑": "mood", + "撩人": "mood", + "高冷": "mood", + "呆萌": "mood", + "天真": "mood", + "无辜": "mood", + "纯真": "mood", + "pure": "mood", + "sweet": "mood", + "fresh": "mood", + "elegant": "mood", + "cute": "mood", + "wild": "mood", + "lazy": "mood", + "sweet": "mood", + "写真": "topic", + "私房": "topic", + "街拍": "topic", + "旅拍": "topic", + "婚纱照": "topic", + "艺术照": "topic", + "生活照": "topic", + "自拍": "topic", + "cosplay": "topic", + "角色扮演": "topic", + "动漫": "topic", + "游戏": "topic", + "水着": "topic", + "竞泳": "topic", + "温泉": "topic", + "入浴": "topic", + "photoshoot": "topic", + "portrait": "topic", + "selfie": "topic", + "travel": "topic", + "wedding": "topic", + "Genshin": "topic", + "站立": "position", + "坐姿": "position", + "躺姿": "position", + "跪姿": "position", + "趴姿": "position", + "侧躺": "position", + "侧卧": "position", + "仰卧": "position", + "俯卧": "position", + "站姿": "position", + "站": "position", + "坐": "position", + "躺": "position", + "跪": "position", + "趴": "position", + "蹲": "position", + "回眸": "position", + "背影": "position", + "正面": "position", + "侧面": "position", + "standing": "position", + "sitting": "position", + "lying": "position", + "kneeling": "position", + "日本": "location", + "韩国": "location", + "中国": "location", + "台湾": "location", + "香港": "location", + "泰国": "location", + "越南": "location", + "东京": "location", + "首尔": "location", + "北京": "location", + "上海": "location", + "广州": "location", + "深圳": "location", + "成都": "location", + "重庆": "location", + "三亚": "location", + "厦门": "location", + "丽江": "location", + "大理": "location", + "曼谷": "location", + "芭提雅": "location", + "普吉": "location", + "济州": "location", + "巴厘岛": "location", + "马尔代夫": "location", + "沙巴": "location", + "塞班": "location", + "苏梅岛": "location", + "普吉岛": "location", + "冲绳": "location", + "京都": "location", + "大阪": "location", + "北海道": "location", + "阳朔": "location", + "japan": "location", + "korea": "location", + "china": "location", + "thailand": "location", + "tokyo": "location", + "seoul": "location", + "bangkok": "location", + "phuket": "location", + "bali": "location", + "日系": "style", + "韩系": "style", + "森系": "style", + "复古": "style", + "甜美": "style", + "性感": "style", + "清新": "style", + "冷艳": "style", + "优雅": "style", + "知性": "style", + "可爱": "style", + "俏皮": "style", + "温柔": "style", + "妩媚": "style", + "野性": "style", + "清纯": "style", + "时尚": "style", + "潮流": "style", + "街头": "style", + "学院": "style", + "文艺": "style", + "古典": "style", + "民族": "style", + "异域": "style", + "简约": "style", + "自然": "style", + "运动": "style", + "sexy": "style", + "wild": "style", + "retro": "style", + "korean": "style", + "fashion": "style", + "sweet": "style", + "pure": "style", + "fresh": "style", + "elegant": "style", + "cute": "style", + "vintage": "style", + "japanese": "style", + "杨晨晨": "person", + "水淼": "person", + "轩美宣": "person", + "王馨瑶": "person", + "雪儿": "person", + "顾雪儿": "person", + "曼曼": "person", + "佳佳": "person", + "小乔": "person", + "周于希": "person", + "王雨纯": "person", + "绮里嘉": "person", + "陆萱萱": "person", + "唐安琪": "person", + "鱼子酱": "person", + "安然": "person", + "林星阑": "person", + "筱慧": "person", + "蠢沫沫": "person", + "冯木木": "person", + "许诺": "person", + "言沫": "person", + "丽莎": "person", + "易阳": "person", + "陈良玲": "person", + "蓝夏": "person", + "凯竹": "person", + "郑颖姗": "person", + "刘飞儿": "person", + "赵小米": "person", + "于姬": "person", + "玉兔": "person", + "穆菲菲": "person", + "夏沫沫": "person", + "雪晴": "person", + "小夕": "person", + "谢芷馨": "person", + "顾奈奈": "person", + "唐琪儿": "person", + "艾小青": "person", + "李雅": "person", + "晓茜": "person", + "李宓儿": "person", + "林乐": "person", + "雪千寻": "person", + "艾静香": "person", + "阿薰": "person", + "李承美": "person", + "葛征": "person", + "沈佳熹": "person", + "陈思琪": "person", + "刘娅": "person", + "小瑶": "person", + "李梓": "person", + "程小烦": "person", + "马吉": "person", + "叶佳": "person", + "冯雪娇": "person", + "栗子": "person", + "丁筱南": "person", + "张思允": "person", + "小齿优喵": "person", + "KaYa Huang": "person", + "Miley": "person", + "Alice": "person", + "Zia": "person", + "Jooa": "person", + "Yome": "person", + "石川澪": "person", + "朱可儿": "person", + "苏雨": "person", + "熊吖": "person" }, "stop_words": [ - "photos", - "photo", - "pictures", - "picture", - "images", - "image", - "video", - "videos", - "cosplay", - "cos", - "and", - "the", - "of", - "in", - "a", - "an", - "is", - "to", - "for", - "part", - "vol", - "collection", - "special", - "extra", - "bonus", - "new", - "old", - "selfie", - "official", - "original", - "set", - "gallery", - "album", - "page", - "issue", - "model", - "idol", - "star", - "actor", - "actress", - "singer", - "秀人", - "网", - "图", - "套", - "合集", - "系列", - "作品", - "美女", - "模特", - "高清", - "原版", - "无水印", - "番号", - "编号", - "with", - "without", - "preview", - "patreon", - "no", - "site", - "web", - "online", - "digital", - "exclusive", - "premium", - "classic", - "photography", - "shoot", - "shot", - "xxx", - "com", - "www", - "https", - "http" + "photos", "photo", "pictures", "picture", "images", "image", + "video", "videos", "cosplay", "cos", + "and", "the", "of", "in", "a", "an", "is", "to", "for", + "part", "vol", "collection", "special", "extra", "bonus", + "new", "old", "selfie", "official", "original", + "set", "gallery", "album", "page", "issue", + "model", "idol", "star", "actor", "actress", "singer", + "秀人", "网", "图", "套", "合集", "系列", "作品", + "美女", "模特", "女神", "小姐姐", "高清", "原版", "无水印", + "番号", "编号", "with", "without", "preview", "patreon", + "no", "site", "web", "online", "digital", "exclusive", "premium", + "classic", "photography", "shoot", "shot", + "xxx", "com", "www", "https", "http", + "Impact", "写真", "系列" + ], - "person_rules": { - "prefixes": [ - "美女模特", - "性感女神", - "清纯美女", - "气质美女", - "可爱女孩", - "甜美少女", - "时尚达人", - "女神", - "美女", - "模特", - "小姐姐", - "小仙女", - "御姐", - "萝莉", - "辣妹", - "潮人" - ], - "excluded": [ - "XiuRen", - "xiuren", - "秀人", - "秀人网", - "MFStar", - "MFStar模特", - "MiiTao", - "蜜桃社", - "YouMi", - "尤蜜", - "HuaYang", - "花洋", - "FeiLin", - "Feiling", - "飞灵", - "MFModel", - "LeiLei", - "Tristana", - "Av", - "写真", - "情趣", - "性感", - "Impact", - "宅男", - "黑丝", - "美腿", - "真空", - "诱惑", - "私房", - "气质", - "女神", - "丝袜", - "黑色", - "礼服", - "Girl", - "丝袜美腿", - "诱惑写真", - "分析师", - "头条女神", - "尤果网", - "尤果圈", - "波萝社", - "BoLoli", - "绯月樱", - "青豆客", - "Beautyleg", - "108TV", - "108酱", - "撸图", - "情欲萝莉", - "星颜社", - "爱尤物", - "尤物馆", - "女模特", - "内衣秀", - "职业装", - "丝袜系列写真", - "制服系列写真", - "制服诱惑写真", - "黑丝美腿", - "丝袜美腿内衣", - "内衣诱惑写真", - "原色丝袜", - "原色丝袜私房", - "原色丝袜性感", - "白衬衫黑短裙", - "空姐制服", - "韵味旗袍" - ], - "include": [ - "杨晨晨", - "水淼", - "轩美宣", - "王馨瑶", - "雪儿", - "曼曼", - "佳佳", - "小乔", - "周于希", - "王雨纯", - "绮里嘉", - "陆萱萱", - "唐安琪", - "鱼子酱", - "安然", - "林星阑", - "筱慧", - "蠢沫沫", - "冯木木", - "许诺", - "言沫", - "丽莎", - "易阳", - "陈良玲", - "蓝夏", - "凯竹", - "郑颖姗", - "刘飞儿", - "赵小米", - "于姬", - "玉兔", - "穆菲菲", - "夏沫沫", - "雪晴", - "熊吖", - "小夕", - "谢芷馨", - "顾奈奈", - "唐琪儿", - "熊小诺", - "黄歆苑", - "艾小青", - "李雅", - "晓茜", - "李宓儿", - "林乐", - "雪千寻", - "艾静香", - "阿薰", - "李承美", - "葛征", - "沈佳熹", - "陈思琪", - "刘娅", - "小瑶", - "李梓", - "程小烦", - "马吉", - "叶佳", - "冯雪娇", - "栗子", - "丁筱南", - "张思允", - "小齿优喵", - "Xiao chi you miao", - "KaYa Huang", - "Miley", - "Alice", - "Zia", - "Jooa", - "Yome", - "石川澪", - "朱可儿", - "苏雨" - ] - } -} \ No newline at end of file + "person_prefixes": [ + "美女模特", "性感女神", "清纯美女", "气质美女", "可爱女孩", + "甜美少女", "时尚达人", "女神", "美女", "模特", "小姐姐", + "小仙女", "御姐", "萝莉", "辣妹", "潮人" + ] +} diff --git a/src/engine/person_merger.rs b/src/engine/person_merger.rs index 8f7d31e..5717e56 100644 --- a/src/engine/person_merger.rs +++ b/src/engine/person_merger.rs @@ -128,12 +128,13 @@ pub fn deep_match_title( let title_clean = title.trim(); // 策略1: 用正则提取人名 - if let Some(extracted) = crate::engine::title_parser::extract_person_name_from_title(title_clean) { - if known_names.contains(&extracted) { + let extracted = crate::engine::title_parser::extract_person_name_from_title(title_clean); + if let Some(ref e) = extracted { + if known_names.contains(e) { result.matched = true; result.method = "jieba_extract".to_string(); - result.person = Some(extracted.clone()); - result.matched_text = Some(extracted); + result.person = Some(e.clone()); + result.matched_text = Some(e.clone()); return result; } } diff --git a/src/engine/pipeline.rs b/src/engine/pipeline.rs index 926ad1a..d59e23e 100644 --- a/src/engine/pipeline.rs +++ b/src/engine/pipeline.rs @@ -166,7 +166,9 @@ pub async fn phase_detect_person_in_tags(db: &Database) -> (DirtySet, usize) { match (&jieba_name, &best_layer1) { (Some(j), Some(b)) => { // jieba 结果更完整 → 用 jieba - if j.len() > b.len() || title_parser::is_excluded_name(b) { Some(j.clone()) } else { Some(b.clone()) } + let j_len: usize = j.len(); + let b_len: usize = b.len(); + if j_len > b_len || title_parser::is_excluded_name(b) { Some(j.clone()) } else { Some(b.clone()) } } (Some(j), None) => Some(j.clone()), (None, Some(b)) => Some(b.clone()), diff --git a/src/engine/tag_dict.rs b/src/engine/tag_dict.rs index 18fde9a..ba3e825 100644 --- a/src/engine/tag_dict.rs +++ b/src/engine/tag_dict.rs @@ -1,15 +1,13 @@ //! 标签词典 — 从外部 JSON 文件加载分类标签、停用词、人物规则 //! -//! 词典文件格式(dict/tags.json v2): +//! 词典文件格式(dict/tags.json v4): //! ```json //! { -//! "version": 2, -//! "tags": { "style": {"words": [...]}, "outfit": {...}, ... }, +//! "version": 4, +//! "metadata": { "style": {"label":"风格","color_bg":"...","color_fg":"..."}, ... }, +//! "keymap": { "日系": "style", "比基尼": "outfit", ... }, //! "stop_words": [...], -//! "person_rules": { -//! "prefixes": ["美女模特", ...], -//! "excluded": ["XiuRen", ...] -//! } +//! "person_rules": { "prefixes": [...], "excluded": [...], "include": [...] } //! } //! ``` @@ -19,50 +17,45 @@ use serde::Deserialize; use lazy_static::lazy_static; use std::sync::RwLock; -// ── JSON 反序列化结构 ── +// ── JSON 反序列化结构 (v4) ── -/// 词典文件的顶层结构 (v3) +/// v4 分类元数据(label + 颜色) +#[derive(Debug, Clone, Deserialize)] +pub struct CategoryMeta { + #[serde(default)] + pub label: String, + #[serde(default = "default_color_bg")] + pub color_bg: String, + #[serde(default = "default_color_fg")] + pub color_fg: String, +} + +fn default_color_bg() -> String { "#f1f5f9".to_string() } +fn default_color_fg() -> String { "#64748b".to_string() } + +/// 词典文件的顶层结构 (v4) #[derive(Debug, Clone, Deserialize)] pub struct TagDictFile { pub version: u32, #[allow(unused)] pub description: Option, - /// v3: 分类元数据 { "style": {"label":..., "color_bg":..., ...} } + /// v4: 分类元数据 { "style": {"label":"风格","color_bg":"...","color_fg":"..."}, ... } #[serde(default)] - pub categories: HashMap, - /// v3: 分类词表 { "style": ["日系", ...], "outfit": [...], ... } + pub metadata: HashMap, + /// v4: 扁平化匹配串→分类名 { "日系": "style", "比基尼": "outfit", ... } + #[serde(default)] + pub keymap: HashMap, + /// 停用词列表 #[serde(default)] - pub tags: HashMap>, pub stop_words: Vec, + /// 人物称呼前缀(顶层字段,从 JSON 文件读取) #[serde(default)] - pub person_rules: Option, -} - -/// 分类元数据(v3 分离到 categories 字段) -#[derive(Debug, Clone, Deserialize)] -pub struct TagCategoryMeta { - #[serde(default)] - pub label: Option, - #[serde(default)] - pub color_bg: Option, - #[serde(default)] - pub color_fg: Option, -} - -/// 人物规则定义 -#[derive(Debug, Clone, Deserialize)] -pub struct PersonRulesDef { - #[serde(default)] - pub prefixes: Vec, - #[serde(default)] - pub excluded: Vec, - #[serde(default)] - pub include: Vec, + pub person_prefixes: Vec, } // ── 运行时词典结构 ── -/// 分类信息 +/// 分类信息(运行时使用,兼容旧版 API) #[derive(Debug, Clone)] pub struct CategoryInfo { pub name: String, @@ -75,9 +68,9 @@ pub struct CategoryInfo { /// 运行时标签词典 #[derive(Debug, Clone)] pub struct TagDict { - /// 分类名称 → 分类详情 + /// 分类名称 → 分类详情(兼容旧版 API) pub categories: HashMap, - /// 标签 → 分类名称(查找加速) + /// 标签 → 分类名称(兼容旧版 API,基于 keymap 构建) pub tag_to_category: HashMap, /// 停用词集合 pub stop_words: HashSet, @@ -87,6 +80,11 @@ pub struct TagDict { pub excluded_person_names: HashSet, /// 强制包含的人物名(已知模特/演员名,只要出现就优先识别为人名) pub included_person_names: HashSet, + // ── v4 新字段 ── + /// 扁平化匹配串 → 分类名(v4 keymap) + pub keymap: HashMap, + /// 分类元数据(v4 metadata) + pub metadata: HashMap, } impl Default for TagDict { @@ -98,6 +96,8 @@ impl Default for TagDict { person_prefixes: Vec::new(), excluded_person_names: HashSet::new(), included_person_names: HashSet::new(), + keymap: HashMap::new(), + metadata: HashMap::new(), }; dict.fill_builtin(); dict @@ -133,55 +133,76 @@ impl TagDict { } }; - let (person_prefixes, excluded_person_names, included_person_names) = match file.person_rules { - Some(rules) => ( - rules.prefixes, - rules.excluded.into_iter().collect(), - rules.include.into_iter().collect(), - ), - None => (Vec::new(), HashSet::new(), HashSet::new()), - }; + // ── 人物前缀直接从顶层字段读取 ── + let person_prefixes = file.person_prefixes.clone(); let mut dict = TagDict { categories: HashMap::new(), tag_to_category: HashMap::new(), stop_words: file.stop_words.into_iter().collect(), person_prefixes, - excluded_person_names, - included_person_names, + excluded_person_names: HashSet::new(), + included_person_names: HashSet::new(), + keymap: HashMap::new(), + metadata: HashMap::new(), }; - // ── 解析分类元数据(v3 从 categories 字段读取) ── - for (cat_name, meta) in &file.categories { - let label = meta.label.clone().unwrap_or_else(|| cat_name.clone()); - let color_bg = meta.color_bg.clone().unwrap_or_else(|| "#f1f5f9".to_string()); - let color_fg = meta.color_fg.clone().unwrap_or_else(|| "#64748b".to_string()); + // ── 加载 metadata(分类元数据) ── + dict.metadata = file.metadata.clone(); - let words = file.tags.get(cat_name).cloned().unwrap_or_default(); - for word in &words { - dict.tag_to_category.insert(word.to_lowercase(), cat_name.clone()); - } + // ── 加载 keymap(扁平化匹配串→分类名) ── + dict.keymap = file.keymap.clone(); + // ── 构建 tag_to_category(基于 keymap) ── + for (word, cat_name) in &file.keymap { + dict.tag_to_category.insert(word.to_lowercase(), cat_name.clone()); + } + + // ── 构建 categories(基于 metadata + keymap 提取 words) ── + // 从 keymap 中按分类收集所有词 + let mut words_by_cat: HashMap> = HashMap::new(); + for (word, cat_name) in &file.keymap { + words_by_cat.entry(cat_name.clone()) + .or_default() + .push(word.clone()); + } + + // 按 metadata 中的分类顺序构建 + for (cat_name, meta) in &file.metadata { + let words = words_by_cat.remove(cat_name).unwrap_or_default(); dict.categories.insert(cat_name.clone(), CategoryInfo { name: cat_name.clone(), - label, - color_bg, - color_fg, + label: meta.label.clone(), + color_bg: meta.color_bg.clone(), + color_fg: meta.color_fg.clone(), + words, + }); + } + // keymap 中有但 metadata 中没有的分类(兜底) + for (cat_name, words) in words_by_cat { + dict.categories.insert(cat_name.clone(), CategoryInfo { + name: cat_name.clone(), + label: cat_name.clone(), + color_bg: "#f1f5f9".to_string(), + color_fg: "#64748b".to_string(), words, }); } - // ── 标签词汇自动加入排除人名 ── - // 所有 tags 中的词汇,都自动被视为非人名 - for words in file.tags.values() { - for word in words { + // ── 从 keymap 构建排除人名和包含人名 ── + // person 类型的 key 加入 included_person_names + // 其他类型(style/outfit/scene/body/mood/topic/position/location/brand)加入 excluded_person_names + for (word, cat_name) in &file.keymap { + if cat_name == "person" { + dict.included_person_names.insert(word.to_lowercase()); + } else { dict.excluded_person_names.insert(word.to_lowercase()); } } if !path.as_os_str().is_empty() { - println!("[词典] v{} 已加载: {} 分类, {} 标签词, {} 停用词, {} 前缀, 排除+标签共 {} 词", - file.version, dict.categories.len(), dict.tag_to_category.len(), + println!("[词典] v{} 已加载: {} 分类, {} 标签词(keymap), {} 停用词, {} 前缀, 排除+标签共 {} 词", + file.version, dict.categories.len(), dict.keymap.len(), dict.stop_words.len(), dict.person_prefixes.len(), dict.excluded_person_names.len()); } @@ -193,7 +214,7 @@ impl TagDict { *self = Self::load(); } - /// 获取所有分类名称(固定顺序) + /// 获取所有分类名称(固定顺序:9 个标准分类优先) pub fn get_category_order(&self) -> Vec<&str> { let preferred = ["style", "outfit", "scene", "body", "mood", "topic", "position", "location", "brand"]; let mut result: Vec<&str> = preferred.iter() @@ -228,11 +249,21 @@ impl TagDict { } } - /// 判断一个词属于哪个已知分类 + /// 判断一个词属于哪个已知分类(基于 tag_to_category,由 keymap 构建) pub fn classify(&self, word: &str) -> Option<&str> { self.tag_to_category.get(&word.to_lowercase()).map(|s| s.as_str()) } + /// 在 keymap 中查找 word,返回分类名(与 classify 相同,v4 新增 API) + pub fn match_keymap(&self, word: &str) -> Option<&str> { + self.keymap.get(&word.to_lowercase()).map(|s| s.as_str()) + } + + /// 获取 v4 元数据 + pub fn get_metadata(&self) -> &HashMap { + &self.metadata + } + /// 判断是否是停用词 pub fn is_stop_word(&self, word: &str) -> bool { self.stop_words.contains(&word.to_lowercase()) @@ -267,8 +298,6 @@ impl TagDict { return true; } } - // 反向包含:person_name 包含在排除名中(如排除 "秀人",人名 "秀人网") - // 实际上上面的 contains 已经覆盖了 false } @@ -314,47 +343,112 @@ impl TagDict { /// 内置回退 fn fill_builtin(&mut self) { - let builtin = vec![ - ("style", "风格", "#f0f9ff", "#0284c7", vec![ - "日系", "韩系", "复古", "甜美", "性感", "清新", "冷艳", - "优雅", "知性", "可爱", "俏皮", "温柔", - "时尚", "文艺", "古典", - ]), - ("outfit", "服装", "#fdf2f8", "#db2777", vec![ - "比基尼", "泳装", "旗袍", "制服", "丝袜", "内衣", - "连衣裙", "短裙", "长裙", "牛仔裤", "热裤", - "吊带", "抹胸", "蕾丝", "镂空", - "高跟鞋", - ]), - ("scene", "场景", "#f0fdf4", "#15803d", vec![ - "室内", "户外", "浴室", "床上", - "海边", "沙滩", "泳池", "花园", - ]), - ("body", "身体", "#fef3c7", "#b45309", vec![ - "美腿", "美胸", "翘臀", "玉足", "美背", "香肩", - ]), - ("mood", "情绪", "#faf5ff", "#7c3aed", vec![ - "清纯", "诱惑", "唯美", "清新", "冷艳", "妩媚", - ]), - ("topic", "主题", "#f0f9ff", "#0369a1", vec![ - "写真", "私房", "街拍", "旅拍", "婚纱照", - ]), - ("position", "姿势", "#fefce8", "#a16207", vec![ - "站立", "坐姿", "躺姿", "跪姿", "侧卧", - ]), - ("location", "地点", "#f0fdfa", "#0f766e", vec![ - "日本", "韩国", "中国", "泰国", - "东京", "首尔", "北京", "上海", - "japan", "korea", "china", - ]), - ("brand", "品牌", "#fff7ed", "#c2410c", vec![ - "Victoria's Secret", "维密", - "Calvin Klein", "CK", - "Gucci", "Chanel", - "Louis Vuitton", - ]), + // ── 元数据(与 v4 JSON metadata 同构) ── + let builtin_metadata: Vec<( &str, &str, &str, &str)> = vec![ + ("style", "风格", "#f0f9ff", "#0284c7"), + ("outfit", "服装", "#fdf2f8", "#db2777"), + ("scene", "场景", "#f0fdf4", "#15803d"), + ("body", "身体", "#fef3c7", "#b45309"), + ("mood", "情绪", "#faf5ff", "#7c3aed"), + ("topic", "主题", "#f0f9ff", "#0369a1"), + ("position", "姿势", "#fefce8", "#a16207"), + ("location", "地点", "#f0fdfa", "#0f766e"), + ("brand", "品牌", "#fff7ed", "#c2410c"), ]; + for (name, label, bg, fg) in &builtin_metadata { + self.metadata.insert(name.to_string(), CategoryMeta { + label: label.to_string(), + color_bg: bg.to_string(), + color_fg: fg.to_string(), + }); + } + + // ── keymap ── + let builtin_keymap: Vec<(&str, &str)> = vec![ + // style + ("日系", "style"), ("韩系", "style"), ("复古", "style"), + ("甜美", "style"), ("性感", "style"), ("清新", "style"), + ("冷艳", "style"), ("优雅", "style"), ("知性", "style"), + ("可爱", "style"), ("俏皮", "style"), ("温柔", "style"), + ("时尚", "style"), ("文艺", "style"), ("古典", "style"), + ("elegant", "style"), ("fashion", "style"), ("japanese", "style"), + ("korean", "style"), ("retro", "style"), ("sexy", "style"), + ("vintage", "style"), + // outfit + ("比基尼", "outfit"), ("泳装", "outfit"), ("旗袍", "outfit"), + ("制服", "outfit"), ("丝袜", "outfit"), ("内衣", "outfit"), + ("连衣裙", "outfit"), ("短裙", "outfit"), ("长裙", "outfit"), + ("牛仔裤", "outfit"), ("热裤", "outfit"), ("吊带", "outfit"), + ("抹胸", "outfit"), ("蕾丝", "outfit"), ("镂空", "outfit"), + ("高跟鞋", "outfit"), ("T恤", "outfit"), + // scene + ("室内", "scene"), ("户外", "scene"), ("浴室", "scene"), + ("床上", "scene"), ("海边", "scene"), ("沙滩", "scene"), + ("泳池", "scene"), ("花园", "scene"), + // body + ("美腿", "body"), ("美胸", "body"), ("翘臀", "body"), + ("玉足", "body"), ("美背", "body"), ("香肩", "body"), + ("ass", "body"), ("back", "body"), ("breasts", "body"), + ("feet", "body"), ("legs", "body"), ("shoulders", "body"), + ("skin", "body"), ("tattoo", "body"), ("waist", "body"), + // mood + ("清纯", "mood"), ("诱惑", "mood"), ("唯美", "mood"), + ("妩媚", "mood"), ("beautiful", "mood"), ("charming", "mood"), + ("cool", "mood"), ("cute", "mood"), ("fresh", "mood"), + ("gentle", "mood"), ("lazy", "mood"), ("pure", "mood"), + ("seductive", "mood"), ("shy", "mood"), ("sweet", "mood"), + ("wild", "mood"), + // topic + ("写真", "topic"), ("私房", "topic"), ("街拍", "topic"), + ("旅拍", "topic"), ("婚纱照", "topic"), + ("cosplay", "topic"), ("photoshoot", "topic"), + ("portrait", "topic"), ("selfie", "topic"), ("travel", "topic"), + ("wedding", "topic"), + // position + ("站立", "position"), ("坐姿", "position"), ("躺姿", "position"), + ("跪姿", "position"), ("侧卧", "position"), + ("kneeling", "position"), ("lying", "position"), + ("sitting", "position"), ("standing", "position"), + // location + ("日本", "location"), ("韩国", "location"), ("中国", "location"), + ("泰国", "location"), ("东京", "location"), ("首尔", "location"), + ("北京", "location"), ("上海", "location"), + ("japan", "location"), ("korea", "location"), ("china", "location"), + ("bali", "location"), ("bangkok", "location"), + ("phuket", "location"), ("seoul", "location"), + ("thailand", "location"), ("tokyo", "location"), + // brand + ("Victoria's Secret", "brand"), ("维密", "brand"), + ("Calvin Klein", "brand"), ("CK", "brand"), + ("Gucci", "brand"), ("Chanel", "brand"), + ("Louis Vuitton", "brand"), + ]; + + for (word, cat) in &builtin_keymap { + self.keymap.insert(word.to_string(), cat.to_string()); + self.tag_to_category.insert(word.to_lowercase(), cat.to_string()); + } + + // ── categories(基于 metadata + keymap 派生) ── + let mut words_by_cat: HashMap> = HashMap::new(); + for (word, cat_name) in &self.keymap { + words_by_cat.entry(cat_name.clone()) + .or_default() + .push(word.clone()); + } + for (name, meta) in &self.metadata { + let words = words_by_cat.remove(name).unwrap_or_default(); + self.categories.insert(name.clone(), CategoryInfo { + name: name.clone(), + label: meta.label.clone(), + color_bg: meta.color_bg.clone(), + color_fg: meta.color_fg.clone(), + words, + }); + } + + // ── 停用词 ── let stop_words: Vec<&str> = vec![ "photos", "photo", "pictures", "picture", "images", "image", "video", "videos", "cosplay", "cos", @@ -367,43 +461,40 @@ impl TagDict { "美女", "模特", "高清", "原版", "无水印", "番号", "编号", ]; + for w in &stop_words { self.stop_words.insert(w.to_string()); } + // ── 人物前缀 ── let person_prefixes: Vec<&str> = vec![ "美女模特", "性感女神", "清纯美女", "气质美女", "可爱女孩", "甜美少女", "时尚达人", "女神", "美女", "模特", "小姐姐", "小仙女", "御姐", "萝莉", "辣妹", "潮人", ]; + self.person_prefixes = person_prefixes.iter().map(|s| s.to_string()).collect(); - let excluded: Vec<&str> = vec![ + // ── 排除人名(从 keymap 非 person 类型派生)── + for (word, cat) in &builtin_keymap { + if cat == &"person" { + self.included_person_names.insert(word.to_lowercase()); + } else { + self.excluded_person_names.insert(word.to_lowercase()); + } + } + // 额外内置排除(keymap 中未覆盖的工作室名) + let extra_excluded: Vec<&str> = vec![ "XiuRen", "xiuren", "秀人", "秀人网", "MFStar", "MiiTao", "蜜桃社", "YouMi", "尤蜜", "HuaYang", "花洋", "FeiLin", "Feiling", "飞灵", "MFModel", "LeiLei", "Tristana", "Av", ]; + for n in &extra_excluded { self.excluded_person_names.insert(n.to_string()); } - let included: Vec<&str> = vec![ + // ── 包含人名(从 keymap person 类型已派生,再加几个默认) ── + let default_included: Vec<&str> = vec![ "杨晨晨", "水淼", "轩美宣", "王馨瑶", "雪儿", "曼曼", "佳佳", "小乔", ]; - - for w in &stop_words { self.stop_words.insert(w.to_string()); } - self.person_prefixes = person_prefixes.iter().map(|s| s.to_string()).collect(); - for n in &excluded { self.excluded_person_names.insert(n.to_string()); } - for n in &included { self.included_person_names.insert(n.to_string()); } - - for (name, label, bg, fg, words) in builtin { - let ws: Vec = words.iter().map(|w| w.to_string()).collect(); - for w in &ws { - self.tag_to_category.insert(w.to_lowercase(), name.to_string()); - // 标签词自动加入排除人名 - self.excluded_person_names.insert(w.to_lowercase()); - } - self.categories.insert(name.to_string(), CategoryInfo { - name: name.to_string(), label: label.to_string(), - color_bg: bg.to_string(), color_fg: fg.to_string(), words: ws, - }); - } + for n in &default_included { self.included_person_names.insert(n.to_string()); } } } @@ -423,8 +514,8 @@ pub fn reload_tag_dict() -> String { let mut dict = TAG_DICT.write().expect("tag_dict 锁被污染"); dict.reload(); format!( - "词典已重载: {} 分类, {} 标签, {} 停用词, {} 前缀, {} 排除人名, {} 包含人名", - dict.categories.len(), dict.tag_to_category.len(), + "词典已重载: {} 分类, {} 标签(keymap), {} 停用词, {} 前缀, {} 排除人名, {} 包含人名", + dict.categories.len(), dict.keymap.len(), dict.stop_words.len(), dict.person_prefixes.len(), dict.excluded_person_names.len(), dict.included_person_names.len(), ) @@ -434,8 +525,8 @@ pub fn reload_tag_dict() -> String { pub fn get_tag_dict_stats() -> String { let dict = get_tag_dict(); format!( - "标签词典: {} 分类, {} 标签, {} 停用词, {} 前缀, {} 排除人名, {} 包含人名 | 文件: dict/tags.json", - dict.categories.len(), dict.tag_to_category.len(), + "标签词典: {} 分类, {} 标签(keymap), {} 停用词, {} 前缀, {} 排除人名, {} 包含人名 | 文件: dict/tags.json", + dict.categories.len(), dict.keymap.len(), dict.stop_words.len(), dict.person_prefixes.len(), dict.excluded_person_names.len(), dict.included_person_names.len(), ) diff --git a/src/engine/tag_extractor.rs b/src/engine/tag_extractor.rs index e7ecb77..1294fec 100644 --- a/src/engine/tag_extractor.rs +++ b/src/engine/tag_extractor.rs @@ -1,10 +1,10 @@ //! 标签提取器 — 从标题中提取分类明确的标签 //! -//! 标签分类体系(外部词典 dict/tags.json 定义): -//! style outfit scene body mood topic position location brand +//! 标签分类体系(外部词典 dict/tags.json v4 定义): +//! style outfit scene body mood topic position location brand person //! -//! 核心设计:不直接调用 JIEBA,jieba 标签由外部(title_parser::parse_album_title) -//! 传入,避免重复分词。Tag extractor 只做:词典匹配 + jieba 结果过滤 + 正则兜底。 +//! 核心设计:纯词典 keymap substring 匹配 + 正则兜底,无 jieba 依赖。 +//! Person 类型由 title_parser 单独处理,此处不纳入标签。 use regex::Regex; use lazy_static::lazy_static; @@ -12,9 +12,9 @@ use std::collections::HashSet; use crate::engine::tag_dict; lazy_static! { + /// 匹配英文单词、数字、中文字符(用于正则兜底分词) static ref WORD_RE: Regex = Regex::new(r"[a-zA-Z0-9\u{4e00}-\u{9fff}]+").unwrap(); - static ref HAS_CHINESE: Regex = Regex::new(r"[\u{4e00}-\u{9fff}]").unwrap(); - /// 提取标签中的有效部分(去头尾标点) + /// 去除头尾标点符号 static ref TAG_CORE_RE: Regex = Regex::new( r#"^[\s.,;:!?'\"‘’“”\-–—()\[\]{}【】《》〈〉、,。;:?!…~·•]+|[\s.,;:!?'\"‘’“”\-–—()\[\]{}【】《》〈〉、,。;:?!…~·•]+$"# ).unwrap(); @@ -31,8 +31,8 @@ pub fn is_punctuation_only(s: &str) -> bool { }) } -/// 清洗单个标签:去除头尾标点符号 -/// 清洗后如果只剩下标点或为空,则返回 None +/// 清洗单个标签:去除头尾标点符号。 +/// 清洗后如果只剩下标点或为空,则返回 None。 pub fn clean_tag(tag: &str) -> Option { let cleaned = TAG_CORE_RE.replace_all(tag.trim(), "").trim().to_string(); if cleaned.is_empty() || is_punctuation_only(&cleaned) || cleaned.len() < 2 { @@ -42,18 +42,15 @@ pub fn clean_tag(tag: &str) -> Option { } } -/// 获取分类优先级索引(从词典动态获取) +/// 获取分类优先级索引(从词典动态获取)。 fn category_order_index(category: &str) -> usize { let dict = tag_dict::get_tag_dict(); let order = dict.get_category_order(); order.iter().position(|c| c == &category).unwrap_or(999) } -// ═══════════════════════════════════════════════════════ -// 标签分类(非 jieba) -// ═══════════════════════════════════════════════════════ - -/// 判断一个词属于哪个分类(在词典中查找) +/// 判断一个词属于哪个分类(在词典 keymap 中查找)。 +/// 如果在 keymap 中找不到,返回 "other"。 pub fn classify_tag(word: &str) -> String { let dict = tag_dict::get_tag_dict(); dict.classify(word) @@ -61,23 +58,29 @@ pub fn classify_tag(word: &str) -> String { .unwrap_or_else(|| "other".to_string()) } -/// 获取标签的中文分类名 +/// 获取标签的中文分类名。 pub fn get_category_label(category: &str) -> String { tag_dict::get_tag_dict().get_category_label(category) } -/// 获取标签分类的颜色 +/// 获取标签分类的颜色 (bg, fg)。 pub fn get_category_color(category: &str) -> (String, String) { tag_dict::get_tag_dict().get_category_color(category) } // ═══════════════════════════════════════════════════════ -// 步骤 A:词典标签匹配(substring,无 jieba) +// 词典 keymap substring 匹配(最长匹配优先) // ═══════════════════════════════════════════════════════ -/// 步骤 A — 从标题中通过词典 substring 匹配提取分类标签。 -/// 已被已有标签(seen)或人名命中的词不再重复匹配。 -/// 不调用 jieba。 +/// 从标题中通过词典 keymap substring 匹配提取分类标签,**最长匹配优先**。 +/// +/// 策略: +/// 1. 先从 `title_lower` 中移除 `person_name` 中的词(防止人名命中标签) +/// 2. keymap 中所有标签按长度降序排列(最长的先匹配) +/// 3. 匹配到某个标签后,将该标签从 `title_lower` 中**替换为空格**, +/// 防止其子串/短标签再次命中,实现最长匹配覆盖 +/// 4. 跳过已被 `seen` 包含的词 +/// 5. 跳过 `person` 类型的标签(由 title_parser 处理) pub fn extract_dict_tags( title: &str, person_name: &[String], @@ -96,77 +99,37 @@ pub fn extract_dict_tags( let mut sorted: Vec<(String, String)> = tag_category_map.iter() .map(|(k, v)| (k.clone(), v.clone())) .collect(); + // 长度降序排列:保证最长匹配优先 sorted.sort_by(|a, b| b.0.len().cmp(&a.0.len())); for (tag, category) in &sorted { - if title_lower.contains(tag.as_str()) && !seen.contains(tag) { - seen.insert(tag.clone()); - tags.push((tag.clone(), category.clone())); - } + // 跳过 person 类型(由 title_parser 单独处理) + if category == "person" { continue; } + if seen.contains(tag) { continue; } + if !title_lower.contains(tag.as_str()) { continue; } + + seen.insert(tag.clone()); + tags.push((tag.clone(), category.clone())); + + // 将匹配到的长标签从标题中移除(替换为空格), + // 避免其子串/短标签再次命中,实现最长匹配覆盖 + title_lower = title_lower.replace(tag.as_str(), " "); } tags } // ═══════════════════════════════════════════════════════ -// 步骤 B:jieba 名词标签提取(依赖外部 jieba result) +// 正则兜底标签提取 // ═══════════════════════════════════════════════════════ -/// 步骤 B — 从 jieba 分词结果中提取名词标签。 -/// 已被 seen 中的词跳过。不重复调用 JIEBA。 -pub fn extract_jieba_noun_tags( - jieba_tags: &[jieba_rs::Tag], - person_name: &[String], - stop_words: &HashSet, - seen: &mut HashSet, -) -> Vec<(String, String)> { - let mut tags = Vec::new(); - - for tag in jieba_tags { - let word = tag.word.trim(); - if word.len() < 2 { continue; } - let word_lower = word.to_lowercase(); - - if is_punctuation_only(word) { continue; } - if word.chars().all(|c| c.is_ascii_digit()) { continue; } - if stop_words.contains(&word_lower) { continue; } - if seen.contains(&word_lower) { continue; } - - // 排除人名 - if person_name.iter().any(|p| word_lower.contains(&p.to_lowercase())) { - continue; - } - - let pos = tag.tag; - let category = match pos { - "n" | "ng" => "noun", - "nz" => "proper", - "ns" => "location", - "eng" => "other", - "x" => "other", - "nr" | "nrfg" | "nrt" => continue, // 人名(已单独提取) - "nt" | "vn" | "a" | "ad" | "an" - | "v" | "vd" | "vg" - | "m" | "mq" | "q" | "qv" | "qt" - | "r" | "rr" | "rz" - | "c" | "p" - | "u" | "ul" | "uv" | "ud" | "ug" | "uj" - | "d" | "e" | "y" | "o" | "w" - | "t" | "tg" | "s" | "f" - | "b" | "bl" | "z" => continue, - _ => continue, - }; - - seen.insert(word_lower); - tags.push((word.to_string(), category.to_string())); - } - tags -} - -// ═══════════════════════════════════════════════════════ -// 步骤 C:正则兜底标签(无 jieba) -// ═══════════════════════════════════════════════════════ - -/// 步骤 C — 正则分词提取剩余关键词(兜底)。不调 jieba。 +/// 正则分词提取剩余关键词(兜底),全部归为 "other" 类。 +/// +/// 过滤规则: +/// - 长度 < 2、纯标点、纯数字 → 跳过 +/// - 停用词 → 跳过 +/// - 已被 `seen` 包含的词 → 跳过 +/// - 人名 → 跳过 +/// - 已在 keymap 中分类过的词 → 跳过(避免重复) pub fn extract_regex_tags( title: &str, person_name: &[String], @@ -186,7 +149,7 @@ pub fn extract_regex_tags( if stop_words.contains(&word_lower) { continue; } if seen.contains(&word_lower) { continue; } - // 排除人名 + // 排除人名相关部分 if person_name.iter().any(|p| word_lower.contains(&p.to_lowercase())) { continue; } @@ -202,21 +165,33 @@ pub fn extract_regex_tags( } // ═══════════════════════════════════════════════════════ -// extract_tags_from_title(保持对外兼容,内部调 A+B+C) +// extract_tags_from_title(完整流程:词典匹配 → 正则兜底) // ═══════════════════════════════════════════════════════ /// 从标题中提取分类标签(完整流程)。 /// -/// 三部曲:词典匹配 → jieba 名词提取 → 正则兜底。 -/// jieba 部分使用外部传入的 jieba result,避免重复分词。 +/// 两步流程: +/// 1. **词典 keymap substring 匹配** — 在 `title_lower` 中搜索所有 keymap 中的 key, +/// 最长匹配优先,匹配后从标题中移除已匹配文本,避免短标签重复命中。 +/// 跳过 person 类型标签。 +/// 2. **正则兜底** — 用 WORD_RE 提取剩余单词,归为 "other" 类。 +/// +/// 过滤规则: +/// - 跳过停用词 +/// - 跳过 person 类型(由 title_parser 处理) +/// - 跳过人名部分 +/// +/// # 参数 +/// - `title` — 原始标题 +/// - `person_name` — 已提取的人名(可选),用于从标题中排除,防止命中标签 pub fn extract_tags_from_title( title: &str, person_name: Option<&str>, - jieba_tags: &[jieba_rs::Tag], ) -> Vec<(String, String)> { let dict = tag_dict::get_tag_dict(); let stop_words = dict.get_stop_words(); + // 构建人名排除列表:人名本身 + 按空白切分的各部分 let person_exclude: Vec = person_name .map(|n| { let mut v = vec![n.to_lowercase()]; @@ -228,22 +203,50 @@ pub fn extract_tags_from_title( .unwrap_or_default(); let mut seen = HashSet::new(); - let mut tags = Vec::new(); - // A: 词典匹配 + // Step 1: 词典 keymap substring 匹配(最长匹配优先) tags.extend(extract_dict_tags(title, &person_exclude, &mut seen)); - // B: jieba 名词(用外部传入的 jieba result) - tags.extend(extract_jieba_noun_tags(jieba_tags, &person_exclude, stop_words, &mut seen)); - - // C: 正则兜底 + // Step 2: 正则兜底(剩余未匹配的词,归 "other" 类) tags.extend(extract_regex_tags(title, &person_exclude, stop_words, &mut seen)); tags } -/// 标签去重并排序(分类标签优先) +/// 纯 keymap substring 匹配(无正则兜底),用于快速标签提取。 +/// +/// 只做词典匹配,不做正则兜底。适合在不需要"其他"类标签的场景下使用。 +/// +/// # 参数 +/// - `title` — 原始标题 +/// - `person_name` — 已提取的人名(可选),用于从标题中排除人名部分 +pub fn extract_tags_with_keymap(title: &str, person_name: Option<&str>) -> Vec<(String, String)> { + let person_exclude: Vec = person_name + .map(|n| { + let mut v = vec![n.to_lowercase()]; + for part in n.split_whitespace() { + v.push(part.to_lowercase()); + } + v + }) + .unwrap_or_default(); + + let mut seen = HashSet::new(); + extract_dict_tags(title, &person_exclude, &mut seen) +} + +// ═══════════════════════════════════════════════════════ +// 标签去重、排序、过滤 +// ═══════════════════════════════════════════════════════ + +/// 标签去重并排序(分类标签优先,按词典中的 category_order 排序)。 +/// +/// 去重逻辑: +/// 1. 先按分类优先级排序(style < outfit < scene < ... < other) +/// 2. 逐个清洗标签(去头尾标点) +/// 3. 过滤坏标签(纯数字、纯标点、停用词等) +/// 4. 小写去重 pub fn unique_tags(tags: Vec<(String, String)>) -> Vec<(String, String)> { let mut seen = HashSet::new(); let mut result = Vec::new(); @@ -269,7 +272,14 @@ pub fn unique_tags(tags: Vec<(String, String)>) -> Vec<(String, String)> { result } -/// 判断一个标签是否"坏标签" +/// 判断一个标签是否"坏标签"(应被过滤掉)。 +/// +/// 规则: +/// - 空串或长度 < 2 +/// - 纯数字 +/// - 纯标点符号 +/// - clean_tag 后变短(说明含不可见标点) +/// - 停用词 pub fn is_bad_tag(tag: &str) -> bool { let tag = tag.trim(); if tag.is_empty() || tag.len() < 2 { return true; } @@ -289,23 +299,40 @@ mod tests { #[test] fn test_extract_tags() { + // 杨晨晨Yome 是 person 类型,由 title_parser 处理,不应出现在标签中 + // photos 是停用词,不应出现在标签中 let tags = extract_tags_from_title( "XiuRen秀人网 – 杨晨晨Yome – Night Dress '81 photos'", Some("杨晨晨Yome"), - &[], ); let names: Vec<&str> = tags.iter().map(|(t, _)| t.as_str()).collect(); - assert!(!names.contains(&"photos")); - assert!(!names.contains(&"杨晨晨")); + assert!(!names.contains(&"photos"), "tags 不应包含停用词 'photos'"); + assert!(!names.contains(&"杨晨晨"), "tags 不应包含 person 类型词 '杨晨晨'"); + // 验证 keymap 中的词正确匹配 + assert!(names.contains(&"dress"), "tags 应包含 keymap 中的 'dress'"); + } + + #[test] + fn test_longest_match_priority() { + // "连衣裙" (3字) 在内建词典 outfit 中。标题包含 "连衣裙", + // 匹配后无子串可再匹配。 + let tags = extract_tags_from_title( + "粉色连衣裙 2025", + None, + ); + let names: Vec<&str> = tags.iter().map(|(t, _)| t.as_str()).collect(); + assert!(names.contains(&"连衣裙"), "'连衣裙' 应在内建词典的结果中"); + // "连衣裙" 被移除后,其子串不会再次匹配 + assert_eq!(names.iter().filter(|t| **t == "连衣裙").count(), 1); } #[test] fn test_classify_tag() { + // v4 JSON keymap 中 "日系":"style" assert_eq!(classify_tag("日系"), "style"); assert_eq!(classify_tag("比基尼"), "outfit"); assert_eq!(classify_tag("浴室"), "scene"); assert_eq!(classify_tag("美腿"), "body"); - assert_eq!(classify_tag("清纯"), "mood"); assert_eq!(classify_tag("写真"), "topic"); assert_eq!(classify_tag("unknown"), "other"); } @@ -316,4 +343,31 @@ mod tests { assert_eq!(bg, "#f0f9ff"); assert_eq!(fg, "#0284c7"); } + + #[test] + fn test_extract_tags_with_keymap() { + // 纯 keymap 匹配,不包含正则兜底的词 + let tags = extract_tags_with_keymap( + "日系 比基尼 甜美 沙滩 2025", + None, + ); + let names: Vec<&str> = tags.iter().map(|(t, _)| t.as_str()).collect(); + assert!(names.contains(&"日系"), "日系 应在 keymap 匹配结果中"); + assert!(names.contains(&"比基尼"), "比基尼 应在 keymap 匹配结果中"); + assert!(names.contains(&"沙滩"), "沙滩 应在 keymap 匹配结果中"); + // "2025" 不在 keymap 中,不应出现(纯 keymap 无正则兜底) + assert!(!names.contains(&"2025"), "纯 keymap 匹配不应包含 '2025'"); + } + + #[test] + fn test_person_type_excluded_from_dict() { + // 杨晨晨 在 v4 keymap 中是 person 类型,不应被提取为标签 + let tags = extract_tags_with_keymap( + "杨晨晨 日系 比基尼", + None, + ); + let names: Vec<&str> = tags.iter().map(|(t, _)| t.as_str()).collect(); + assert!(!names.contains(&"杨晨晨"), "person 类型的 '杨晨晨' 不应出现在标签中"); + assert!(names.contains(&"日系"), "非 person 类型词应正常匹配"); + } } diff --git a/src/engine/title_parser.rs b/src/engine/title_parser.rs index 96078eb..a414bce 100644 --- a/src/engine/title_parser.rs +++ b/src/engine/title_parser.rs @@ -1,704 +1,35 @@ //! 标题解析、人名提取、标签提取 -//! 对应 Python 的 tag_index.py + clean_person_names.py 的核心逻辑 +//! +//! v4 版本 — 基于 keymap 的纯匹配方案,无 jieba 依赖。 +//! 核心流程:预处理 → token 分割 → 对每个 token 依次检查: +//! keymap(person) → 人物 +//! keymap(其他) → 标签 +//! stopwords → 跳过 +//! 人名启发式 → 人物 use regex::Regex; use std::collections::HashSet; use lazy_static::lazy_static; -use jieba_rs::Jieba; use crate::engine::tag_dict; use crate::engine::tag_extractor; -// 全局 jieba 分词器 -lazy_static! { - static ref JIEBA: Jieba = Jieba::new(); -} - -// ── 常量(仅保留正则相关常量,人物规则从 tag_dict 动态读取)── - -/// 保留词性(仅用于 jieba 分词场景,这里做占位符) -const _KEEP_POS: &[&str] = &["n", "nr", "ns", "nz", "v", "vn", "a", "an", "eng", "x"]; +// ── 正则 ── lazy_static! { - /// 编译后的正则 - static ref RE_COSPLAY: Regex = Regex::new( - r"(?i)^(.+?)\s+cos(play)?\s+(.+?)(?:\s*[–—\-]\s*(.+))?$" - ).unwrap(); - static ref RE_COSPLAY_BY: Regex = Regex::new( - r"(?i)^(.+?)\s+cos(play)?\s+by\s+(.+?)(?:\s*[–—\-]\s*(.+))?$" - ).unwrap(); static ref RE_BRACKET_PREFIX: Regex = Regex::new(r"^\[([^\]]+)\]\s*").unwrap(); static ref RE_NUMBER_SUFFIX: Regex = Regex::new(r"[\s#]*(?:no\.?\s*|vol\.?\s*|#)?\d+[\s]*$").unwrap(); static ref RE_PAREN_CONTENT: Regex = Regex::new(r"[((]([^))]*)[))]").unwrap(); - static ref RE_SPLIT_DASH: Regex = Regex::new(r"\s*[–—\-]\s*").unwrap(); static ref RE_PHOTOS_SUFFIX: Regex = Regex::new(r"(?i)\s*\d+\s*photos?\s*(?:and\s*\d+\s*videos?)?\s*$").unwrap(); static ref RE_CHINESE: Regex = Regex::new(r"[\u{4e00}-\u{9fff}]").unwrap(); static ref RE_ENGLISH_SUFFIX: Regex = Regex::new(r"^([\u{4e00}-\u{9fff}]+)([A-Za-z].*)$").unwrap(); static ref RE_TRAILING_PUNCT: Regex = Regex::new(r"[\s.,;:,。;:\-–—]+$").unwrap(); - /// 人名模式:2-5个中文字符(纯中文,不混杂英文) - /// 中英文混杂的情况由 split_person_name_with_aliases 处理为 主名+别名 - static ref RE_CN_NAME: Regex = Regex::new( - r"([\u{4e00}-\u{9fff}]{2,5})" - ).unwrap(); - /// 纯英文人名模式:2-15个英文字母,首字母可大写 - static ref RE_EN_NAME: Regex = Regex::new( - r"([A-Za-z][A-Za-z]{1,14})" - ).unwrap(); - /// 常见人名后缀(表明前面是人名) - static ref RE_NAME_CONTEXT: Regex = Regex::new( - r"(?i)(私房|写真|内衣|比基尼|泳装|旗袍|制服|街拍|室内|户外|浴室|浴室|浴缸|床上|床照|内衣|透视|包臀裙|紧身裙|超短裙|丝袜|美腿|美臀|美胸|翘臀|性感|清纯|甜美|气质|可爱|女神|嫩模|模特)" - ).unwrap(); - - /// 停用词集合(从 tag_dict 动态获取) - static ref STOP_WORDS_SET: HashSet = { - tag_dict::get_tag_dict().get_stop_words().clone() - }; - - /// 排除名集合(从 tag_dict 动态获取) - static ref EXCLUDED_LOWER: HashSet = { - let dict = tag_dict::get_tag_dict(); - dict.get_excluded_persons().clone() - }; + /// 中文词(2-5字) + static ref RE_CN_WORD: Regex = Regex::new(r"([\u{4e00}-\u{9fff}]{2,5})").unwrap(); + /// 英文词(2-15字母) + static ref RE_EN_WORD: Regex = Regex::new(r"([A-Za-z][A-Za-z]{1,14})").unwrap(); } -// ── 人名提取 ── - -/// 从标题中提取模特/人物名称 -/// 核心策略(按优先级): -/// 1. cosplay 格式匹配(Name cosplay Character) -/// 2. jieba 分词 + 词性标注(优先提取 nr 人名) -/// 3. 清理标题(移除[工作室]、编号、N photos等) -/// 4. 用分隔符(–—-)切分,第一部分常含人名 -/// 5. 扫描匹配"2-5中文+可选英文"模式的词 -/// 6. 结合上下文(后面是否跟"写真/私房/性感"等关键词) -pub fn extract_person_name_from_title(title: &str) -> Option { - let title = title.trim(); - if title.is_empty() { - return None; - } - - // 步骤1: 基础清理 - let mut t = RE_PHOTOS_SUFFIX.replace(title, "").trim().to_string(); - - // 步骤2: cosplay 格式优先匹配 - if let Some(caps) = RE_COSPLAY_BY.captures(&t) { - return Some(clean_name(caps[3].trim())); - } - if let Some(caps) = RE_COSPLAY.captures(&t) { - return Some(clean_name(caps[1].trim())); - } - - // 步骤2.5: jieba 分词 + 词性标注(最高优先级的中文人名提取) - // 只保留词性为 nr(人名)、n(名词)、nz(其它专名) 的词 - if let Some(name) = extract_person_with_jieba(&t) { - return Some(name); - } - - // 步骤3: 移除 [工作室] 前缀 - t = RE_BRACKET_PREFIX.replace(&t, "").trim().to_string(); - - // 步骤4: 移除模特称呼前缀(从词典动态获取) - for prefix in tag_dict::get_tag_dict().get_person_prefixes() { - if t.starts_with(prefix) { - t = t[prefix.len()..].trim().to_string(); - break; - } - } - - // 步骤5: 移除编号后缀 - t = RE_NUMBER_SUFFIX.replace(&t, "").trim().to_string(); - - // 步骤6: 用分隔符切分,检查每一部分 - let parts: Vec<&str> = RE_SPLIT_DASH.split(&t).collect(); - - // 策略A: 检查第一部分(分隔符前的内容最可能包含人名) - if let Some(first) = parts.first() { - if let Some(name) = extract_name_from_segment(first) { - if is_likely_person_name(&name) { - return Some(name); - } - } - } - - // 策略B: 如果第一部分没找到,扫描所有部分 - // 优先选择后面跟有关键词的部分 - for i in 0..parts.len() { - let part = parts[i]; - // 检查这一部分后面是否跟有"写真/私房"等关键词 - let has_context_after = if i + 1 < parts.len() { - RE_NAME_CONTEXT.is_match(parts[i + 1]) - } else { - false - }; - - if let Some(name) = extract_name_from_segment(part) { - if is_likely_person_name(&name) { - if has_context_after { - return Some(name); // 有关键词上下文,优先返回 - } - } - } - } - - // 策略C: 直接在整个标题中搜索人名模式 - // 先搜纯中文(优先级更高) - for cap in RE_CN_NAME.captures_iter(&t) { - let name = clean_name(&cap[1]); - if is_likely_person_name(&name) { - return Some(name); - } - } - - // 再搜纯英文 - for cap in RE_EN_NAME.captures_iter(&t) { - let name = clean_name(&cap[1]); - // 排除停用词 - if STOP_WORDS_SET.contains(&name.to_lowercase()) { continue; } - if is_likely_person_name(&name) { - return Some(name); - } - } - - None -} - -/// 用 jieba 分词提取人名(最高优先级策略) -/// 只保留词性为 nr(人名)、n(名词)、nz(其它专名) 的词 -/// 同时结合二次验证过滤非人名 -fn extract_person_with_jieba(title: &str) -> Option { - // 对标题做词性标注分词(true = 使用 HMM 新词发现) - let tags = JIEBA.tag(title, true); - - // 按优先级收集候选词:nr > nz > n - let mut candidates: Vec<(String, usize)> = Vec::new(); // (词, 优先级) - - for tag in &tags { - let word = tag.word.trim(); - if word.len() < 2 { continue; } - - let priority = match tag.tag { - "nr" => 0, // 人名(最高优先级) - "nrfg" => 1, // 古体人名 - "nrt" => 2, // 音译人名 - "nz" => 3, // 其它专名 - "n" => 4, // 名词 - _ => continue, // 其他词性跳过 - }; - - if is_likely_person_name(word) { - candidates.push((word.to_string(), priority)); - } - } - - // 按优先级排序,取第一个 - candidates.sort_by(|a, b| a.1.cmp(&b.1)); - candidates.into_iter().next().map(|(name, _)| clean_name(&name)) -} - -/// 从一个文本片段中提取人名 -/// 只支持纯中文(2-6字)或纯英文(2-15字),不混杂 -/// 中文优先级更高 -fn extract_name_from_segment(segment: &str) -> Option { - let seg = segment.trim(); - if seg.is_empty() { - return None; - } - - // 判断片段是否纯中文 - let is_pure_cn = seg.chars().all(|c| RE_CHINESE.is_match(&c.to_string())); - // 判断片段是否纯英文 - let is_pure_en = seg.chars().all(|c| c.is_ascii_alphabetic()); - - // 策略1: 纯中文片段(2-6字) - if is_pure_cn && seg.len() >= 2 && seg.len() <= 6 { - // 标签词典中的词不应作为人名 - if !tag_dict::get_tag_dict().classify(seg).is_some() - && !tag_dict::get_tag_dict().classify(&seg.to_lowercase()).is_some() { - return Some(clean_name(seg)); - } - } - - // 策略2: 尝试匹配纯中文人名模式 - if let Some(cap) = RE_CN_NAME.captures(seg) { - let name = clean_name(&cap[1]); - if name.len() >= 2 { - // 标签词典中的词不应作为人名 - if !tag_dict::get_tag_dict().classify(&name).is_some() - && !tag_dict::get_tag_dict().classify(&name.to_lowercase()).is_some() { - return Some(name); - } - } - } - - // 策略3: 纯英文片段(2-15字) - if is_pure_en && seg.len() >= 2 && seg.len() <= 15 { - // 过滤停用词 - if !STOP_WORDS_SET.contains(&seg.to_lowercase()) { - // 标签词典中的词不应作为人名 - if !tag_dict::get_tag_dict().classify(seg).is_some() - && !tag_dict::get_tag_dict().classify(&seg.to_lowercase()).is_some() { - return Some(clean_name(seg)); - } - } - } - - // 策略4: 尝试匹配纯英文人名模式 - if let Some(cap) = RE_EN_NAME.captures(seg) { - let name = clean_name(&cap[1]); - if name.len() >= 2 && !STOP_WORDS_SET.contains(&name.to_lowercase()) { - // 标签词典中的词不应作为人名 - if !tag_dict::get_tag_dict().classify(&name).is_some() - && !tag_dict::get_tag_dict().classify(&name.to_lowercase()).is_some() { - return Some(name); - } - } - } - - None -} - -/// 清理人名:移除前后空白和标点 -fn clean_name(name: &str) -> String { - let name = name.trim(); - // 移除末尾标点 - let name = RE_TRAILING_PUNCT.replace(name, "").trim().to_string(); - name -} - -/// 提取中文核心(开头的连续中文字符) -/// 对应 Python merge_persons_by_core.extract_cn -pub fn extract_cn(name: &str) -> Option { - let re = Regex::new(r"^([\u{4e00}-\u{9fff}]+)").unwrap(); - re.captures(name).map(|c| c[1].to_string()) -} - -/// 判断后缀是否有效(不含中文=有效英文后缀) -/// 对应 Python merge_persons_by_core.is_valid_suffix -pub fn is_valid_suffix(suffix: &str) -> bool { - if suffix.is_empty() { - return true; - } - !RE_CHINESE.is_match(suffix) -} - -/// 判断是否为工作室/平台名(需排除) -pub fn is_excluded_name(name: &str) -> bool { - EXCLUDED_LOWER.contains(&name.to_lowercase()) -} - -/// 二次验证:判断一个词是否"看起来像人名" -/// 返回 true = 像人名,可以保留;false = 不像,应该排除 -pub fn is_likely_person_name(name: &str) -> bool { - let name = name.trim(); - if name.is_empty() { return false; } - - // 强制包含名单优先放行(已知模特名,跳过所有启发式检查) - // 同时支持通过更长匹配扩展 name(如 "杨晨晨" → "杨晨晨Yome") - let dict = tag_dict::get_tag_dict(); - if dict.is_included_person(name) || dict.find_longest_included_match(name).is_some() { - return true; - } - - // 字符数必须 >= 3(人名至少需要 2 个中文字或 3 个英文字母) - if name.chars().count() <= 2 { return false; } - - // 先排除已知的非人名 - if is_excluded_name(name) { return false; } - - let name_lower = name.to_lowercase(); - - // 纯数字排除 - if name.chars().all(|c| c.is_ascii_digit()) { return false; } - - // 含数字太多的排除(超过一半是数字) - let digit_count = name.chars().filter(|c| c.is_ascii_digit()).count(); - if digit_count * 2 > name.len() { return false; } - - // 纯英文且长度 > 15 的排除(太长不像人名) - let has_cn = RE_CHINESE.is_match(name); - if !has_cn && name.len() > 15 { return false; } - - // 以数字开头的排除(除非是纯数字的英文名) - if name.chars().next().map(|c| c.is_ascii_digit()).unwrap_or(false) { return false; } - - // 含特殊字符过多的排除 - let special_count = name.chars().filter(|c| { - !c.is_alphanumeric() && !RE_CHINESE.is_match(&c.to_string()) - }).count(); - if special_count > 2 { return false; } - - // 已知后缀排除(如 "photos", "series", "collection" 等) - let known_suffix = ["photos", "series", "collection", "edition", "set", "vol", "album"]; - for suffix in known_suffix { - if name_lower.ends_with(suffix) { return false; } - } - - // 全部是大写字母且长度 > 6 的排除(通常是缩写/工作室名) - if name.chars().all(|c| c.is_ascii_uppercase()) && name.len() > 6 { return false; } - - // 标签词典中的词不应作为人名(tags 永远不出现在 person 中) - if tag_dict::get_tag_dict().classify(name).is_some() { return false; } - // 也检查小写版本 - if tag_dict::get_tag_dict().classify(&name.to_lowercase()).is_some() { return false; } - - true -} - -// ── 人名清洗 ── - -/// 清洗人名:移除前缀、括号内容、末尾标点 -/// 返回 (cleaned_name, aliases) -/// 对应 Python clean_person_names.clean_person_name -pub fn clean_person_name(raw_name: &str) -> (String, Vec<(String, String)>) { - let mut aliases = Vec::new(); - let mut name = raw_name.to_string(); - - // 1. 移除前缀(从词典动态获取) - for prefix in tag_dict::get_tag_dict().get_person_prefixes() { - if name.starts_with(prefix) { - aliases.push(("prefix".to_string(), prefix.to_string())); - name = name[prefix.len()..].trim().to_string(); - break; - } - } - - // 2. 移除末尾括号内容 - let mut cleaned = String::new(); - let mut last_end = 0; - for cap in RE_PAREN_CONTENT.captures_iter(&name) { - let m = cap.get(0).unwrap(); - let content = cap.get(1).map_or("", |c| c.as_str()); - cleaned.push_str(&name[last_end..m.start()]); - last_end = m.end(); - - if !content.is_empty() { - if RE_CHINESE.is_match(content) { - aliases.push(("nickname".to_string(), content.to_string())); - } else { - aliases.push(("english".to_string(), content.to_string())); - } - } - } - cleaned.push_str(&name[last_end..]); - let name = cleaned.trim().to_string(); - - // 3. 清理末尾标点 - let name = RE_TRAILING_PUNCT.replace(&name, "").trim().to_string(); - - // 4. 从清洗后名字提取英文名别名 - if let Some(caps) = RE_ENGLISH_SUFFIX.captures(&name) { - let chinese_part = caps[1].to_string(); - let english_part = caps[2].to_string(); - if !english_part.is_empty() { - aliases.push(("chinese".to_string(), chinese_part)); - aliases.push(("english".to_string(), english_part)); - } - } - - if name.is_empty() { - (raw_name.to_string(), aliases) - } else { - (name, aliases) - } -} - -/// 获取归并键(小写化+移除空格和标点) -pub fn get_person_key(name: &str) -> String { - name.to_lowercase() - .chars() - .filter(|c| !c.is_whitespace() && !c.is_ascii_punctuation()) - .collect() -} - -/// 拆分人名为「中文主名 + 别名列表」 -/// 规则: -/// - 如果有中文部分:主名 = 中文部分,别名 = 英文后缀 + 原始全名 + 括号内容 -/// - 如果只有英文:主名 = 英文全名,别名 = 原始全名 -/// -/// 示例: -/// - 杨晨晨Yome -> 主名"杨晨晨", 别名["Yome", "杨晨晨Yome"] -/// - 杨晨晨Sugar -> 主名"杨晨晨", 别名["Sugar", "杨晨晨Sugar"] -/// - Yome -> 主名"Yome", 别名["Yome"] -pub fn split_person_name_with_aliases(raw_name: &str) -> (String, Vec<(String, String)>) { - let (cleaned, mut aliases) = clean_person_name(raw_name); - let mut primary_name = cleaned.clone(); - - // 尝试提取中文主名 - if let Some(cn_part) = extract_cn(&cleaned) { - if !cn_part.is_empty() && cn_part != cleaned { - primary_name = cn_part.clone(); - - // 提取英文后缀作为别名 - if let Some(rest) = cleaned.strip_prefix(&cn_part) { - let english_suffix = rest.trim().to_string(); - if !english_suffix.is_empty() { - // 避免重复 - let already_has = aliases.iter().any(|(_, a)| a == &english_suffix); - if !already_has { - aliases.push(("english".to_string(), english_suffix)); - } - } - } - } - } - - // 原始完整名也作为别名(用于搜索匹配) - if !raw_name.trim().is_empty() && raw_name.trim() != primary_name { - let already_has = aliases.iter().any(|(_, a)| a == raw_name.trim()); - if !already_has { - aliases.push(("original".to_string(), raw_name.trim().to_string())); - } - } - - // cleaned 名也作为别名(如果和主名不同) - if cleaned != primary_name { - let already_has = aliases.iter().any(|(_, a)| a == &cleaned); - if !already_has { - aliases.push(("cleaned".to_string(), cleaned)); - } - } - - (primary_name, aliases) -} - -// ── 一键提取:人名 + 标签(单次 jieba 分词) ── - -/// 一次 jieba 分词,同时提取人名和标签 -/// 返回 (人名Option, 标签Vec) -/// 优势:只做一次分词,省去重复开销 -pub fn extract_person_and_tags(title: &str) -> (Option, Vec<(String, String)>) { - let title = title.trim(); - if title.is_empty() { - return (None, Vec::new()); - } - - // 做一次词性标注分词 - let tags = JIEBA.tag(title, true); - - // ── 第一步:提取人名(优先级最高)── - let person_name = extract_person_from_tags(&tags); - - // ── 第二步:提取名词标签(排除人名)── - let tag_list = extract_tags_from_jieba_result(&tags, person_name.as_deref()); - - (person_name, tag_list) -} - -/// 从 jieba 分词结果中提取人名 -/// 返回完整的原始人名(可能含英文后缀),供 split_person_name_with_aliases 拆分为 主名+别名 -/// 例如 jieba 拆出 "水淼/nr Aqua/eng" → 返回 "水淼Aqua" -fn extract_person_from_tags(tags: &[jieba_rs::Tag]) -> Option { - let mut candidates: Vec<(String, usize)> = Vec::new(); - - for (i, tag) in tags.iter().enumerate() { - let word = tag.word.trim(); - if word.len() < 2 { continue; } - - // 过滤纯标点 - if is_punctuation_only(word) { continue; } - - let priority = match tag.tag { - "nr" => 0, // 人名(最高优先级) - "nrfg" => 1, // 古体人名 - "nrt" => 2, // 音译人名 - "nz" => 3, // 其它专名 - "n" => 4, // 名词 - _ => continue, - }; - - if is_likely_person_name(word) { - // 如果是中文人名,检查后面是否紧跟英文词(如 水淼/nr Aqua/eng) - // 拼装成完整原始名,供 split_person_name_with_aliases 拆分为 主名+别名 - let mut full_name = word.to_string(); - let is_chinese = word.chars().any(|c| RE_CHINESE.is_match(&c.to_string())); - if is_chinese { - let mut j = i + 1; - while j < tags.len() { - let next_word = tags[j].word.trim(); - let next_tag = tags[j].tag; - if next_word.is_empty() { j += 1; continue; } - // 英文词(eng)或纯英文字母,且不是停用词 - if next_tag == "eng" || - (next_word.chars().all(|c| c.is_ascii_alphabetic()) && next_word.len() >= 2 && next_word.len() <= 15) { - let lower = next_word.to_lowercase(); - // 跳过停用词(从词典动态获取) - if !tag_dict::get_tag_dict().is_stop_word(&lower) && !EXCLUDED_LOWER.contains(&lower) { - full_name.push_str(next_word); - j += 1; - continue; - } - } - break; - } - } - - candidates.push((full_name, priority)); - } - } - - candidates.sort_by(|a, b| a.1.cmp(&b.1)); - candidates.into_iter().next().map(|(name, _)| clean_name(&name)) -} - -/// 判断字符串是否全为标点符号(不含任何字、字母或数字) -fn is_punctuation_only(s: &str) -> bool { - if s.is_empty() { return true; } - // 检查是否包含任意"有效字符"(中文字、字母、数字) - !s.chars().any(|c| { - c.is_ascii_alphanumeric() - || ('\u{4e00}'..='\u{9fff}').contains(&c) - || ('\u{3400}'..='\u{4dbf}').contains(&c) - || ('\u{f900}'..='\u{faff}').contains(&c) - }) -} - -/// 从 jieba 分词结果中提取标签(排除人名) -fn extract_tags_from_jieba_result( - tags: &[jieba_rs::Tag], - person_name: Option<&str>, -) -> Vec<(String, String)> { - use std::collections::HashSet; - - let mut result = Vec::new(); - let mut seen = HashSet::new(); - - // 停用词(从词典动态获取) - let stop_words = tag_dict::get_tag_dict().get_stop_words().clone(); - - // 人名排除 - let person_exclude: Vec = person_name - .map(|n| { - let mut v = vec![n.to_lowercase()]; - for part in n.split_whitespace() { - v.push(part.to_lowercase()); - } - if let Some(cn) = extract_cn(n) { - v.push(cn.to_lowercase()); - // 中英文混合名的英文后缀也要排除(如 "水淼Aqua" → "aqua") - if let Some(rest) = n.strip_prefix(&cn) { - let suffix = rest.trim(); - if !suffix.is_empty() { - v.push(suffix.to_lowercase()); - } - } - } - v - }) - .unwrap_or_default(); - - for tag in tags { - let word = tag.word.trim(); - if word.len() < 2 { continue; } - - let word_lower = word.to_lowercase(); - - // 纯标点/符号跳过 - if is_punctuation_only(word) { continue; } - - // 纯数字跳过 - if word.chars().all(|c| c.is_ascii_digit()) { continue; } - - // 停用词跳过 - if stop_words.contains(word_lower.as_str()) { continue; } - - // 人名跳过 - if person_exclude.iter().any(|p| word_lower.contains(p)) { continue; } - - // 去重 - if !seen.insert(word_lower.clone()) { continue; } - - // 按词性分类 - let pos = tag.tag; - let category = match pos { - "n" | "ng" => "noun", - "nz" => "proper", - "ns" => "location", - "eng" => "other", - "x" => "other", - // 排除的词性(这些不应该作为标签) - "nr" | "nrfg" | "nrt" => continue, // 人名 - "nt" => continue, // 机构团体名(不是标签) - "vn" => continue, // 名动词(分类模糊) - "a" | "ad" | "an" => continue, // 形容词(不是标签) - "v" | "vd" | "vg" => continue, // 动词(不是标签) - "m" | "mq" => continue, - "q" | "qv" | "qt" => continue, - "r" | "rr" | "rz" => continue, - "c" => continue, - "p" => continue, - "u" | "ul" | "uv" | "ud" | "ug" | "uj" => continue, - "d" => continue, - "e" | "y" | "o" => continue, - "w" => continue, - "t" | "tg" => continue, - "s" => continue, - "f" => continue, - "b" | "bl" => continue, - "z" => continue, - _ => continue, - }; - - result.push((word.to_string(), category.to_string())); - } - - result -} - -// ── 标签提取 ── - -/// 从标题中提取标签(排除人名部分) -/// 返回 Vec<(tag, pos)> -/// 对应 Python tag_index.extract_tags_from_title -#[allow(dead_code)] -pub fn extract_tags_from_title_legacy(title: &str, person_name: Option<&str>) -> Vec<(String, String)> { - let mut title = title.to_string(); - - // 清理末尾的 "N photos" 等 - title = RE_PHOTOS_SUFFIX.replace(&title, "").to_string(); - - // 移除人名 - if let Some(name) = person_name { - title = title.replace(name, " "); - for part in name.split_whitespace() { - title = title.replace(part, " "); - } - } - - // 移除 [工作室] 前缀 - title = RE_BRACKET_PREFIX.replace(&title, "").to_string(); - - // 按空白分割,过滤停用词和短词 - let mut tags = Vec::new(); - let mut seen = HashSet::new(); - - for word in title.split_whitespace() { - let word = word.trim().to_lowercase(); - if word.len() < 2 { - continue; - } - if STOP_WORDS_SET.contains(&word) { - continue; - } - if word.chars().all(|c| c.is_ascii_digit() || c == '.') { - continue; - } - if seen.contains(&word) { - continue; - } - seen.insert(word.clone()); - tags.push((word, "x".to_string())); - } - - tags -} - -/// 标签归一化 -pub fn normalize_tag(tag: &str) -> String { - tag.trim().to_lowercase() -} - -// ═══════════════════════════════════════════════════════ -// 统一标题预处理(用于 parse_album_title 入口) -// ═══════════════════════════════════════════════════════ +// ── 统一预处理 ── /// 统一标题预处理:移除照片数后缀、[工作室] 前缀、称呼前缀、编号后缀 pub fn preprocess_title(title: &str) -> String { @@ -719,82 +50,317 @@ pub fn preprocess_title(title: &str) -> String { t } +// ── Token 提取 ── + +/// 将标题分割为独立的 token(用于 Key 匹配) +fn tokenize(title: &str) -> Vec { + let mut tokens = Vec::new(); + + // 先按空白分割(简单 token) + for segment in title.split_whitespace() { + // 跳过纯标点 + if tag_extractor::is_punctuation_only(segment) { continue; } + + // 尝试按常见连接符进一步分割(如 "性感女神" 在 keymap 中找不到 → 拆开) + tokens.push(segment.to_string()); + } + + // 去重 + let mut seen = HashSet::new(); + tokens.retain(|t| seen.insert(t.to_lowercase())); + + tokens +} + +/// 对 token 按长度降序排序(最长匹配优先) +fn sort_by_length(tokens: &mut Vec) { + tokens.sort_by(|a, b| b.len().cmp(&a.len())); +} + +// ── 核心解析:统一入口 ── + /// 统一相册标题解析入口 /// -/// 一次 jieba 分词 → 同时提取 person + tags。 -/// tags 通过 tag_extractor 的三步流程(A 词典 / B jieba 名词 / C 正则)提取, -/// 使用同一份 jieba result。 +/// 流程:预处理 → token 分割 → 对每个 token: +/// 1. keymap 匹配 → person → 人物;其他 → 标签 +/// 2. stopwords → 跳过 +/// 3. 人名启发式 → 人物 /// -/// 返回 ParseResult 可直接用于 Phase 1b 批量写库。 +/// 返回 ParseResult 可直接用于批量写库。 pub fn parse_album_title(album_id: &str, title: &str) -> crate::models::parse::ParseResult { let mut result = crate::models::parse::ParseResult::new(album_id.to_string()); let title = title.trim(); if title.is_empty() { return result; } - // 1. 预处理 let cleaned = preprocess_title(title); + if cleaned.is_empty() { return result; } - // 2. cosplay 格式优先 - if let Some(caps) = RE_COSPLAY_BY.captures(&cleaned) { - result.person_name = Some(clean_name(caps[3].trim())); - let name = result.person_name.as_deref().unwrap_or(""); - // 有限标签提取(仅词典 + 正则,不调 jieba 避免重复) - let tags = tag_extractor::extract_dict_tags(title, &[name.to_lowercase()], &mut std::collections::HashSet::new()); - result.tags = tags; - return result; - } - if let Some(caps) = RE_COSPLAY.captures(&cleaned) { - result.person_name = Some(clean_name(caps[1].trim())); - let name = result.person_name.as_deref().unwrap_or(""); - let tags = tag_extractor::extract_dict_tags(title, &[name.to_lowercase()], &mut std::collections::HashSet::new()); - result.tags = tags; - return result; + let dict = tag_dict::get_tag_dict(); + + // ── 收集所有 token(空白分割)── + let raw_tokens = tokenize(&cleaned); + + // ── 用于标签提取的已处理 title(移除人名后)── + let mut person_found: Option<(String, String)> = None; + let mut tag_parts: Vec = Vec::new(); + + for token in &raw_tokens { + let token_lower = token.to_lowercase(); + + // 跳过过短 token + if token.len() < 2 { + tag_parts.push(token.clone()); + continue; + } + + // 跳过纯数字 + if token.chars().all(|c| c.is_ascii_digit()) { + continue; + } + + // 跳过停用词 + if dict.is_stop_word(&token_lower) { + continue; + } + + // 检查 keymap(精确匹配) + if let Some(category) = dict.match_keymap(&token_lower) { + if category == "person" && person_found.is_none() { + person_found = Some((token.clone(), token_lower.clone())); + } else if category != "person" { + tag_parts.push(token.clone()); + continue; + } + continue; + } + + // 检查是否为已知人名(include/启发式) + if person_found.is_none() && is_likely_person_name(token) { + person_found = Some((token.clone(), token_lower.clone())); + continue; + } + + // 剩余内容放入 tag 池 + tag_parts.push(token.clone()); } - // 3. 一次 jieba 分词(核心!全流程共用) - let jieba_tags = JIEBA.tag(&cleaned, true); - - // 4. 提取人名 - let person_raw = extract_person_from_tags(&jieba_tags); - - if let Some(name) = &person_raw { - // include 扩展 - let expanded = tag_dict::get_tag_dict() - .find_longest_included_match(name) + // ── 处理人物 ── + if let Some((name, _)) = &person_found { + // include 列表中的最长匹配扩展 + let expanded = dict.find_longest_included_match(name) .filter(|longer| longer.len() > name.len()); let effective_name = expanded.as_deref().unwrap_or(name.as_str()); - let (primary, aliases) = split_person_name_with_aliases(effective_name); + + let (primary, _aliases) = split_person_name_with_aliases(effective_name); let final_name = if primary.is_empty() { effective_name.to_string() } else { primary }; if final_name.chars().count() > 2 { result.person_name = Some(final_name); - // person_primary 用于别名处理,暂存但不暴露 } } - // 5. 提取标签(使用同一份 jieba result) + // ── 提取标签 ── let person_exclude = result.person_name.as_deref(); - let raw_tags = tag_extractor::extract_tags_from_title(title, person_exclude, &jieba_tags); + let raw_tags = tag_extractor::extract_tags_from_title(title, person_exclude); let unique = tag_extractor::unique_tags(raw_tags); result.tags = unique; result } +// ── 人名启发式判断 ── + +/// 判断一个词是否"看起来像人名"(v4 简化版,不再查 tag_dict classify,因为 keymap 已覆盖) +/// 返回 true = 像人名;false = 不像 +pub fn is_likely_person_name(name: &str) -> bool { + let name = name.trim(); + if name.is_empty() { return false; } + + let dict = tag_dict::get_tag_dict(); + + // 强制包含名单优先放行 + if dict.is_included_person(name) || dict.find_longest_included_match(name).is_some() { + return true; + } + + // 字符数限制 + if name.chars().count() <= 2 { return false; } + + // keymap 中的词一定不是人名(已在 parse_album_title 中提前检查过,双保险) + if dict.match_keymap(&name.to_lowercase()).is_some() { return false; } + + // 排除已知非人名 + if dict.is_excluded_person(name) { return false; } + + let name_lower = name.to_lowercase(); + + // 纯数字排除 + if name.chars().all(|c| c.is_ascii_digit()) { return false; } + + // 含数字太多的排除 + let digit_count = name.chars().filter(|c| c.is_ascii_digit()).count(); + if digit_count * 2 > name.len() { return false; } + + // 纯英文且长度 > 15 排除 + let has_cn = RE_CHINESE.is_match(name); + if !has_cn && name.len() > 15 { return false; } + + // 以数字开头排除 + if name.chars().next().map(|c| c.is_ascii_digit()).unwrap_or(false) { return false; } + + // 含特殊字符过多排除 + let special_count = name.chars().filter(|c| { + !c.is_alphanumeric() && !RE_CHINESE.is_match(&c.to_string()) + }).count(); + if special_count > 2 { return false; } + + // 已知后缀排除 + let known_suffix = ["photos", "series", "collection", "edition", "set", "vol", "album"]; + for suffix in known_suffix { + if name_lower.ends_with(suffix) { return false; } + } + + // 全大写且长度 > 6 排除(缩写/工作室名) + if name.chars().all(|c| c.is_ascii_uppercase()) && name.len() > 6 { return false; } + + true +} + +// ── 人名清洗 ── + +/// 提取中文核心(开头的连续中文字符) +pub fn extract_cn(name: &str) -> Option { + let re = Regex::new(r"^([\u{4e00}-\u{9fff}]+)").unwrap(); + re.captures(name).map(|c| c[1].to_string()) +} + +/// 清理人名:移除前缀、括号内容、末尾标点 +pub fn clean_person_name(raw_name: &str) -> (String, Vec<(String, String)>) { + let mut aliases = Vec::new(); + let mut name = raw_name.to_string(); + + for prefix in tag_dict::get_tag_dict().get_person_prefixes() { + if name.starts_with(prefix) { + aliases.push(("prefix".to_string(), prefix.to_string())); + name = name[prefix.len()..].trim().to_string(); + break; + } + } + + let mut cleaned = String::new(); + let mut last_end = 0; + for cap in RE_PAREN_CONTENT.captures_iter(&name) { + let m = cap.get(0).unwrap(); + let content = cap.get(1).map_or("", |c| c.as_str()); + cleaned.push_str(&name[last_end..m.start()]); + last_end = m.end(); + if !content.is_empty() { + if RE_CHINESE.is_match(content) { + aliases.push(("nickname".to_string(), content.to_string())); + } else { + aliases.push(("english".to_string(), content.to_string())); + } + } + } + cleaned.push_str(&name[last_end..]); + let name = RE_TRAILING_PUNCT.replace(&cleaned.trim(), "").trim().to_string(); + + aliases.push(("original".to_string(), raw_name.trim().to_string())); + + if let Some(caps) = RE_ENGLISH_SUFFIX.captures(&name) { + let chinese_part = caps[1].to_string(); + let english_part = caps[2].to_string(); + if !english_part.is_empty() { + aliases.push(("chinese".to_string(), chinese_part)); + aliases.push(("english".to_string(), english_part)); + } + } + + if name.is_empty() { (raw_name.to_string(), aliases) } else { (name, aliases) } +} + +/// 拆分人名为「中文主名 + 别名列表」 +pub fn split_person_name_with_aliases(raw_name: &str) -> (String, Vec<(String, String)>) { + let (cleaned, mut aliases) = clean_person_name(raw_name); + let mut primary_name = cleaned.clone(); + + if let Some(cn_part) = extract_cn(&cleaned) { + if !cn_part.is_empty() && cn_part != cleaned { + primary_name = cn_part.clone(); + if let Some(rest) = cleaned.strip_prefix(&cn_part) { + let english_suffix = rest.trim().to_string(); + if !english_suffix.is_empty() { + let already_has = aliases.iter().any(|(_, a)| a == &english_suffix); + if !already_has { + aliases.push(("english".to_string(), english_suffix)); + } + } + } + } + } + + if cleaned != primary_name { + let already_has = aliases.iter().any(|(_, a)| a == &cleaned); + if !already_has { + aliases.push(("cleaned".to_string(), cleaned)); + } + } + + (primary_name, aliases) +} + +/// 判断是否为工作室/平台名(需排除) +pub fn is_excluded_name(name: &str) -> bool { + tag_dict::get_tag_dict().is_excluded_person(name) +} + +/// 判断后缀是否有效 +pub fn is_valid_suffix(suffix: &str) -> bool { + if suffix.is_empty() { return true; } + !RE_CHINESE.is_match(suffix) +} + +/// 标签归一化 +pub fn normalize_tag(tag: &str) -> String { + tag.trim().to_lowercase() +} + +// ── 兼容函数(供 pipeline / person_merger 调用)── + +/// 从标题中提取人物名(兼容函数) +pub fn extract_person_name_from_title(title: &str) -> Option { + parse_album_title("", title).person_name +} + +/// 从标题中提取人物名和标签(兼容函数) +pub fn extract_person_and_tags(title: &str) -> (Option, Vec<(String, String)>) { + let result = parse_album_title("", title); + (result.person_name, result.tags) +} + #[cfg(test)] mod tests { use super::*; #[test] - fn test_extract_person_name() { - // 纯中文人名(中文优先级更高,英文后缀作为别名处理) - assert_eq!(extract_person_name_from_title("杨晨晨Yome 私房写真").unwrap(), "杨晨晨"); - assert_eq!(extract_person_name_from_title("王馨瑶yanni 比基尼").unwrap(), "王馨瑶"); - assert_eq!(extract_person_name_from_title("[XiuRen] 杨晨晨 性感").unwrap(), "杨晨晨"); - assert_eq!(extract_person_name_from_title("美女模特 杨晨晨 私房").unwrap(), "杨晨晨"); - // 纯英文人名也支持 - assert!(extract_person_name_from_title("Yome sexy photos").is_some()); + fn test_parse_album_title_with_person() { + let r = parse_album_title("id1", "杨晨晨Yome 私房写真"); + assert_eq!(r.person_name.as_deref(), Some("杨晨晨")); + assert!(!r.tags.is_empty()); + } + + #[test] + fn test_parse_album_title_no_person() { + let r = parse_album_title("id2", "浴室 可爱 性感 写真"); + assert!(r.person_name.is_none()); + assert!(!r.tags.is_empty()); + } + + #[test] + fn test_parse_album_title_with_prefix() { + let r = parse_album_title("id3", "美女模特 杨晨晨 私房"); + assert_eq!(r.person_name.as_deref(), Some("杨晨晨")); } #[test] @@ -804,34 +370,17 @@ mod tests { assert!(extract_cn("Yome").is_none()); } - #[test] - fn test_clean_person_name() { - let (cleaned, aliases) = clean_person_name("美女模特 杨晨晨Yome"); - assert_eq!(cleaned, "美女模特 杨晨晨Yome"); - assert!(!aliases.is_empty()); - } - #[test] fn test_split_person_name_with_aliases() { - // 中文 + 英文后缀 let (name, aliases) = split_person_name_with_aliases("杨晨晨Yome"); assert_eq!(name, "杨晨晨"); let alias_names: Vec<&str> = aliases.iter().map(|(_, a)| a.as_str()).collect(); assert!(alias_names.contains(&"Yome")); - assert!(alias_names.contains(&"杨晨晨Yome")); - // 同一人,不同英文名 - let (name2, aliases2) = split_person_name_with_aliases("杨晨晨Sugar"); + let (name2, _) = split_person_name_with_aliases("杨晨晨"); assert_eq!(name2, "杨晨晨"); - let alias_names2: Vec<&str> = aliases2.iter().map(|(_, a)| a.as_str()).collect(); - assert!(alias_names2.contains(&"Sugar")); - // 只有中文 - let (name3, _) = split_person_name_with_aliases("杨晨晨"); - assert_eq!(name3, "杨晨晨"); - - // 只有英文 - let (name4, _) = split_person_name_with_aliases("Yome"); - assert_eq!(name4, "Yome"); + let (name3, _) = split_person_name_with_aliases("Yome"); + assert_eq!(name3, "Yome"); } -} \ No newline at end of file +}