Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 如何在python中使用nltk从文本文件中提取姓氏_Python 3.x_Nltk - Fatal编程技术网

Python 3.x 如何在python中使用nltk从文本文件中提取姓氏

Python 3.x 如何在python中使用nltk从文本文件中提取姓氏,python-3.x,nltk,Python 3.x,Nltk,我想从简历中提取姓氏。它正确返回第一个名称,但第二个名称错误 如何解决此问题?您能提供您的输入文件示例吗?JAY PRATAP PANDEY Mobile:+91111111电子邮件:pratappandey7@gmail.com地点:印度新德里目标:确保一个既有挑战又有良好增长机会的有希望的职位。 import re import nltk from nltk.corpus import stopwords stop = stopwords.words('english') from nltk

我想从简历中提取姓氏。它正确返回第一个名称,但第二个名称错误


如何解决此问题?

您能提供您的输入文件示例吗?JAY PRATAP PANDEY Mobile:+91111111电子邮件:pratappandey7@gmail.com地点:印度新德里目标:确保一个既有挑战又有良好增长机会的有希望的职位。
import re
import nltk
from nltk.corpus import stopwords
stop = stopwords.words('english')
from nltk.corpus import wordnet

inputfile = open('file.txt', 'r')
String= inputfile.read()


def last_name(resume_text):
  tokenized_sentences = nltk.sent_tokenize(resume_text)
  a_list=[]
  for sentence in tokenized_sentences:
      a_list=(sentence.split())
      s1=a_list[1:]
      sentence1=''.join(s1)
      tokenized_sentences = nltk.sent_tokenize(sentence1)
      for sentence in tokenized_sentences:
          for chunk in nltk.ne_chunk(nltk.pos_tag(nltk.word_tokenize(sentence), tagset='universal')):
            if hasattr(chunk, 'label') and chunk.label() == 'PERSON':
              chunk = chunk[0]
            (name, tag) = chunk
            if tag == 'NOUN':
              return name
if __name__ == '__main__':
    lastname= last_name(String)
print(lastname)