首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我怎样才能找到问题的主题?

我怎样才能找到问题的主题?
EN

Stack Overflow用户
提问于 2022-02-02 13:26:39
回答 1查看 52关注 0票数 1

如果我有一个类似于Why Is Raiden Punching Armstrong So Fascinating?的问题,我如何用Raiden Punching Armstrong编程获得问题的主题?使用spacy对句子进行标记会产生以下结果:

代码语言:javascript
复制
import spacy
nlp = spacy.load('en_core_web_sm')
sentence = "Why Is Raiden Punching Armstrong So Fascinating?"
nlp_doc=nlp(sentence)
subject = [tok.dep_ for tok in nlp_doc]
print(subject) 
# ['advmod', 'ROOT', 'compound', 'compound', 'nsubj', 'advmod', 'nsubj', 'punct']

如果我的问题似乎过于笼统,请原谅。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-02-02 17:43:31

句子的主语是正在做或正在做某事的名词。动词是执行动作或将主语与进一步的信息联系起来。直接宾语是接受动词的动作。

代码语言:javascript
复制
import spacy
nlp = spacy.load('en_core_web_sm')
sentence = "Why Is Raiden Punching Armstrong So Fascinating?"
nlp_doc=nlp(sentence)

#I am taking propernoun, other nouns if any, and verb in the subject. It depends upon your sentence; we may skip the verb part in the subject.

for x in nlp_doc :
#here pos_ keyword is used for Parts Of Speech
if x.pos_ == "PROPN" or x.pos_ == "NOUN" or x.pos_ == "VERB":
  print(x, end=' ')

#output
Raiden Punching Armstrong
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70956470

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档