Python | NLTK nltk.tokenize.ConditionalFreqDist()
With the help of nltk.tokenize.ConditionalFreqDist() method, we are able to count the frequency of words in a sentence by using tokenize.ConditionalFreqDist() method.
Syntax :
tokenize.ConditionalFreqDist()
Return : Return the frequency distribution of words in a dictionary.
Example #1 :
In this example we can see that by using tokenize.ConditionalFreqDist() method, we are able to count the occurrence of words in a sentence.
# import ConditionalFreqDist() method from nltk from nltk.probability import ConditionalFreqDist from nltk.tokenize import word_tokenize # Create a reference variable for Class SExprTokenizer tk = ConditionalFreqDist() # Create a string input gfg = "Geeks for Geeks" for word in word_tokenize(gfg): condition = len(word) tk[condition][word] += 1 print(tk) |
Output :
FreqDist({‘Geeks’: 2, ‘for’: 1})
Example #2 :
# import ConditionalFreqDist() method from nltk from nltk.probability import ConditionalFreqDist from nltk.tokenize import word_tokenize # Create a reference variable for Class SExprTokenizer tk = ConditionalFreqDist() # Create a string input gfg = "G F G" for word in word_tokenize(gfg): condition = len(word) tk[condition][word] += 1 print(tk) |
Output :
FreqDist({‘G’: 2, ‘F’: 1})
Recommended Posts:
- Python NLTK | nltk.tokenizer.word_tokenize()
- Python NLTK | nltk.tokenize.StanfordTokenizer()
- Python NLTK | nltk.tokenize.SpaceTokenizer()
- Python NLTK | nltk.tokenize.LineTokenizer
- Python NLTK | nltk.tokenize.SExprTokenizer()
- Python NLTK | nltk.tokenize.TabTokenizer()
- Python NLTK | nltk.tokenize.mwe()
- Python NLTK | nltk.TweetTokenizer()
- Python NLTK | nltk.WhitespaceTokenizer
- Python | Lemmatization with NLTK
- Python | Gender Identification by name using NLTK
- Python NLTK | tokenize.WordPunctTokenizer()
- Python NLTK | tokenize.regexp()
- Python | Stemming words with NLTK
- Tokenize text using NLTK in python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : ManasChhabra2

