In Python Read a Line of Text Convert Singular to Plural Chegg
Lab 9: Sets in the Java Collection Framework For this week's lab,...
Lab 9: Sets in the Java Collection Framework
For this week's lab, you will use ii of the classes in the Java Collection Framework:HashSet andTreeSet. You will use these classes to implement a spell checker.
Set Methods
this lab, you volition demand to apply some of the methods that are defined in the Set interface. Recall that if fix is a Set, then the post-obit methods are defined:
- set.size() -- Returns the number of items in the set.
- ready.add(item) -- Adds the item to the set, if it is not already there.
- fix.contains(particular) -- Cheque whether the set contains the item.
- gear up.isEmpty() -- Cheque whether the set is empty.
You lot will too need to exist able to traverse a ready, using either an iterator or a for-each loop.
Reading a Lexicon
The file words.txt (in the code directory) contains a list of English language words, with 1 word on each line. You will look up words in this listing to check whether they are correctly spelled. To make the list easy to use, y'all can store the words in a prepare. Since there is no need to accept the words stored in social club, you can apply aHashSet for maximum efficiency.
Utilise a Scanner to read the file. You can create scanner,filein, for reading from a file with a argument such as:
filein = new Scanner
(new File("/classes/s09/cs225/words.txt"));
and that a file tin can be candy, token by token, in a loop such as:
while (filein.hasNext()) {
Cord tk = filein.side by side();
procedure(tk); // exercise something with the token
}
(For the wordlist file, a token is simply a discussion.)
Start your main program by reading the words from words.txt and storing them in aHashSet<String>. For the purposes of this plan,catechumen all words to lower case earlier putting them in the set. To make certain that yous've read all the words, cheque the size of the fix. (It should be 72875.) You could also use the contains method to check for the presence of some mutual give-and-take in the set.
Checking the Words in a File
In one case you have the list of words in a ready, it's like shooting fish in a barrel to read the words from a file and check whether each give-and-take is in the set. Get-go by letting the user select a file. You tin either allow the user type the proper name of the file or y'all can use the following method:
/**
* Lets the user select an input file using a standard file
* option dialog box. If the user cancels the dialog
* without selecting a file, the return value is null.
*/
static File getInputFileNameFromUser() {
JFileChooser fileDialog = new JFileChooser();
fileDialog.setDialogTitle("Select File for Input");
int choice = fileDialog.showOpenDialog(null);
if (selection != JFileChooser.APPROVE_OPTION)
return nix;
else
return fileDialog.getSelectedFile();
}
Use a Scanner to read the words from the selected file. In lodge to skip over any not-alphabetic character characters in the file, you lot can utilize the following command just later creating the scanner (where in is the variable name for the scanner):
in.useDelimiter("[^a-zA-Z]+");
(In this statement, "[^a-zA-Z]+" is a regular expression that matches whatever sequence of one or more non-letter characters. This substantially makes the scanner treat any non-alphabetic character the way information technology would ordinarily treat a space.)
You tin then become through the file, read each word (converting it to lower case) and check whether the set contains the word. At this point, just print out any word that you find that is not in the dictionary.
Providing a Listing of Possible Correct Spellings
A spell checker shouldn't but tell you what words are misspelled -- it should also requite you a list of possible correct spellings for that word. Write method
static TreeSet corrections(String badWord, HashSet lexicon)
that creates and returns aTreeSet<String> containing variations onbadWord that are contained in the dictionary. In your main program, when y'all find a word that is not in the prepare of legal words, pass that word to this method (forth with the set). Accept the return value and output any words that it contains; these are the suggested correct spellings of the misspelled word. Hither, for instance, is part of the output from a sample program when it was run with the HTML source of this page as input:
html: (no suggestions)
cpsc: (no suggestions)
hashset: hash set
treeset: tree set
cvs: cs, vs
isempty: is empty
href: ref
txt: tat, tet, text, tit, tot, tut
filein: file in
pre: are, ere, ire, ore, peel, pee, per, pie, poe, pore, prep, pres,
casualty, pro, pry, pure, pyre, re
hasnext: has adjacent
wordlist: word listing
getinputfilenamefromuser: (no suggestions)
jfilechooser: (no suggestions)
filedialog: file dialog
setdialogtitle: (no suggestions)
int: ant, dint, hint, in, ina, inc, ind, ink, inn, ins, inti, into,
it, lint, mint, nit, pint, tint
Note that the program was written then that it will non output the aforementioned misspelled discussion more than than one time. (This is washed by keeping a ready of misspelled words that accept been output.) If thecorrections() method returns an empty set, the program outputs the message "(no suggestions)". Since the corrections are stored in a tree set up, they are automatically printed out in alphabetical order with no repeats.
The possible corrections that the programme considers are as follows:
• Delete any one of the letters from the misspelled word.
• Modify whatsoever alphabetic character in the misspelled word to whatsoever other letter.
• Insert any letter at any betoken in the misspelled word.
• Swap any two neighboring characters in the misspelled word.
• Insert a infinite at any point in the misspelled word (and check that both of the words that are produced are in the dictionary)
For constructing the possible corrections, you volition accept to make extensive utilise of substrings. If w is a string, thenw.substring(0,i) is the string consisting of the showtime i characters in w (not including the character in position i, which would be character numberi+1). Andwest.substring(i) consists of the characters of westward from position i through the end of the cord. For example, ifch is a character, then you can alter thei-thursday character of due west to ch with the statement:
String s = w.substring(0,i) + ch + w.substring(i+1);
As well, you volition notice it convenient to use afor loop in which the loop control variable is achar:
for (char ch = 'a'; ch <= 'z'; ch++) { ...
Respond & Explanation
Solved by verified practiced
entesq
consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentes
ce dui lectus, congue vel laoreet air conditioning, dictum vitae odio. Donec aliquet. Lorem ipsum do
rem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar torto
,ur laoreet. Nam risus dues, dapibus a molestie consx
Unlock full access to Course Hero
Explore over 16 1000000 footstep-by-step answers from our library
Subscribe to view answer
Step-by-pace explanation
a. Fusce dui lec
dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit down amet, consectetur adipiscing elit. Nam lacinia pulvinar tortorconlonec50ac, dictumrisus sumiametiur licetm ipsum dolo,dictum vitae odio. Donec aliquet. Lorem ipsum dolorsua molestie consequat, ultrices air conditioning magna. Fusce dui lectufng elit. Nia pulvinar tortor nesuair-conditioning, dictusuec facconsectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque daconsectetur am ipslestie consequat, ultrices air-conditioning magna. Fusce dui lectus, congue vel laoreet ac, dictum vitatrimolestie consequat, ultrices air-conditioning magna. Fusce dui lectus,sutrices air conditioning magna. Fusce dui lectus, congue vel laoreet air-conditioning, dictum vitaitur laoreeusce dui lectus, congue vel laoreet ac, dsuinia pulvinar tortor nec facm ipsat, ultrices air-conditioning magna. Fusce dui lectus, congue vel laoreet air conditioning, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit down amet, consectetuuFusce dui lectus, congue vel laoreet air conditioning, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit down amet,tring elit. Nam lacinia pulvinar tortor nec facilisis. Pellsucongue vel laoreet air-conditioning, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit down amet, consecteturair conditioning,lestie consequat, ucea molestie consequctum vitae odio. Donec aliquet. Lorem ipsum dac,dictum vimolestie consequa molestie conseqonecfacilisis. Pellentesque dapibusiaDonec al0s ante, dapibusicitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magazineair-conditioning,ur laoreet. Nam risus ante, dapibus auac, dictum vitae odio. Donec afinia pulvinar tortor nec facac,ipsum dentm ipsum dolor sit ametonecs a molestie consequat, ultrac,ipsum dusceFusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit apulv, consectetur adipiscing elit. Nam lacinia pulvinar tortair conditioning,dictum 6ur laoreet. Nam risus dues, dapibus a molestie consec aliquet. Lorem ipsum dolor0congue vel l ametipsumec aliquet. Lorem ipsumuscfacilisis. Pellentesque dapibus esuet, consectetur adipiscing elit. Nam lacinia pulinia pulvinar tortor neone thousand ipsumiaor nec facilisis. Pellentesque dapibametg ipsumum risus ante, dapibus a molestie consequat, ultrior nelametinia ponectesque dapor neamet, consectetur adipiscing elit. Nam ametongue velipsum dolorto. Donec aliquet. Lorem ipsum dolo,sum dolor sit amet, consectetur adipiscing elsuitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magnicDiallen0entesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie conse0cing elit. Nam lacinia pulvinar tortor nec facilisfctum vitae odio. Donec aliquet. Lorem ipsum dolor sit down amet, cuitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrtrictum vitae odio. Donec aliicDac,onguecefficituriafficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna.usus ante, dapibus a molestie consequat, ultrices air conditioning magna. Fusce duitrisouthward ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui l0ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit down aicDair-conditioning,onguecefficituriafficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna.uair-conditioning, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur atriusce dui lectus, congue vel laoreet air-conditioning, dictum vitae odio. Doneac,ongueceac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit ametufficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices air-conditioning magna. Fusce dui lectus, conguetrinec facilisis. Pellentesque dapibus efficitur laoreeticDiallenfentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie conse0rem ipfsouth a molestieac,amet, consectetur adipiscifs a molestieac,fficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultricf, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit down amet, consecteuitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrtring elit. Nam lacinia pulvinaor neo. Donec aliquet. Lorem ipsu
, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacin
sum do
Source: https://www.coursehero.com/tutors-problems/Java-Programming/21112512-Lab-9-Sets-in-the-Java-Collection-Framework-For-this-weeks-lab-you/
0 Response to "In Python Read a Line of Text Convert Singular to Plural Chegg"
Post a Comment