【问题标题】:How to extract names from the resume in python如何在python中从简历中提取姓名
【发布时间】:2020-09-01 06:23:20
【问题描述】:

我正在尝试提取简历的人名。我没有得到正确的输出。到目前为止我所做的是。

import en_core_web_sm
import spacy
import pdfplumber
nlp = en_core_web_sm.load()

nlp = spacy.load("en_core_web_sm")
pdf = pdfplumber.open('C:/Person.pdf')
page = pdf.pages[0]
doc = nlp(page.extract_text())
print([(X.text, X.label_) for X in doc.ents if X.label_ == 'PERSON'])

我的输出是:

[('Mohamme mohammed24@yahoo.com\n', 'PERSON'), ('Mangalore', 'PERSON'), ('Demo Design1', 'PERSON'), ('Demo Design2', 'PERSON'), ('Demo Design3', 'PERSON'), ('Java', 'PERSON')]

我尝试了很多东西,但无法获得唯一的名字。它包括许多东西,如技能、电子邮件等。

如何从简历示例技能、电话号码、姓名、工作年限、电子邮件中提取所有详细信息。

【问题讨论】:

    标签: python-3.x machine-learning nlp nltk named-entity-recognition


    【解决方案1】:

    使用 spacy 提取名字和姓氏

    我们首先定义了要在文本中搜索的模式。在这里,我们基于一个人的名字和姓氏始终是专有名词这一事实创建了一个简单的模式。因此,我们指定了 spacy 来搜索一个模式,使得两个连续词的词性标记等于 PROPN(专有名词)。

    import spacy
    from spacy.matcher import Matcher
    
    # load pre-trained model
    nlp = spacy.load('en_core_web_sm')
    
    # initialize matcher with a vocab
    matcher = Matcher(nlp.vocab)
    
    def extract_name(resume_text):
        nlp_text = nlp(resume_text)
        
        # First name and Last name are always Proper Nouns
        pattern = [{'POS': 'PROPN'}, {'POS': 'PROPN'}]
        
        matcher.add('NAME', None, [pattern])
        
        matches = matcher(nlp_text)
        
        for match_id, start, end in matches:
            span = nlp_text[start:end]
            return span.text
    

    【讨论】:

    • # 用词汇初始化匹配器 matcher = Matcher(nlp.vocab) def extract_name(resume_text): nlp_text = nlp(resume_text) # 名字和姓氏总是专有名词 pattern = [{'POS ': 'PROPN'}, {'POS': 'PROPN'}] matcher.add('NAME', None, *pattern) matches = matcher(nlp_text) for match_id, start, end in 匹配:span = nlp_text[start :end] return span.text pdf = pdfplumber.open('C:/ZuhairResume.pdf') page = pdf.pages[0] text = page.extract_text() extract_name(text) // 这里需要调用一个方法这是正确的。
    • 正确编写代码 - 我几乎不明白你的问题。此外,您只需编写上述代码并调用“extract_name()”函数即可从简历中获取姓名。
    • 我收到类似 ValueError: [E178] Invalid pattern 的错误。预期的 dicts 列表,但得到:{'POS': 'PROPN'}。也许您不小心将单个模式传递给 Matcher.add 而不是模式列表?如果您只想添加一个模式,请确保将其包装在一个列表中。例如:matcher.add('NAME', [pattern])
    • @sripandianman 听起来不错。我已编辑解决方案 - 如果解决方案帮助您考虑投票并选择正确答案。
    猜你喜欢
    • 2015-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-15
    • 2016-12-02
    • 1970-01-01
    • 1970-01-01
    • 2017-01-07
    相关资源
    最近更新 更多