Question

In: Computer Science

Put theory into practice by performing stopwords removal and text processing in Python using the popular...

Put theory into practice by performing stopwords removal and text processing in Python using the popular NLTK library.

1:Obtain number of lines from the above text and make each line to store in an element of array؟

This is my first program.

. We are the students of Master’s in Data Science, Hello! How are you?

We are here to learn the python script, this is it now.

Solutions

Expert Solution

To get the number of lines and store each sentence in an array as different array elements, we can use Sentence tokenization which is available as a sent_tokenize module in the NLTK library.

The code for counting the number of sentences from the given string is given below-

If you are using NLTK tokenization for the first time, use this script to install the tokenization package before executing the program-

import nltk
nltk.download('punkt')

This will download the package and save it for further usage.

The code for tokenization is -

from nltk.tokenize import sent_tokenize

text = "This is my first program. We are the students of Master’s in Data Science, Hello! How are you? We are here to learn the python script, this is it now."
sentences = sent_tokenize(text) #Save sentences as array elements
numSentences = len(sentences) #Count number of sentences

print(sentences)
print(numSentences)

OUTPUT -


Related Solutions

Python Project Description: Text Processing This assignment requires you to process a short text from an...
Python Project Description: Text Processing This assignment requires you to process a short text from an input file, perform some analyses, manipulate the text, and save the results in an output file. For example, the input file bentley.txt contains a brief introduction of Bentley University: Each line in this file is a paragraph that contains one or more sentences. Note that each line can be very long! The program will provide the following user interaction on the screen: · Ask...
Using c programming language How do you put data from a text file into a 2d...
Using c programming language How do you put data from a text file into a 2d array For example a text file with names and age: john 65 sam 34 joe 35 sarah 19 jason 18 max 14 kevin 50 pam 17 bailey 38 one 2d array should have all the names from the file and one 2d array should have all the ages and both arrays should be printed out separately and be 3x3
Describe your practicum goals and objectives using the seven domains of practice Discuss a nursing theory...
Describe your practicum goals and objectives using the seven domains of practice Discuss a nursing theory that would be used to guide your practice.
Describe your practicum goals and objectives using the seven domains of practice Discuss a nursing theory...
Describe your practicum goals and objectives using the seven domains of practice Discuss a nursing theory that would be used to guide your practice.
Please answer using python 3 and def functions! Lab 2 Drill 3: (function practice) create and...
Please answer using python 3 and def functions! Lab 2 Drill 3: (function practice) create and use a function named highest() that takes three inputs and returns the highest number. After you have got it working, try calling the function with inputs ‘hat’, ‘cat’, ‘rat’.
Read the Chapter 15 Mini Case on page 651-652 in Financial Management: Theory and Practice. Using...
Read the Chapter 15 Mini Case on page 651-652 in Financial Management: Theory and Practice. Using complete sentences and academic vocabulary, please answer questions a and b. If the company were to recapitalize, then the debt would be issued and the funds received would be used to repurchase stock. Pizza Palace is in the 40% state-plus-federal corporate tax bracket, its beta is 1.0, the risk-free rate is 6%, and the market risk premium is 6%. a. Using the free cash...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT