自建库检测
checkType=pf(默认比对全网库)或checkType=pf_custom(仅比对自建库)。多格式处理方案
Free Spire.PDF for Java(免费版支持前 10 页转换)或pdflayer API(支持 HTML/PDF 互转)67;python-pptx和pandas库提取文本内容。批量检测与效率优化
concurrent.futures)提升并发处理能力。获取 API 凭证
apiKey和apiSecret。开发环境配置
pip install requests python-dotenv(用于管理 API 凭证)。文档预处理
提交检测任务 import requests from dotenv import load_dotenv import os load_dotenv()
# 加载环境变量 def submit_document(file_path, title, author):
url = os.getenv("SUBMIT_URL")
files = {"doc": open(file_path, "rb")}
data = { "title": title, "author": author,
"checkType": "pf_custom", # 仅比对自建库
"apiKey": os.getenv("API_KEY"),
"apiSecret": os.getenv("API_SECRET") }
response = requests.post(url, files=files, data=data) result = response.json() if result["error_no"] == 0: return result["data"] # 返回task_id else:
raise Exception(f"提交失败:{result['message']}")
查询检测结果 def query_results(task_ids):
url = os.getenv("QUERY_URL")
data = { "task_id_list": ",".join(task_ids),
"apiKey": os.getenv("API_KEY"),
"apiSecret": os.getenv("API_SECRET") } response = requests.post(url, data=data)
result = response.json()
if result["error_no"] == 0:
return result["data"] else:
raise Exception(f"查询失败:{result['message']}")
完整流程示例 def batch_check(documents):
task_ids = [] # 提交所有文档 for doc in documents:
task_id = submit_document(doc["path"], doc["title"], doc["author"])
task_ids.append(task_id)
print(f"提交成功:{doc['title']},任务ID:{task_id}")
# 分批次查询结果 batch_size = 10
for i in range(0, len(task_ids), batch_size):
batch = task_ids[i:i+batch_size]
results = query_results(batch)
for res in results:
print(f"文档:{res['title']},重复率:{res['similar']}")
if res["check_status"] == 3:
download_report(res["check_result"]) # 下载报告函数
报告解析
check_result字段获取 ZIP 报告地址,下载后解压得到 HTML/PDF 报告。BeautifulSoup提取具体重复内容:python
from bs4 import BeautifulSoup def parse_report(report_path): with open(report_path, "r", encoding="utf-8") as f: soup = BeautifulSoup(f.read(), "html.parser") duplicates = soup.find_all("div", class_="duplicate-block") for dup in duplicates: print(f"重复片段:{dup.text.strip()}")数据持久化
task_id, title, author, similar, check_time, report_url。安全增强措施
requests库设置verify=True验证证书。apiKey和apiSecret存储在环境变量或 Kubernetes 机密中,禁止硬编码。检测策略定制
exclude_words排除特定词汇(如企业名称、产品型号),避免误判。集成与自动化
制造业:知识库优化
金融机构:研报原创性保障
医疗行业:病历质量提升
问题场景 | 解决方案 |
|---|---|
文档格式不支持 | 使用Free Spire.PDF将 PDF 转 Word,或通过pdflayer API将 HTML 转 PDF |
需要本地部署自建库 | 可联系对接商务进行报价 |
检测结果不准确 | 调整checkType参数(如同时比对自建库 + 全网库),或提交样例文档至技术支持优化算法 |
通过以上方案,企业可快速实现内部文档检测的自动化与智能化,在保护商业创意、提升内容质量的同时,降低 70% 以上的人工审核成本。建议优先从核心业务文档(如合同、研报、产品说明书)入手,逐步扩展至全企业内容管理。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。