如果我有一个类似于Why Is Raiden Punching Armstrong So Fascinating?的问题,我如何用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']如果我的问题似乎过于笼统,请原谅。
发布于 2022-02-02 17:43:31
句子的主语是正在做或正在做某事的名词。动词是执行动作或将主语与进一步的信息联系起来。直接宾语是接受动词的动作。
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 Armstronghttps://stackoverflow.com/questions/70956470
复制相似问题