- 全链路:多源JD接入/清洗交叉验证/结构化抽取(星火+离线双通道)/时序知识图谱/新岗位发现/演化分析/人岗匹配/学习路径 - WebUI 五视图:驾驶舱/图谱工作台/岗位演化/匹配(单人+批量)/学习路径 - 设置中心(config.json)/Token鉴权/SQLite状态库/语义向量通道(BGE-M3本地或联网API) - 71 个 pytest 用例;数据目录仅保留结构(.gitkeep),数据由 scripts/generate_dataset.py 复现
48 lines
1.6 KiB
Python
48 lines
1.6 KiB
Python
"""噪声过滤:识别广告尾注、无关条款等非岗位描述内容。"""
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
import re
|
|
|
|
from app.models import JDRecord
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
# 噪声特征:广告导流、扫码领资料、与岗位无关的商业条款等
|
|
NOISE_PATTERNS = [
|
|
r"扫码|点击关注|关注公众号|领取.{0,6}(资料|福利|红包)",
|
|
r"【广告】|推广信息|商务合作请加",
|
|
r"长期回收|代办|加盟代理|刷单",
|
|
r"内部推荐奖.{0,10}扫码",
|
|
]
|
|
_NOISE_RE = re.compile("|".join(NOISE_PATTERNS))
|
|
|
|
|
|
def is_noise(text: str) -> bool:
|
|
"""判断文本是否含有噪声内容。"""
|
|
return bool(_NOISE_RE.search(text))
|
|
|
|
|
|
def strip_noise_lines(text: str) -> str:
|
|
"""逐行剔除噪声行,保留正文(用于噪声行与正文混排的情况)。"""
|
|
kept = [ln for ln in text.splitlines() if ln.strip() and not is_noise(ln)]
|
|
return "\n".join(kept)
|
|
|
|
|
|
def filter_noise(records: list[JDRecord]) -> list[JDRecord]:
|
|
"""标记噪声记录:整条以噪声为主的记录 is_noise=True 并降权;混排的只剔除噪声行。"""
|
|
marked = 0
|
|
for r in records:
|
|
lines = [ln for ln in r.text.splitlines() if ln.strip()]
|
|
noisy = [ln for ln in lines if is_noise(ln)]
|
|
if not noisy:
|
|
continue
|
|
if len(noisy) >= max(1, len(lines) // 2):
|
|
r.is_noise = True
|
|
r.weight = round(r.weight * 0.1, 4)
|
|
marked += 1
|
|
else:
|
|
r.text = strip_noise_lines(r.text)
|
|
logger.info("噪声过滤:%d 条记录被标记为噪声", marked)
|
|
return records
|