Question

In: Computer Science

how would I be able to implement a hash table into a spell checker program while...

how would I be able to implement a hash table into a spell checker program while using a StringNode class in java that checks for spelling mistakes?

Solutions

Expert Solution

import java.util.ArrayList;
import java.util.Scanner;

public class SpellCheck {

    private Dictionary dict;
    final static String filePath = "d:/desktop/words.txt";
    final static char[] alphabet = "abcdefghijklmnopqrstuvwxyz".toCharArray();
SpellCheck() {
        dict = new Dictionary();
        dict.build(filePath);

    }

    void run() {
        Scanner scan = new Scanner(System.in);
        boolean done = false;
        String input;
if (input.equals("")) {
                break;
            }
            if (dict.contains(input)) {
                System.out.println("\n" + input + " is spelled correctly");
            } else {
                System.out.print("is not spelled correctly, ");
                System.out.println(printSuggestions(input));
 }
        }
    }

   
String printSuggestions(String input) {
        StringBuilder sb = new StringBuilder();
        ArrayList<String> print = makeSuggestions(input);
        if (print.size() == 0) {
            return "and I have no idea what word you could mean.\n";
        }
        sb.append("perhaps you meant:\n");
        for (String s : print) {
            sb.append("\n  -" + s);
        }
        return sb.toString();
    }

   

Related Solutions

Create a graphical spell checker program that The File menu has the three items shown. On...
Create a graphical spell checker program that The File menu has the three items shown. On Open, the program reads a text file (!) with the current directory set to the directory where your program is located. Save saves the current text in the window to the file selected over a dialog and The Edit menu has one menu item: Spell Check.
How can I make this program able to implement listener for the editable text field: ///////////////////////////////...
How can I make this program able to implement listener for the editable text field: /////////////////////////////// KiloConverter.java ////////////////////////// import java.awt.BorderLayout; import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; public class KiloConverter extends JFrame { // constant for converting km to miles static final double KM_TO_MILES = 0.6214; // important components that needs to be accessed throughout the program private JTextField input, output; // constructor initializing GUI public KiloConverter() { // passing title...
Implement a Cuckoo hash table in which two separate tables are maintained. Each table should have...
Implement a Cuckoo hash table in which two separate tables are maintained. Each table should have a fixed size of 13. Use the hash function h1(x) = x mod 13 for the first table, and h2(x)= 11 – (x mod 11) for the second table. Your program should read an input file, input.txt, consisting of one input per line, insert the input to the table in order, and print out the final content of the hash table in the provided...
Write a program to insert the following elements into a hash table of size 17. The...
Write a program to insert the following elements into a hash table of size 17. The hash function is X mod 17 where X is the input element.   6, 12, 34, 29, 28, 11, 23, 7, 0, 33, 30, 45 Use linear probing to resolve any collisions.
PYTHON--- regarding a hash table, why would it be bad to delete an item to successive...
PYTHON--- regarding a hash table, why would it be bad to delete an item to successive searches or insertions that uses open addressing
How would you implement a training and development program in a huge company?
How would you implement a training and development program in a huge company?
Decades ago I was in a physics Ph.D. program, made a hash of things, and quite...
Decades ago I was in a physics Ph.D. program, made a hash of things, and quite rightly was dropped from the program. Since then I've had a very satisfying career as a computer programmer, and picked up an M.S. in Applied Math. I'm currently working in a bioinformatics research lab, and really enjoying myself. I think I might want to retire in five or six years, and lately I've been daydreaming about returning to my first love, and entering a...
Hello I would love to know the steps of how to be able to create a...
Hello I would love to know the steps of how to be able to create a Pearson's correlations chart in APa format from SPSS?
3. Assume a hash table with 7 locations and the hashing function h(i) = i%7. Show...
3. Assume a hash table with 7 locations and the hashing function h(i) = i%7. Show the hash table that results when the integers are inserted in the order given. (10 points each. Total 30) • 5, 11, 18, 23, 28, 13, 25, with collisions resolved using linear probing • 5, 11, 18, 23, 28, 13, 25, with collisions resolved using quadratic probing • 5, 11, 18, 23, 28, 13, 25, with collisions resolved using chaining.
Implement a python program in file named tarvel.py. Create an empty dictionary named responses. Implement while...
Implement a python program in file named tarvel.py. Create an empty dictionary named responses. Implement while loop to take in user's name and desired destination for as long as there are user inputs. Prompt user to input yes to continue and no to quit. Prompt for user's name. Receive the name into the program and save it as the value of name variable. Prompt user for their desired vacation destination. Receive response and save it as the value of a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT