newsname-match.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:newsname-match 作者: bahadasx 项目源码 文件源码
def performNameExtraction(text):
    #Returns a list of what NLTK defines as persons after processing the text passed into it.
    try:
        entity_names = []
        for sent in nltk.sent_tokenize(text):
            for chunk in nltk.ne_chunk(nltk.pos_tag(nltk.word_tokenize(sent))):
                if hasattr(chunk, 'label') and chunk.label:
                        if chunk.label() == 'PERSON':
                        name_value = ' '.join(child[0] for child in chunk.leaves())
                        if name_value not in entity_names:
                            entity_names.append(name_value)
    except:
        print "Unexpected error:", sys.exc_info()[0]
    return entity_names
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号