目的:通過python將pubmed下載的摘要txt文檔,統計出其中的PMID數目,是否和文獻總篇數一致,一致的話,就可以利用PMID的regex pattern進行分割字符串為單篇摘要文獻。
import re
fname = '2020-01-14_endometriosis_2020-01-01_UTF8.txt'
with open(fname, "r", encoding = 'utf-8') as f:
abstracts = f.read()
str = abstracts
iList= re.findall(r"PMID: \d+ ",str)
print(len(iList)) # output: 6049,符合文檔中文獻的總篇數
iList= re.findall(r"PMID: \d+",str) # regex pattern中少一個空格
print(len(iList)) # output: 6050,結果比文檔中文獻總篇數多了一篇
