Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In java please. And use these classes. The purpoee of this aseignment is to guin familiarity with dictionaries. A homophone is one of two or
In java please. And use these classes.
The purpoee of this aseignment is to guin familiarity with dictionaries. A homophone is one of two or more words that are pronounced alike but are different in meaning or spellingi for example, the words "two", "too", and "to". Write a Java program that uses one of the implementations of the dietionary interface that we have discused to find the largest set of words that are homophonts. Use only UALDictionary or OAL.Dictionary, and do not use data struetures that we have not covered so far in the conarie (for example hash maps or sorting algorithms other than insertiot sort or sedection wort). The file "cmudict.0.7a.txt" on Vocareum contains a prominciation dietionary downloaded from http://uvu. apeech. cs. cnu, edu/cgi-bin/cnadict The page also contains a drtaikd description of the pronunciation dictionary. The file consists of lines of the form ABUNDANT AHO B AHI BD AHO B T The first string is the word, which is followed by one or more phonemies (or phones) that describe the pronunciation of the word. There are 39 phonemes oceurring in North American English that are ueed in the dictionary. The colleetion of 39 symbols is known as the Arpotet, for the Advanced Remearch Projects Afency (ARPA), which developed it in the 1970 's in connection with fecarch on sperch undentanding. The starter code on Vocareum contains several fles you can use. UALDiotionaryjawa is a clas that implements the dictionsry interface uxing an unordered array list. OALDictionary java is a class that implements the dictionary interface using an otdered array list. The array list stores (key, value) pais ass described in the class KVpair.java. Pronumeiation.java is a class that atotrs and manage acceses to a (word, phonemes) pair. There is also a program Starter.javs that shows how you can reval in the cmu dietionary (skipping comments and no on). Call your program Maxtlotnophones. The inpet is a mingle positive integer n. If the largest set of homophones in the first on lines of the pronunciation dictionary is of sice k, then your program should pirint out k on the fat line, followed by k homophones, each on a new line. If there is more than one collection of k homophones, your program shotald print out earh group, sparated to a blank line. The outpat should be all upper cios for cotadstency with the peonuneiation dictionary. For example, if the input is 1000 then the correct output is 5 ABAE File: work/Starte mport java. fo.rile; mport java. io. FileNotfoundexception; mpert java.utili. Scanner; mport java.util. Arraytist; ublic class starter f public static void moin(5tring[] args) \{ //oatoictionaryestring, Pronunciations poict - new oALDictionaryestring, Pronunciations UALicicionaryestring, Pronunciations poict = new UALDictionary (string, Pronunciation) () long start = Systen, currentTimetilis (); try { scanner scanner = new scanner (file); while (scanner. hasNextline( ) ) f string line - scanner. nextine (): if (1ine, substring (0,3), equals (:,z=)) continue; /I skip coment lines Pronunciation p - new Pronunciation(1ine); poict.insert (p.getword () , p): Scanner. close(): ) catch (filiehotioundixception e) \{ 1 e.printstackTrace(); long eiddle = systen icurrent Timemilis(); systen.out.println("Loaded dictionary; elapsed time "+(middle-start)); int count = ej for (Pronunciation p= polct.values ()) l ticount: System.out.print ln(p); if (count >5 ) break; long end = system. current Timelinis () ; Systen.out.println("fun timesz loed dictionarye " + (middle - start) \} + process: + (end - middle) + total 7+ (end - start)), import java,util. Arraytist; import java.util. Collections; class Uutoictionaryskey extends Comparable, E> inplenents oictionaryckey, E> ( private static final int defaulesize ; 19 ; private Arraylistekvpairckey, t) 1 ist, (f Constructors UALoictionary () \& ) this (defaultsize); Utolettionary (intisz) \{ ) List = nes Arraylistixvpairckey, E) (sz); public woid clear( () ) Hist.clear(): P*o Insert an element append to Hict of Kvpairckey, List. ) Iist,add(teep)d p(knt kpairckey, ts(k,e)j Hon Resove element with iny ky return elseent. % pudile I renove ( Key k) i E temp. find (k)d if (teng ind ind (k)d is istire 1. return tempi now kvalr (key,)(k,tenp)); (i*: Hesove any rlenent. public t removeany return 1ist, remove (1) ) return list,remove (1 ist.size (01),value( ) i *ind k using sequentiat search? - Ereturn ficcord with key yalue k public t find (key k ) f for (cypairaxey, is t i list). if (k.conpare olo (t,key())=a) reture t-value ( i) 1. return nulis /thk does not wpear in dirtlonary public iterablect) findadl (key k) f Arraylistabs al o new Arraycisteos (; for (xvpalrckey, in t int list) if (k, sempardfortikey ()}0) File: work/UALDictionary.java fir meikibai intanaryjun import java.util. Arraylist; private static final int defaultsize =10; private ArrayList KVpairKey, E list; // Constructors OALDictionary () \{ this(defaultsize); \} OALDictionary (int sz) \{ 7 list = new Arraylist KVpairKey,E>>(sz); public void clear (11{ ; list.clear( ); W.* Insert an element: append to list \% public void insert (Key k,E e) \{ KVpair Key, Es temp = new KVpair Key, E> (k,e); int i m, ; (i)) list, add (i, temp); Remove element with kev k. return element */ File: work/OALDictionary.java /** Remove element with key k, return element * public E remove(Key k) \{ E temp = find (k); if (temp I= nuli) list. remove(new KVpair( k, temp)); 3 return temp; I*: Remove any element / public E removeAny() \{ 3 return list. remove(list. size ( ) -1). value(); "* Find k using sequential search Qreturn Record with key value k public E sfind(Key k ) \{ for (KVpairt; list) return t.value(); ) return nu1l; // " k " does not appear in dictionary * Find k using binary search Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started