【问题标题】:In spaCy is there a way to extract the sentence the entity has been extracted from?在 spaCy 中,有没有办法提取提取实体的句子?
【发布时间】:2019-11-03 18:57:24
【问题描述】:

考虑以下句子:

“敏捷的棕狐跳过懒狗”

如果我想提取棕色,只提取棕色相当容易,但是我想要以下输出:

"brown" , "敏捷的棕色狐狸跳过懒狗"

【问题讨论】:

    标签: python spacy named-entity-recognition


    【解决方案1】:

    是的,在 Spacy 中有一种方法可以做到这一点。您必须遍历实体 Span 对象并从每个 Span 对象中提取句子。这是一个例子:

        doc = nlp("John and Claire live in London. They have a dog. Claire walks her 
        dog everyday.")
        for entity in doc.ents:
           print('Entity extracted : ', entity.text)
           print('Sentence extracted from : ', entity.sent)
    
    

    这应该会给你以下输出:

    Entity extracted :  John
    Sentence extracted from :  John and Claire live in London.
    
    Entity extracted :  Claire
    Sentence extracted from :  John and Claire live in London.
    
    Entity extracted :  London
    Sentence extracted from :  John and Claire live in London.
    
    Entity extracted :  Claire
    Sentence extracted from :  Claire walks her dog everyday.
    
    Entity extracted :  everyday
    Sentence extracted from :  Claire walks her dog everyday.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-03
      • 1970-01-01
      • 2020-10-27
      • 2013-07-20
      • 2020-12-16
      • 2019-06-07
      相关资源
      最近更新 更多