diff --git a/core/parser.py b/core/parser.py index d9aee50..bc9e76a 100644 --- a/core/parser.py +++ b/core/parser.py @@ -184,16 +184,16 @@ class K3VoucherParser: continue # 提取名称 — 按用户规则:取最后一个横杠之后的文字 + # 先取最后横杠之后的内容再清洗(防止尾随横杠被提前消除→"银行存款-"变"银行存款") name = t[m.end():].lstrip('--—= ') - name = re.sub(r'[\d.\-—=]+$', '', name).strip() + idx = max(name.rfind('-'), name.rfind('-'), name.rfind('—')) + if idx >= 0: + name = name[idx+1:].strip() + # 清洗尾部数字/符号 + name = re.sub(r'[\d.\-—=-]+$', '', name).strip() name = name.lstrip('-—-=') - if '\\' in name: name = name.split('\\', 1)[0].strip() - else: - idx = max(name.rfind('-'), name.rfind('-'), name.rfind('—')) - if idx >= 0: - name = name[idx+1:].strip() # 去重:优先保留带完整名称的行 if code_part in code_map: @@ -237,6 +237,12 @@ class K3VoucherParser: continue name_candidates.append((t, cy, cx)) + # 额外过滤:排除园区名/房号类文本(含"里景苑园"且有数字) + name_candidates = [(t, cy, cx) for t, cy, cx in name_candidates + if not re.search(r'[\u4e00-\u9fff]*[里景苑园]\w*\d', t) + and not t.endswith('/') + and not re.search(r'各类统筹|装修押金|电费收入|本收入|办公费', t)] + name_candidates.sort(key=lambda x: x[1]) for code in codes: @@ -274,6 +280,12 @@ class K3VoucherParser: n = n[idx+1:].strip() if not n or len(n) < 3: continue + # 排除园区名/行政地名作为科目名称(如"假日里""假日风景") + if re.search(r'[里景苑园]$', n): + continue + # 排除公司名/单位名(如"鹤壁科赛物业服务有限公司"等) + if re.search(r'公司|有限|税务|供电|电力', t): + continue # 排除明显的非科目名称文本 if any(k in t for k in ['未到账', '过账', 'Manager', '出纳', '制单', '审核', '经办']): continue @@ -296,10 +308,20 @@ class K3VoucherParser: for cand in candidates: score = 0 if cand['is_inline']: - score = 10 # 内联名称基线分(有实际来源,更高可信度) + score = 10 # 内联名称基线分 + # 多级代码配一级名称→降权(内联可能不完整,让补位有机会) + if code['code'].count('.') >= 1 and cand['name'] in ( + '银行存款', '库存现金', '其他货币资金', + '应收账款', '预付账款', '其他应收款', + '应付账款', '预收账款', '其他应付款', + '主营业务成本', '主营业务收入', '其他业务收入', + '管理费用', '财务费用', '销售费用', + '营业外收入', '营业外支出', '代扣代缴', + ): + score -= 15 else: - if '-' in cand['raw'] or '-' in cand['raw']: - score += 10 # 含横杠信号 + if any(d in cand['raw'] for d in ['-', '-', '—']): + score += 10 # 含横杠信号(含全角/ASCII/长破折号) if len(cand['name']) >= 4: score += 3 # 长名称更可信 x_dist = abs(cand['x'] - code['x_pos']) @@ -314,6 +336,18 @@ class K3VoucherParser: # 非科目名称特征文本 if any(k in cand['raw'] for k in ['未到账', '过账', 'Manager']): score -= 20 + # 已知一级科目名+多级代码→名称应是末级而非一级 + code_levels = code['code'].count('.') + 1 + if code_levels >= 2 and cand['name'] in ( + '银行存款', '库存现金', '其他货币资金', + '应收账款', '预付账款', '其他应收款', + '应付账款', '预收账款', '其他应付款', + '主营业务成本', '主营业务收入', '其他业务收入', + '管理费用', '财务费用', '销售费用', + '营业外收入', '营业外支出', + '代扣代缴', '实收资本', '本年利润', + ): + score -= 25 # 多级代码配一级名称→明显不对 score -= abs(cand['y'] - code['y_pos']) / 10 # 近的优先(y差10px扣1分,防止跨行误抓) cand['score'] = score