【问题标题】:How to split in Spacy using doc phrase and extract a specific word如何使用文档短语在 Spacy 中拆分并提取特定单词
【发布时间】:2021-09-22 09:30:59
【问题描述】:

我有 5 个短语。例如:

phrase(Text:'bla bla bla') | phrase(Text:'bla bla bla')|

我需要获取文本标签之后的内容 - 在本例中为“bla bla bla”。所以我考虑过使用拆分,但没有 readline 是不可能的。那么如何提取呢?目前我得到了 5 个空列表。

我想要一行“bla bla bla| bla bla bla|...”。

en_nlp = spacy.load("en_core_web_sm")
en_nlp.add_pipe("textrank", config={ "stopwords": { "word": ["NOUN"] } })
doc = en_nlp(text)
tr = doc._.textrank

for phrase in doc._.phrases[:5]:
     print(phrase, end=" | ")

for phrase in doc._.phrases[:5]:    
    print(re.findall(r'Phrase\(Text:([^()]+)\)', text)) 

【问题讨论】:

  • 听起来最好用reimport re 并使用print(re.findall(r'phrase\(Text:([^()]+)\)', text_string))
  • text_string 应该是什么?它没有将 doc._.phrases[:5] 作为字符串
  • 你有text
  • forphrases in doc._.phrases[:5]: print(re.findall(r'phrase(Text:([^()]+))', text)) 这样我得到了 5 个空列表
  • 您不需要for phrase in doc._.phrases[:5]:。只有一个text。你不需要 pandas 也不需要 spacy。

标签: pandas numpy split nlp spacy


【解决方案1】:

显然,我只需要在循环中使用phrase.text,现在它就可以工作了。

print(phrase.text, end=" | ")

【讨论】:

  • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
猜你喜欢
  • 2017-11-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多