Python NLTK: Bigrams trigrams fourgrams

前端 未结 4 1158
被撕碎了的回忆
被撕碎了的回忆 2020-12-25 14:16

I have this example and i want to know how to get this result. I have text and I tokenize it then I collect the bigram and trigram and fourgram like that

im         


        
4条回答
  •  借酒劲吻你
    2020-12-25 15:13

    from nltk.util import ngrams
    
    text = "Hi How are you? i am fine and you"
    
    n = int(input("ngram value = "))
    
    n_grams = ngrams(text.split(), n)
    
    for grams in n_grams :
    
       print(grams)
    

提交回复
热议问题