仅从格式为.tex的arXiv文章中提取正文文本


757461156
2025-03-16 12:17:35 (23天前)
  1. 我的数据集由arXiv天体物理学文章组成.tex文件,我只需从文章正文中提取文本,而不是从文章的任何其他部分(例如表格,图形,摘要,...

2 条回复
  1. 0# 猫南北 | 2019-08-31 10-32



    要从文档中获取所有文本,

    tree.descendants

    这里会更加友好。这将按顺序输出所有文本。




    1. def getText(section):
      for token in section.descendants:
      if isinstance(token, str):
      corpus.write(str(x))

    2. </code>


    为了捕捉边缘情况,我写了一个稍微更加丰富的版本。这包括检查您在那里列出的所有条件。




    1. from TexSoup import RArg

    2. def getText(section):
      for x in section.descendants:
      if isinstance(x, str):
      if x.startswith(‘$’) and x.endswith(‘$’):
      continue
      corpus.write(str(x))
      elif isinstance(x, RArg):
      corpus.write(str(x))
      elif hasattr(x, source’) and hasattr(x.source, name’) and x.source.name in (‘acknowledgements’, appendix’):
      return

    3. </code>

登录 后才能参与评论