How to do it...

  1. Develop and import the following packages using Python:
import numpy as np 
from nltk.corpus import brown 
  1. Describe a function that divides text into chunks:
# Split a text into chunks 
def splitter(content, num_of_words): 
   words = content.split(' ') 
   result = [] 
  1. Initialize the following programming lines to get the assigned variables:
   current_count = 0 
   current_words = []
  1. Start the iteration using words:
   for word in words: 
     current_words.append(word) 
     current_count += 1 
  1. After getting the essential amount of words, reorganize the variables:
     if current_count == num_of_words: 
       result.append(' '.join(current_words)) 
       current_words = [] 
       current_count = 0 
  1. Attach the chunks to the output variable:
 result.append(' '.join(current_words)) ...

Get Raspberry Pi 3 Cookbook for Python Programmers - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.