[Solved]-Use Text File Ascii Automotive5txt Exercise Little 14mb Size Initial Work Find Words Autom Q37268166
Use the text file (in ASCII) Automotive_5.txt for this exercise.It is a little over 14MB in size. Your initial work is to find allwords in the Automotive file that are good in the dictionary(ignore the rest). I have attached the standard EnglishWordList.txtas our reference dictionary and the SpellChecker.java that you canuse for this purpose. Please make sure to convert every word intolowercase and get rid of punctuations if present. The code givendoes it but use it wisely. Your main goal is to find the top fivemost frequently occurring words in the Automotive file and top fiveleast frequently occuring words in the Automotive file that arelegit (with respect to the dictionary) and not obvious words (suchas “the”, “an”, etc.) that are in the attached stop_words.txt. Ihave given a file of obvious words called stop_words.txt thatshould not be considered for printing out the most frequently orleast frequently occuring words. Use efficient data structures.
PRIMITIVE EDITORimport java.util.*;import java.io.*;public class PrimitiveJavaEditor {PrintWriter printWriter=null; public boolean find (String x) { String word; ListIterator<String> itr = ReadFiles.textFile.listIterator(); while (itr.hasNext()){ word= itr.next().trim(); //word= word.replaceAll(“[[]_:”‘`?;0-9;()-/.,*! ]”, “”).toLowerCase(); // System.out.println(word); if (word.equals(x)) { return true; } } return false; } // Looks for a word “x” in the file and returns true if found or false otherwise.public boolean findReplace (String find, String replace) { int index; index = ReadFiles.textFile.indexOf(find); if (index != -1) { String prev = ReadFiles.textFile.set(index,replace); return true; } else return false; } // looks for the first occurrence of word “x” in the file and replaces it with word “y” if found returning true, false otherwise.public boolean findInsert (String find, String insert) { // looks for the first occurrence of word “x” in the file and then insert “y” right after “x”, if x is found, returning true, false otherwise. int index; index = ReadFiles.textFile.indexOf(find); if (index != -1) { ReadFiles.textFile.add(index+1,insert); return true; } else return false; } public boolean delete (String del) { // looks for the first occurrence of word “x” in the file and deletes it from the file, returning true if x is found, returning false otherwise. return (ReadFiles.textFile.removeFirstOccurrence(del)); } public String spellCheck () { // finds the first occurrence of spelling error and returns the misspelled word. If no word is misspelled returns “Spell Check Passed”. String word; ListIterator<String> itr = ReadFiles.textFile.listIterator(); while (itr.hasNext()){ word= itr.next().trim(); // word= word.replaceAll(“[[]_:”‘`?;0-9;()-/.,*! ]”, “”).toLowerCase(); if (!ReadFiles.wordList.contains(word)) return word; } return “no spelling errors”; } public void spellCheckAll() {// find all misspelled words and output them to the screen. String word; boolean spellPass=true; ListIterator<String> itr = ReadFiles.textFile.listIterator(); while (itr.hasNext()){ word= itr.next().trim(); //word= word.replaceAll(“[[]_:”‘`?;0-9;()-/.,*! ]”, “”).toLowerCase(); // word=word.replaceAll(“[]”,””); // System.out.println(word); if (!ReadFiles.wordList.contains(word)) {System.out.println(word); spellPass=false; } } if (spellPass) System.out.println(“no misspelled words, spellcheck passed “); } public void save() { // saves file with the changes made ListIterator itr = ReadFiles.textFile.listIterator(); int count=0; try { printWriter = new PrintWriter (new FileWriter (“newTextFile.txt”)); while (itr.hasNext()){ printWriter.print(itr.next()); count++; if (count % 10 ==0) printWriter.print (“n”); } } catch (IOException e) { System.out.println(e); } // } printWriter.close(); } public void print() // saves file with the changes and outputs the contents of the file to the screen. { this.save(); Scanner sc; try { sc = new Scanner(“newTextFile.txt”); while (sc.hasNext()) System.out.println(sc.nextLine()); } catch (Exception e) { System.out.println(e); } } public void quit() { save(); } public boolean findReplaceAll(String x, String y) { boolean found=false; int index=0; ListIterator<String> itr = ReadFiles.textFile.listIterator(); while (itr.hasNext()){ String word= itr.next().trim(); if (word.equals(x)) { ReadFiles.textFile.set(index,y); found=true; index++; } } return found; }}
READFILES
import java.util.*;import java.io.*;public class ReadFiles { Scanner fileScanner; static LinkedList<String> textFile; static ArrayList<String> wordList; String dictionaryFile = “EnglishWordList.txt”; String textFileName =”alcott-little-261.txt”; public ReadFiles () { fileScanner=null; textFile = new LinkedList<>(); wordList = new ArrayList<>(); } public void readTextFile() { String line=null; //String[] words; try { fileScanner = new Scanner (new File (textFileName)); while (fileScanner.hasNext()) { line = fileScanner.nextLine(); String[] words=line.split(” “); for (int i=0;i<words.length;i++) { String s = words[i].replaceAll(“[[]_:”‘`?;â€0-9—;“()-/.,*! ]”, “”).trim().toLowerCase(); if (!s.isEmpty())textFile.add(s); } } } catch (IOException e) { System.out.println(e); } } public void readDictionary() { String word=null; try { fileScanner = new Scanner (new File (dictionaryFile)); while (fileScanner.hasNext()) { word = fileScanner.nextLine(); wordList.add(word); } } catch (IOException e) { System.out.println(e); } } }
Expert Answer
Answer to Use the text file (in ASCII) Automotive_5.txt for this exercise. It is a little over 14MB in size. Your initial work is … . . .
OR

