How can I find the subject matter of a question?
Question:
If I were to have a question like
Why Is Raiden Punching Armstrong So Fascinating?
, how could I get the subject matter of the question (Raiden Punching Armstrong
) programmatically using Python? Using spacy
to tokenize the sentence yields the following:
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']
Apologies if my question seems to be too general.
Answers:
The subject of the sentence is the noun that is doing or being something. The verb is carrying out the action or linking the subject to further information. And the direct object is receiving the action of the verb.
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
If I were to have a question like
Why Is Raiden Punching Armstrong So Fascinating?
, how could I get the subject matter of the question (Raiden Punching Armstrong
) programmatically using Python? Using spacy
to tokenize the sentence yields the following:
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']
Apologies if my question seems to be too general.
The subject of the sentence is the noun that is doing or being something. The verb is carrying out the action or linking the subject to further information. And the direct object is receiving the action of the verb.
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