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



如果我有这样的问题Why Is Raiden Punching Armstrong So Fascinating?,如何使用Python以编程方式获得问题的主题(Raiden Punching Armstrong(?使用spacy对句子进行标记产生以下结果:

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']

如果我的问题太笼统,我深表歉意。

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

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

相关内容

  • 没有找到相关文章

最新更新