【问题标题】:Spacy, noun phrases: How to locate noun phrase span start and end token of every noun_chunk in doc with spacySpacy,名词短语:如何使用 spacy 定位 doc 中每个 noun_chunk 的名词短语跨度开始和结束标记
【发布时间】:2020-04-07 15:49:51
【问题描述】:

我正在使用 spacy 来获取文本的名词短语。 我想要做的是根据单词的标记索引在文本中找到那些名词短语。

例如

import spacy

# Load English 
nlp = spacy.load("en_core_web_sm")
doc = nlp("The blue car is nicer than the white car"
noun_chunks = list(doc.noun_chunks)

for i,noun_chunk in enumerate(noun_chunks):
    for j,token in enumerate(noun_chunk):
        print(i,noun_chunk,j,token.text)

值j是名词块范围内token.text的索引,但我想获取名词块的第一个和最后一个单词的token.i编号

在示例中,两个名词块是: “红色汽车” 和 “白车”

期望的输出是:

代币: 1 蓝色 2 3号车 是 4 更好 5 超过 6 7 白色 8 9号车

名词块 1:“蓝色汽车”;开始 1,结束 3

名词块 2:“白车”; 7 开始,9 结束

通过名词块的开头和结尾,我将能够识别文档中名词块的跨度

谢谢

【问题讨论】:

    标签: nlp token spacy chunks phrase


    【解决方案1】:

    我不知道块的开始和结束方法

    chunk.start 为您提供块跨度的起始标记号 chunk.end 为您提供块跨度的结束标记号

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-23
      • 1970-01-01
      • 1970-01-01
      • 2019-02-19
      • 1970-01-01
      • 1970-01-01
      • 2017-03-09
      • 2016-12-30
      相关资源
      最近更新 更多