【问题标题】:Removing names from noun chunks in spacy从 spacy 中的名词块中删除名称
【发布时间】:2018-11-29 08:07:14
【问题描述】:

有没有办法删除名词块中的人名?

这里是代码

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

【问题讨论】:

    标签: python-3.x nlp spacy named-entity-recognition


    【解决方案1】:

    参考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
    

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 2020-06-22
      • 2023-03-15
      • 1970-01-01
      • 1970-01-01
      • 2019-02-19
      • 1970-01-01
      • 2016-02-11
      • 1970-01-01
      • 2014-04-10
      相关资源
      最近更新 更多