Define a function percent(word, text) that calculates how often a given word occurs in a text and expresses the result as a percentage.
Question 2: (2 marks)
Write a Python NLTK program to split all punctuation into separate tokens.
Sample Output:
Original string:
Reset your password if you just can't remember your old one.
Split all punctuation into separate tokens:
['Reset', 'your', 'password', 'if', 'you', 'just', 'can', """, 't', 'remember', 'your', 'old', 'one', '']
Question 3: (3 marks)
Write a program to find all words with number of the letters less than 4 in the given text.With the help of a frequency distribution (FreqDist), show these words in decreasing order of frequency.
Example:
Input:
'He would also attend the opening ceremony for the construction of the U.S.Embassy complex in Cau Giay District, as well as meeting students, teachers and scientists at the Hanoi University of Science and Technology'
Output:
['Cau', 'He', 'and', 'as', 'at', 'for', 'in', 'of', 'the']
+ 100%
Zoom
Close