必须同意“使我的代码更好”这个网站不太适合的建议,但是我可以为您提供一些 尝试的 途径。
看看斯坦福命名实体识别器(NER)。它的绑定已包含在NLTK v
2.0中,但是您必须下载一些核心文件。这是可以为您完成所有操作的脚本。
我写了这个脚本:
import nltkfrom nltk.tag.stanford import NERTaggerst = NERTagger('stanford-ner/all.3class.distsim.crf.ser.gz', 'stanford-ner/stanford-ner.jar')text = """YOUR TEXT GOES HERE"""for sent in nltk.sent_tokenize(text): tokens = nltk.tokenize.word_tokenize(sent) tags = st.tag(tokens) for tag in tags: if tag[1]=='PERSON': print tag并没有那么糟糕的输出:
(’Francois’,’PERSON’)(’R.’,’PERSON’)(’Velde’,’PERSON’)(’Richard’,’PERSON’)(’Branson’,’PERSON’)(’Virgin’
,’PERSON’)(’Galactic’,’PERSON’)(’Bitcoin’,’PERSON’)(’Bitcoin’,’PERSON’)(’Paul’,’PERSON’)(’Krugman’,’PERSON’)
(’Larry’,’PERSON’)(’Summers’,’PERSON’)(’Bitcoin’,’PERSON’)(’Nick’,’PERSON’)(’Colas’,’PERSON’)
希望这会有所帮助。



