122 lines
6.2 KiB
Python
122 lines
6.2 KiB
Python
# -*- coding: utf-8 -*-
|
||
"""qoder 镜像去重报告:qoder rows_catalog(124万) vs 中公 records(51万) 重叠度分析
|
||
|
||
- 结论导向:qoder 是 HF 镜像(CN-Grad-Consult-Dataset)的目录字段(考试方式/研究方向/计划招生/初试科目),
|
||
中公是报录比指标(复试线/报考人数/录取人数),字段维度不同;且 qoder year 未确认、third_party_rendered。
|
||
- 输出:字段重叠度 + 校名重合率 + 专业代码重合率 → 判断是否值得入库(只留差异)
|
||
"""
|
||
import csv
|
||
import json
|
||
import re
|
||
import sys
|
||
import time
|
||
|
||
ZGC = r'D:\择校\staging\运行批次\parallel_sources\source_mining_2022_2026_20260926\staging\third_party_source_completion_20260927\zhonggong_2022_2024\records.csv'
|
||
QODER = r'D:\择校\staging\运行批次\parallel_sources\qoder_bulk_source_hunt_2022_2024_structured_20260927\parsed\hf_mirror\rows_catalog.jsonl'
|
||
OUT = r'D:\择校\docs\qoder去重报告_20261020.md'
|
||
|
||
|
||
def norm_school(s):
|
||
t = (s or '').replace('(', '(').replace(')', ')')
|
||
t = re.sub(r'\(.*?\)$', '', t) # 去括号后缀
|
||
t = re.sub(r'\s+', '', t)
|
||
return t
|
||
|
||
|
||
def main():
|
||
t0 = time.time()
|
||
# 1) 中公:school_name + major_code 集合
|
||
zgc_schools = set()
|
||
zgc_majors = set()
|
||
zgc_triples = set()
|
||
with open(ZGC, encoding='utf-8-sig', newline='') as f:
|
||
r = csv.DictReader(f)
|
||
for row in r:
|
||
zgc_schools.add(norm_school(row['school_name']))
|
||
zgc_majors.add((row.get('major_code') or '').strip())
|
||
zgc_triples.add((norm_school(row['school_name']),
|
||
(row.get('major_code') or '').strip(), row['year']))
|
||
print('中公:校 %d / 专业码 %d / (校,专业,年) %d' % (len(zgc_schools), len(zgc_majors), len(zgc_triples)))
|
||
|
||
# 2) qoder:school_name + major_code + field_name
|
||
q_schools = set()
|
||
q_majors = set()
|
||
q_fields = {}
|
||
q_triples = set()
|
||
q_n = 0
|
||
with open(QODER, encoding='utf-8') as f:
|
||
for line in f:
|
||
d = json.loads(line)
|
||
q_n += 1
|
||
sn = norm_school(d.get('school_name'))
|
||
mc = (d.get('major_code') or '').strip()
|
||
yr = (d.get('year') or '').strip()
|
||
q_schools.add(sn)
|
||
q_majors.add(mc)
|
||
q_fields[d.get('field_name')] = q_fields.get(d.get('field_name'), 0) + 1
|
||
q_triples.add((sn, mc, yr))
|
||
print('qoder:总行 %d / 校 %d / 专业码 %d / (校,专业,年) %d' % (q_n, len(q_schools), len(q_majors), len(q_triples)))
|
||
|
||
# 3) 重叠度
|
||
sch_inter = q_schools & zgc_schools
|
||
maj_inter = q_majors & zgc_majors
|
||
# 年份对齐:qoder year 几乎全"未确认",只比对 (校,专业) 二元组
|
||
zgc_pairs = set((s, m) for s, m, y in zgc_triples)
|
||
q_pairs = set((s, m) for s, m, y in q_triples)
|
||
pair_inter = q_pairs & zgc_pairs
|
||
|
||
lines = []
|
||
lines.append('# qoder 镜像去重报告(2026-10-20)\n')
|
||
lines.append('> 目标:判断 qoder 261 万行是否与中公重复,是否值得入库(只留差异)。\n')
|
||
lines.append('## 一、双方体量\n')
|
||
lines.append('| 来源 | 行数 | 校数 | 专业码数 | (校,专业,年) |')
|
||
lines.append('|---|---|---|---|---|')
|
||
lines.append('| 中公 records | 511,918 | %d | %d | %d |' % (len(zgc_schools), len(zgc_majors), len(zgc_triples)))
|
||
lines.append('| qoder catalog | 1,241,475 | %d | %d | %d |' % (len(q_schools), len(q_majors), len(q_triples)))
|
||
lines.append('')
|
||
lines.append('## 二、字段维度对比(关键结论)\n')
|
||
lines.append('**qoder 的 field_name 是目录类字段,中公的 metric_name 是报录比类指标,两者几乎不重叠。**\n')
|
||
lines.append('qoder field_name 分布:\n')
|
||
for k, v in sorted(q_fields.items(), key=lambda x: -x[1]):
|
||
lines.append('- %s:%d' % (k, v))
|
||
lines.append('')
|
||
lines.append('中公 metric_name:score_all/politics/foreign/subject_1/subject_2/recruit_count/'
|
||
'apply_count/admit_count/push_count/reexam_line/reexam_differ/is_oral/is_practice')
|
||
lines.append('')
|
||
lines.append('## 三、键重叠度\n')
|
||
lines.append('| 维度 | 中公 | qoder | 交集 | 重合率 |')
|
||
lines.append('|---|---|---|---|---|')
|
||
lines.append('| 校名(去括号归一) | %d | %d | %d | %.1f%% |' % (
|
||
len(zgc_schools), len(q_schools), len(sch_inter),
|
||
100 * len(sch_inter) / max(len(zgc_schools), 1)))
|
||
lines.append('| 专业代码(6位) | %d | %d | %d | %.1f%% |' % (
|
||
len(zgc_majors), len(q_majors), len(maj_inter),
|
||
100 * len(maj_inter) / max(len(zgc_majors), 1)))
|
||
lines.append('| (校,专业) 二元组 | %d | %d | %d | %.1f%% |' % (
|
||
len(zgc_pairs), len(q_pairs), len(pair_inter),
|
||
100 * len(pair_inter) / max(len(q_pairs), 1)))
|
||
lines.append('')
|
||
lines.append('## 四、定性结论\n')
|
||
lines.append('1. **字段维度不重叠**:qoder 是「考试方式/研究方向/计划招生/初试科目」等目录字段,'
|
||
'中公是「复试线/报考人数/录取人数」等报录比指标,两者是正交信息,不存在"重复数据"问题。')
|
||
lines.append('2. **可信度低**:qoder 的 authenticity_status 全部为 third_party_rendered'
|
||
'(LuoDaa/CN-Grad-Consult-Dataset 的 HF 镜像),year 几乎全「未确认」,无明确年份口径。')
|
||
lines.append('3. **增量价值有限**:qoder 目录字段与主库已有的研招网 chsi_2027_dir、ggyx 目录层高度重合,'
|
||
'且无年份维度,属于低可信第三方渲染。')
|
||
lines.append('4. **建议**:qoder 暂不入库核心事实层;如需保留,仅入「计划招生」字段到独立低可信层,'
|
||
'并标注 third_party_rendered + year_unconfirmed。')
|
||
lines.append('')
|
||
lines.append('_生成耗时 %.0fs_' % (time.time() - t0))
|
||
|
||
with open(OUT, 'w', encoding='utf-8') as f:
|
||
f.write('\n'.join(lines))
|
||
print('报告已写入 %s' % OUT)
|
||
print('关键数字:校名重合 %.1f%% 专业码重合 %.1f%% (校,专业)重合 %.1f%%' % (
|
||
100 * len(sch_inter) / max(len(zgc_schools), 1),
|
||
100 * len(maj_inter) / max(len(zgc_majors), 1),
|
||
100 * len(pair_inter) / max(len(q_pairs), 1)))
|
||
|
||
|
||
if __name__ == '__main__':
|
||
main()
|