在我的论文中,我需要添加首字母缩略词列表。我想知道如何编程。我找到了很好的工具pdfgrep,它也得到了正则表达式。我用它以这样一种方式:如何在pdf文件中查找首字母缩略词
pdfgrep "([A-Z]+)" thesis.pdf
这是最好的正则表达式我已经找到了这个目的,但它也得到单大写字母。有没有人有更好的解决方案? 我写了一个Python代码与输出涉及:
import subprocess
import shlex
import re
FOLDER = 'full folder'
THESIS = '%s/thesis.pdf'%(FOLDER)
OUTPUT_FILE = '%s/acronymsInMyThesis.txt'%(FOLDER)
PATTERN = '([A-Z]+)'
def searchAcronymsInPDF():
output = pdfSearch()
acrs = []
for reg in re.findall(PATTERN, output):
reg.strip()
if (len(reg)>1):
acrs.append(reg)
return set(acrs)
def pdfSearch():
command = 'pdfgrep "%s" %s'%(PATTERN,THESIS)
output = shellCall(command)
return output
def shellCall(command):
p = subprocess.Popen(shlex.split(command), stdout=subprocess.PIPE)
out, _ = p.communicate()
return out
if __name__ == '__main__':
acrs = searchAcronymsInPDF()
print(acrs)
'[A-Z] [A-Z] +'?或'[A-Z] {2,}'?什么是你的缩写? “S.H.I.E.L.D.”吗?是'ToC'吗? –
这是一个很好的问题。我决定这将是至少2个大写字母的序列。但是,正如你所说,它不会抓住ToC。 –