Удаление имен из именных кусков в просторах - PullRequest
0 голосов
/ 29 ноября 2018

Есть ли способ удалить имя человека из существительных кусков?

Вот код

import en_vectors_web_lg
nlp = en_vectors_web_lg.load()
text = "John Smith is lookin for Apple ipod"
doc = nlp(text)
for chunk in doc.noun_chunks:
     print(chunk.text)

Токовый выход

John Smith
Apple ipod

Я хотел быиметь вывод, как показано ниже, где имя людей игнорируется.Как этого добиться?

Apple ipod

1 Ответ

0 голосов
/ 29 ноября 2018

Ссылка spaCy ents

import spacy
# loading the model
nlp = spacy.load('en_core_web_lg')
doc = nlp(u'"John Smith is lookin for Apple ipod"')
# creating the filter list for tokens that are identified as person
fil = [i for i in doc.ents if i.label_.lower() in ["person"]]
# looping through noun chunks
for chunk in doc.noun_chunks:
    # filtering the name of the person
    if chunk not in fil:
        print(chunk.text)

Вывод:

Apple ipod

Надеюсь, это поможет.

...