import re
import spacy
import nltk
from nltk.corpus import stopwords
stop = stopwords.words('english')
from nltk.corpus import wordnet
inputfile = open('file.txt', 'r')
String= inputfile.read()
nlp = spacy.load('en_core_web_sm')
def candidate_name_extractor(input_string, nlp):
input_string = str(input_string)
doc = nlp(input_string)
print(doc)
# Extract entities
doc_entities = doc.ents
#print(doc_entities)
# Subset to person type entities
doc_persons = filter(lambda x: x.label_ == 'PERSON', doc_entities)
doc_persons = filter(lambda x: len(x.text.strip().split()) >= 2, doc_persons)
doc_persons = list(map(lambda x: x.text.strip(), doc_persons))
candidate_name = doc_persons[0]
return candidate_name
if __name__ == '__main__':
names = candidate_name_extractor(String, nlp)
print(names)
이 프로그램을 실행하면 print nlp(input_string)
이 정상적으로 작동합니다. 그러나 라인 "doc_entities=doc.ents"
,왜 함수를 호출 할 때 .ents가 적절한 방법으로 작동하지 않습니다.
- 그것은 이름 모바일 및 이메일과 나는 그것에서 이름을 추출 할를 포함하는 상위 세 가지 라인을 제거를 실행할 때.
어디에 문제가 어느 "doc_entities = doc.ents"
는 적절한 방법 또는 무엇에 작동하지입니까?
어떻게 우리가 말없이이 디버깅 제안 않는 입력을 문자열 또는'nlp'? – erip
다시 말하지만,'file.txt'가 어떻게 생겼는지 전혀 모르겠습니다. – erip
@erip 그것은 나의 CV의 텍스트 파일이다 –