Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Text Analysis using Java Collections Framework There is some debate on influence

ID: 3831060 • Letter: T

Question

Text Analysis using Java Collections Framework


There is some debate on influence of Jane Austen on Charlotte Bronte work as a writer (and in generalon all three Bronte sisters’). If you are interested in finding more, feel free to google for their works andthe debate.  
For this exercise, using the publicly available books on Project Gutenberg (http://www.gutenberg.org),you are asked to find the top 10 words and number of times they occur in books by Charlotte Bronte butnot used by Jane Austen.
To simply this exercise, we will only use the following books:

Jane Austen

Charlotte Bronte

Pride and Prejudice
(http://www.gutenberg.org/files/1342/1342-0.txt)

Jane Eyre: An Autobiography
(http://www.gutenberg.org/cache/epub/1260/pg1260.txt)

Emma
(http://www.gutenberg.org/files/158/158-0.txt)

Villette
(http://www.gutenberg.org/cache/epub/9182/pg9182.txt)

Sense and Sensibility
(http://www.gutenberg.org/cache/epub/161/pg161.txt)

Shirley
(http://www.gutenberg.org/files/30486/30486-0.txt)

Persuasion
(http://www.gutenberg.org/cache/epub/105/pg105.txt)

The Professor
(http://www.gutenberg.org/files/1028/1028-0.txt)

Mansfield Park
(http://www.gutenberg.org/files/141/141-0.txt)


HashMap (or HashTree) Java Collection will come handy for finding and keeping the count of words. You are only allowed to use Java Collections as described in Chapter 11 of our class textbook.
Hint: refer to Word Count Map case study in Chapter 11.To receive full credit, submit the following:- Java source code file(s)- Nicely formatted report containing a table of top 10 words found in Charlotte Bronte’s books and not
in Jane Austen’s and their counts, and a summary of your insights from this exercise including how this type of analysis can be useful and any suggestions for improvements.

Explanation / Answer

import java.io.IOException;

import java.nio.file.Files;

import java.nio.file.Paths;

import java.util.ArrayList;

import java.util.Collections;

import java.util.HashMap;

import java.util.HashSet;

import java.util.Set;

/**

*

*/

public class TextBook {

         /**

        

         */

         public static void main(String[] args) {

                 ArrayList<String> words=new ArrayList<String>();

                

                 try {

// here you can give any text file path

//use this for getting the path of a file or book

                          for (String line : Files.readAllLines(Paths.get("http://www.gutenberg.org/files/1342/1342-0.txt"))) {

                                   for (String part : line.split("\s+")) {

                                       words.add(part);

                                   }

                          }

                          HighesOccuringChar(10,words);

                 }

                 catch (IOException e) {

                          e.printStackTrace();

                 }

         }

         public static void HighesOccuringChar(int n,ArrayList<String> words )

         {

                 HashMap<Integer,String> frequnencyofwords=new HashMap<>();

                 int counter=0;

                 for(String s:words)

                 {

                          counter=0;

                          for(String sub:words)

                                   if(s.equals(sub))

                                            counter++;

                          frequnencyofwords.put(counter,s);

                 }

                 Set<Integer> keys=frequnencyofwords.keySet();

                 ArrayList<Integer> sortedkeys=new ArrayList<Integer>(keys);

                 Collections.sort(sortedkeys);

                 for(int i=0;i<n;i++)

                 {

                          System.out.println(frequnencyofwords.get(sortedkeys.get(sortedkeys.size()-1-i)));

                 }

        

         }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote