Python 3.x 如何从简历中提取学位/学历和年份?在python中使用NLTK

Python 3.x 如何从简历中提取学位/学历和年份?在python中使用NLTK,python-3.x,regex,pandas,nlp,nltk,Python 3.x,Regex,Pandas,Nlp,Nltk,我尝试过以下代码,但无法从简历中提取正确的学历和年份 import re from nltk.corpus import stopwords # load pre-trained model nlp = spacy.load('en_core_web_sm') # Grad all general stop words STOPWORDS = set(stopwords.words('english')) # Education Degrees EDUCATION = [

我尝试过以下代码,但无法从简历中提取正确的学历和年份

import re
from nltk.corpus import stopwords

# load pre-trained model
nlp = spacy.load('en_core_web_sm')

# Grad all general stop words
STOPWORDS = set(stopwords.words('english'))

# Education Degrees
EDUCATION = [
            'BE','B.E.', 'B.E', 'BS', 'B.S','C.A.','c.a.','B.Com','B. Com','M. Com', 'M.Com','M. Com .',
            'ME', 'M.E', 'M.E.', 'MS', 'M.S',
            'BTECH', 'B.TECH', 'M.TECH', 'MTECH',
            'PHD', 'phd', 'ph.d', 'Ph.D.','MBA','mba','graduate', 'post-graduate','5 year integrated masters','masters',
            'SSC', 'HSC', 'CBSE', 'ICSE', 'X', 'XII'
        ]

def extract_education(resume_text):
    nlp_text = nlp(resume_text)
    # Sentence Tokenizer
    nlp_text = [sent.string.strip() for sent in nlp_text.sents]
    edu = {}
    # Extract education degree
    for index, text in enumerate(nlp_text):
        #print(index, text), print('-'*50)
        for tex in text.split():
            # Replace all special symbols
            tex = re.sub(r'[?|$|.|!|,]', r'', tex)
            print(tex)
            if tex.upper() in EDUCATION and tex not in STOPWORDS:
                edu[tex] = text + nlp_text[index + 1]
                print(edu.keys())

print(extract_education(text)) #resume parsed into text
正文:

B.Tech Computer Science  -  2016, MSc Computer Science - 2018 and other text...... (focusing on degree part of resume)
上面的输出没有显示任何内容--

期望输出:

[[B.Tech, 2016], [MSc, 2018]]
有人能帮我纠正这个代码,并获取相应教育的通过年份吗? 提前谢谢

将字符串更改为文本:

[sent.text.strip() for sent in nlp_text.sents]
在last中添加
返回列表(edu.keys())
以返回度数列表

这将为您提供与我一样的学位名称,CBSE将字符串更改为文本:

[sent.text.strip() for sent in nlp_text.sents]
在last中添加
返回列表(edu.keys())
以返回度数列表


这将为您提供与我一样的学位名称,CBSE

请附上您的跑步成绩。一些示例,如您期望的内容和您得到的输出。@Mandy8055:请重新检查问题,并添加当前输出和期望输出以及示例文本。是否有帮助?不太可能……据我所知,正则表达式帮不了什么忙。因为如果我解析其他简历,那么它将无法获取它。因此,我们如何才能概括并获得所需的输出。请附上您的跑步结果。一些示例,如您期望的内容和您得到的输出。@Mandy8055:请重新检查问题,并添加当前输出和期望输出以及示例文本。是否有帮助?不太可能……据我所知,正则表达式帮不了什么忙。因为如果我解析其他简历,那么它将无法获取它。那么,我们如何才能概括并获得所需的输出呢。