Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a Scala program in the functional programming (FP) style, to read in a text file, analyse the text, and produce the following output on

Write a Scala program in the functional programming (FP) style, to read in a text file, analyse the text, and produce the following output on the console (i.e. on standard output using print, println, etc.) You can choose to present the output in any format you wish, provided that the information is presented clearly. NB: Make sure you put appropriate supporting comments in your code so that anyone reading it can understand your algorithms easily. If necessary, include in your comments any important assumptions that you make. The output from your program should include each of the following.

1) Output the word (or list of words) that occurs the most times in the text file (irrespective of case i.e. word and Word are treated the same for this purpose). We are only interested in words that contain alphabetic characters [A-Z a-z], so ignore any digits (numbers), punctuation, etc. If there are several words that occur most often with equal frequency then all these words should be printed as a list. Alongside the word(s) you should output the number of occurrences. For example: The word(s) that occur most often are [and, it, the] each with 10 occurrences in the text.

2) Output the length of the longest word(s). For example: The longest word(s) in the text are [juxtaposition, possibilities] each with 13 characters.

3) Output the pairs of consecutive words that occur in the text most often. By pairs of consecutive words we are referring to two words that occur one after the other in the text. For example (output, the), (the, pairs), (pairs, of), and so on. For the purpose of this algorithm we ignore the case of characters in the words (and any punctuation). For example: The pairs of words that occur most often are [(in, the), (over, and)]. Each of these pairs of words occurs 8 times in the text.

4) Output any pairs of words in the text that are the mirror image of each other. For example, if the text contains the word pan, and at any other place the word nap occurs, then this pair of words are mirror images of each other (nap, pan). The output should contain all such pairs of mirror-image words that appear in the text. For example: The following pairs of mirror-image words appear in the text: [(on, no), (nap, pan), (parts, strap)]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Building The Data Lakehouse

Authors: Bill Inmon ,Mary Levins ,Ranjeet Srivastava

1st Edition

1634629663, 978-1634629669

More Books

Students also viewed these Databases questions

Question

How successful have your efforts to diversify been?

Answered: 1 week ago

Question

Guidelines for Informative Speeches?

Answered: 1 week ago