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

Java programing A concordance is a unique list of words for a given document alo

ID: 3763765 • Letter: J

Question

Java programing

A concordance is a unique list of words for a given document along with the frequencies of occurrence for each word. You are to design and develop an application which will create a concordance with frequencies for given text document and output the results, sorted either alphabetically or by frequencies (user specified).

Test your program with the following flat text files
      . Obama (2009) inaugural address
      . Buch (2005) inaugural address
      . Pride and Prejudice by Jane Austen
      . Communist Manifesto by Engels and Marx
      . The Holy Bible - King James Version
      . Huckleberry Finn by Mark Twain

Program requirements:

     A “Concordance” class - that contains: the unique word list, frequency for each word, total word count, a unique word total, a source input file reference, a method for populating frequencies, methods for constructing, sorting and reporting the concordance,…….

    A “TestConcordance” class for running the concordances.

   Arguments will be passed to the main method (in TestConcordance) using command line arguments with parameters for: 1) file containing the text, 2) alpha vs. numeric sort report (possibly a or n). java program

Explanation / Answer

import java.util.*; mport java.io.*; /** * Generates and prints a concordance from a text document written in English. */ public class Concordance { /** * Stores lowercase English words as keys and the related Word objects as values. Each value can be used to extract the frequency of the word and the sentence numbers in which it appeared. The TreeMap will store the keys in alphabetical order by default as they are lowercase. */ private static TreeMap word_map = new TreeMap(); /** * The current sentence number in the document being read. */ private static int sentenceNumber = 1; /** * A String representation of the contents of the document. */ private static String fileContent = ""; /** * The length of the String representation of the document. */ private static int length = fileContent.length(); /** * The current index of the String representation of the document. */ private static int currentIndex = 0; /** * Scans the String representation of the document, stores each word in the concordance and records the word's frequency and the sentence numbers in which it appeared. */ private static void createConcordance(){ while(currentIndex aa-zz, and so on. * @param num the integer value which needs to be translated * @return the alphabetical value of the number */ private static String getAlpha(int num) { StringBuffer result = new StringBuffer(); num--; //so 1 => 'a', not 0 => 'a' int remainder = (num) % 26; char digit = (char) (remainder + 97); //add to unicode value of 'a' for(int i = num/26; i>=0; i--) { result.append(digit); //keep inserting the same digit } return result.toString(); } /** * Opens a file and converts its contents to a String. */ private static void fileToString(String fileName) { try{ StringBuffer str = new StringBuffer(); Scanner reader = new Scanner(new File(fileName)); while(reader.hasNext()) str.append(reader.nextLine()); reader.close(); fileContent = str.toString(); } catch (FileNotFoundException ex){ ex.printStackTrace(); } } /** * Creates and prints a concordance of a text document written in English. */ public static void main(String args[]) { fileContent = "Given an arbitrary text document written in English, write a program that will generate a concordance, i.e. an alphabetical list of all word occurrences, labeled with word frequencies. Bonus: label each word with the sentence numbers in which each occurrence appeared."; createConcordance(); printConcordance(); } } class Word { /** * The String representation of the Word. */ private String value; /** * The frequency of the value of the Word. */ private int count; /** * The sentence numbers in which the value of the Word has appeared. */ private LinkedList sentenceNumbers; /** * Creates a new Word. The value should be the English representation of the Word. */ public Word(String s) { this.value = s; this.sentenceNumbers = new LinkedList(); } /** * Adds the sentence number in which the Word's value has appeared. * @param num an integer representation of a sentence in which this Word's value has appeared. */ public void addSentenceNumber(int num) { this.sentenceNumbers.add(num); } /** * Increments this Word's frequency by 1. */ public void incrementCount() { this.count++; } /** * Gets the value of the Word. * @return this Word's value. */ public String getWord() { return this.value; } /** * Gets the sentence numbers in which the Word has appeared. * @return this Word's sentence numbers. */ public LinkedList getSentenceNumbers() { return this.sentenceNumbers; } /** * Gets the frequency of the Word. * @return the number of times this Word's value has appeared. */ 1.2.}
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