在我的python任务中,我必须阅读一篇PDF文档,并获取所有引用及其计数(在本文中提到)This is the PDF as example它有18个参考文献,说参考文献1在论文中被提到了3次,参考文献2被提到了1次,所以这就是我想要的
Ref# Count Reference
1 3 Arto Anttila. 1995. How to recognise subjects in English. In Karlsson et al., chapt. 9, pp. 315-358.
2 1 Dekang Lin. 1996. Evaluation of Principar with the Susanne corpus. In John arroll, editor, Workshop on Robust Parsing, pages 54-69, Prague
...
我已经完成了列表中的Ref#和References,并且通过使用以下正则表达式,设法从包含引用的文本中获取行:
regex = re.compile(r'[A-Z]{1}[a-z\u0000-\u007F]+ \([0-9]{4}\)|\([A-Z]{1}[a-z\u0000-\u007F]+, [0-9]{4}\)|\([A-Z]{1}[a-z\u0000-\u007F]+, [0-9]{4}; [A-Za-z \u0000-\u007F,;]*\)|[A-Z]{1}[a-z\u0000-\u007F]+ \([0-9]{4},[A-Za-z0-9\u0000-\u007F ]*\)|[A-Z]{1}[a-z\u0000-\u007F ]+ [a-z]{2} [a-z]{2}. \([0-9]{4}\)')
所以,当我遍历字符串列表(由句子分割的文本)并使用以下代码查找上正则表达式时:
for i in range(0, len(lstString)):
refLine = re.findall(regex, lstString[i])
if(refLine != [] and refLine [0] != []):
print(refLine)
我得到如下输出:
(Karls- son et al., 1995)
Our work is partly based on the work done with the Constraint Grammar framework that was orig- inally proposed by Fred Karlsson
(1990)
(Tapanainen, 1996)
(Tapanainen, 1996) is dif- ferent from the former (Karlsson et al., 1995)
Hurskainen (1996)
In essence, the same formalism is used in the syn- tactic analysis in J~rvinen (1994) and Anttila (1995)
Our notation follows the classical model of depen- dency theory (Heringer, 1993) introduced by Lucien Tesni~re (1959) and later
advocated by Igor Mel'~uk (1987)
Hudson (1991)
(Hays, 1964)
(McCord, 1990; Sleator and Tem- perley, 1991; Eisner, 1996)
(Hudson, 1991)
(J~irvinen, 1994)
The CG-2 program (Tapanainen, 1996) runs a mod- ified disambiguation grammar of Voutilainen (1995)
(J~rvinen, 1994; Tapanainen and J/~rvinen, 1994)
(Eisner, 1996)
Dekang Lin (1996)
Acknowledgments We are using Atro Voutilainen's (1995)
它返回所有包含引用的字符串,但我遇到了如下问题
- It is not capturing Reference like this Karlsson et al. (1995)
- Some of these contains 2 reference in them
- How can I update count for each reference in reference list
我尝试了这段代码来获取每个ref的count,但它总是返回整个列表
matching = [s for s in lstRef if any(xs in s for xs in refLine)]
任何形式的帮助都将不胜感激
我想知道,如果从文档末尾的
References
中获取名称(和年份),并使用它们来搜索文档中的引用,该怎么办在上一个问题中,您得到的代码在文档末尾得到
References
使用regex
'((.*)\. (\d{4})\.
我可以将名称作为一个字符串获取,将年份作为一个字符串获取(最终将两者都作为一个字符串获取)即
使用next regex
',[ ]*and |,[ ]*| and '
我可以将具有名称的字符串拆分为名称列表使用普通的
split(" ")
我可以得到比全名更有用的姓氏(姓氏)即
现在我可以使用这些名字(或者更确切地说是姓氏)和年份来生成像
surname (year)
,surname, year
这样的字符串,然后在文档中搜索如果有很多姓氏,那么我可以得到第一个姓氏并生成
surname et al. (year)
,等等使用这些字符串和标准字符串函数
text.count(generated_string)
我可以计算它们目前这是我的全部,但仍然不理想
您可以手动查找文档中的所有引用,并使用它们来测试代码。你会看到哪一个被正确计算,哪一个需要更多的改变
例如,在文本
We are using Atro Voutilainen's (1995)
中有对's
的引用。也许应该使用nltk像NLP
(自然语言处理)中那样清理文档一些本机字符产生问题-名称
Järvinen
在一个位置提取为J~rvinen
,在另一个位置提取为J/irvinen
名称提取的结果:
计数结果:
相关问题 更多 >
编程相关推荐