How to count the frequency of words existing in a text using nltk

前端 未结 1 1728
情书的邮戳
情书的邮戳 2021-01-29 01:04

I have a python script that reads the text and applies preprocess functions in order to do the analysis.
The problem is that I want to count the frequency of words but the s

相关标签:
1条回答
  • 2021-01-29 01:41

    Maybe this might help.

    import nltk
    text = "An an valley indeed so no wonder future nature vanity. Debating all she mistaken indulged believed provided declared. He many kept on draw lain song as same. Whether at dearest certain spirits is entered in to. Rich fine bred real use too many good. She compliment unaffected expression favourable any. Unknown chiefly showing to conduct no."
    tokens = [t for t in text.split()]
    freqs = nltk.FreqDist(tokens)
    blah_list = [(k, v) for k, v in freqs.items()]
    print(blah_list)
    

    This snippet counts the word frequency.

    Edit: Code is now working.

    0 讨论(0)
提交回复
热议问题