参考文献移除
更新时间:2026-09-14
简介
参考文献移除算子:识别 LaTeX 文档里的参考文献 / 附录起始标记,把标记本身及其后到文末的内容整段删除。
功能描述
- 识别
appendix、begin{references}、begin{REFERENCES}、begin{thebibliography}、bibliography{...}五个标记,从标记本身开始一路删到文末(标记也删掉) - 正则以
re.DOTALL编译,尾部.*$跨行贪婪匹配,一次替换即清空到文末 - 无构造参数,行为完全固定
- 命中不到任何标记的文本原样返回;输入 None 的行返回 None;单行异常记日志并返回 None,不中断整批
算子参数
输入
| 输入 | 含义 |
|---|---|
| texts | 文本字符串数组 |
输出
| 输出 | 含义 |
|---|---|
| result | 删除参考文献段后的文本(string),输入 None 返回 None |
参数
无(__init__ 只接受透传给基类的 **kwargs)
注意事项
appendix是 LaTeX 的附录起始标记,不专指参考文献。带正文价值的附录同样会被整段删除,这是本算子的既定口径。- 删除范围是「标记到文末」,不是「到
end{...}」:intro begin{references} r end{references} more text的结果是intro,end{references}之后的正文一并丢失。 - 标记大小写只认
references与REFERENCES两种拼写,begin{References}不命中。
调用示例
Python
1from __future__ import annotations
2
3import os
4
5import daft
6from daft import col
7
8from daft.aihc.common.udf import aihc_udf
9from daft.aihc.functions.text.remove_bibliography import RemoveBibliography
10
11if __name__ == "__main__":
12 if os.getenv("DAFT_RUNNER", "native") == "ray":
13 import ray
14 ray.init(dashboard_host="0.0.0.0", ignore_reinit_error=True)
15 daft.set_runner_ray()
16 daft.set_execution_config(actor_udf_ready_timeout=6000, min_cpu_per_task=0)
17
18body = "\section{Intro}
19real content here
20"
21 samples = {
22 "texts": [
23 body + "\begin{thebibliography}{9}
24\bibitem{a} Foo
25\end{thebibliography}",
26 body + "\appendix
27appendix stuff",
28 "plain text without bibliography",
29 None,
30 ]
31 }
32 ds = daft.from_pydict(samples)
33 ds = ds.with_column(
34 "result",
35 aihc_udf(RemoveBibliography, construct_args={}, num_cpus=1, concurrency=1, batch_size=4)(col("texts")),
36 )
37 ds.show()
评价此篇文章
