How to identify the subject of a sentence?

前端 未结 6 1606
我在风中等你
我在风中等你 2020-12-14 18:53

Can Python + NLTK be used to identify the subject of a sentence? From what I have learned till now is that a sentence can be broken into a head and its dependents. For e.g.

6条回答
  •  死守一世寂寞
    2020-12-14 19:35

    You can use Spacy.

    Code

    import spacy
    nlp = spacy.load('en')
    sent = "I shot an elephant"
    doc=nlp(sent)
    
    sub_toks = [tok for tok in doc if (tok.dep_ == "nsubj") ]
    
    print(sub_toks) 
    

提交回复
热议问题