python nltk — stemming list of sentences/phrases

后端 未结 1 1748
Happy的楠姐
Happy的楠姐 2021-01-23 06:48

I have bunch of sentences in a list and I wanted to use nltk library to stem it. I am able to stem one sentence at a time, however I am having issues stemming sentences from a l

相关标签:
1条回答
  • 2021-01-23 07:03

    You're passing a list to word_tokenize which you can't.

    The solution is to wrap your logic in another for-loop,

    data_list = ['the gamers playing games','higher scores','sports']
    for words in data_list:
        words = tokenize.word_tokenize(words)
        for w in words:
            print(ps.stem(w))
    
    >>>>the
    gamer
    play
    game
    higher
    score
    sport
    
    0 讨论(0)
提交回复
热议问题