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

Homework Hash Table: Part 1: Prompt a user in a console output OR Create an opti

ID: 3872224 • Letter: H

Question

Homework Hash Table:

Part 1: Prompt a user in a console output OR Create an optional small GUI program using javax.swing components that will prompt the user to search a word.

Eg.

Word to search for: Data Structure

Data Structure(noun) - (computer Science)The organization of data and its storage allocations in a computer.

Part 2: A text file named "dictionary.txt" will be provided to you for the database of English words, their

type (noun, verb, etc.) and their meaning. Create an efficient hash function to

convert each word into an int Key:

sample lines in dictionary.txt:

power_tool|NOUN|a tool driven by a motor

power_train|NOUN|wheelwork consisting of a connected set of rotating gears by which force is transmitted or motion or torque is changed; "the fool got his tie caught in the geartrain"

power_trip|NOUN|(slang) a self-aggrandizing action undertaken simply for the pleasure of exercising control over other people

power_unit|NOUN|a measure of electric power

Note: the text file will containe single words or multiple words connected via underscore, the type of

the word (noun, verb, etc) and its meaning. So if we search for Data Structure, we will find

Data_Structure which will be valid result to return.

Part 3: Implement Linear Probing, Quadtratic Probing, Separate Chaining, Double Hashing techniques

discussed in class. Chose an appropriate Lamda value per implementation. Use Key generation in part 2

to store the node (key, type, meaning) in the hash table.

Part 4: Once a word is searched, output its meaning and provide the information related to each specific

implementation in the ouput. For example:

Final output:

Word to search for: Data Structure (Enter)

Data Structure(noun) - (computer Science)The organization of data and its storage allocations in a computer.

Total Words: xxxxx

Data Structure Table Size Lambda Success Items Investigated

Linear Probing xxx xxx yes/no xxx

Quadratic Probing xxx xxx yes/no xxx

Separate Chaining xxx xxx yes/no xxx

Double Hashing xxx xxx yes/no xxx

Use JAVA or C/C++

Explanation / Answer

import javax.swing.JOptionPane;
import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;

public class MainFrame extends javax.swing.JFrame {


public MainFrame() {
initComponents();
}

private void initComponents() {

jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jSeparator1 = new javax.swing.JSeparator();
jLabel2 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
jButton1 = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jPanel1.setBackground(new java.awt.Color(255, 255, 255));

jLabel1.setFont(new java.awt.Font("Cambria Math", 0, 24));
jLabel1.setText("Reverse Dictionary");

jSeparator1.setBackground(new java.awt.Color(0, 0, 0));
jSeparator1.setForeground(new java.awt.Color(0, 0, 0));

jLabel2.setFont(new java.awt.Font("Cambria Math", 0, 17));
jLabel2.setText("Enter Query");

jTextArea1.setColumns(20);
jTextArea1.setFont(new java.awt.Font("Cambria Math", 0, 17));
jTextArea1.setRows(5);
jScrollPane1.setViewportView(jTextArea1);

jButton1.setFont(new java.awt.Font("Cambria Math", 0, 17));
jButton1.setText("Process");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});

javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jSeparator1)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(20, 20, 20)
.addComponent(jLabel2)
.addGap(18, 18, 18)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(152, 152, 152)
.addComponent(jLabel1)))
.addContainerGap(75, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(jButton1)
.addGap(190, 190, 190))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(23, 23, 23)
.addComponent(jLabel1)
.addGap(29, 29, 29)
.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(51, 51, 51)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(102, 102, 102)
.addComponent(jLabel2)))
.addGap(28, 28, 28)
.addComponent(jButton1)
.addContainerGap(55, Short.MAX_VALUE))
);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);

pack();
}

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
try
{
String txt=jTextArea1.getText().trim();
if(txt.equals(""))
JOptionPane.showMessageDialog(this, "Enter Query");
else
{
ArrayList qry=new ArrayList();
String g1[]=txt.split(" ");
for(int i=0;i<g1.length;i++)
qry.add(g1[i]);


System.out.println(qry);
File fe=new File("stopwords1.txt");
FileInputStream fis=new FileInputStream(fe);
byte data[]=new byte[fis.available()];
fis.read(data);
fis.close();

String g2[]=new String(data).split(" ");
ArrayList stop1=new ArrayList();
for(int i=0;i<g2.length;i++)
stop1.add(g2[i].trim());
//System.out.println(stop1);
for(int i=0;i<qry.size();i++)
{
String a1=qry.get(i).toString().toLowerCase().trim();
if(stop1.contains(a1))
qry.remove(i);
}

if(qry.size()>=2)
{
System.out.println(qry);

ReverseMapping rv=new ReverseMapping(qry);
String rs=rv.getReverseSet();

RMSFrame rms=new RMSFrame(qry);
rms.setVisible(true);
rms.setTitle("Reverse Mapping Set");
rms.setResizable(false);
//rms.jTextArea1.setText(rs);

rms.jTextArea1.setText(rv.adjective);
rms.jTextArea2.setText(rv.adverb);
rms.jTextArea3.setText(rv.verb);
rms.jTextArea4.setText(rv.noun);
}
else
{
JOptionPane.showMessageDialog(this, "Query size > 3");
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
}/
public static void main(String args[]) {

try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}

java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new MainFrame().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JSeparator jSeparator1;
private javax.swing.JTextArea jTextArea1;
// End of variables declaration//GEN-END:variables
}


package dictionary;

import java.util.ArrayList;

import edu.smu.tspell.wordnet.WordNetDatabase;

import edu.smu.tspell.wordnet.Synset;

import edu.smu.tspell.wordnet.WordSense;

import edu.smu.tspell.wordnet.impl.file.PropertyNames;

public class FindWords

{

ArrayList qry=new ArrayList();

FindWords(ArrayList at1)

{

qry=at1;

}

public String getResult()

{

String res="";

try

{

ArrayList lt=new ArrayList();

System.setProperty(PropertyNames.DATABASE_DIRECTORY, "dict");

for(int ii=0;ii<qry.size();ii++)

{

String word=qry.get(ii).toString().trim();

WordNetDatabase database = WordNetDatabase.getFileInstance();

Synset[] synsets11 = database.getSynsets(word);

for(int i=0;i<synsets11.length;i++)

{

String wf[]=synsets11[i].getWordForms();

for(int j=0;j<wf.length;j++)

{

WordSense wd[]=synsets11[i].getDerivationallyRelatedForms(wf[j]);

for(int k=0;k<wd.length;k++)

{


Synset st=wd[k].getSynset();

String sh[]=st.getWordForms();

for(int m=0;m<sh.length;m++)

{

if(!lt.contains(sh[m]))

lt.add(sh[m]);

}

}

}

}

}

System.out.println("lt "+lt);

for(int i=0;i<lt.size();i++)

res=res+lt.get(i).toString()+" ";

}

catch(Exception e)

{

e.printStackTrace();

}

return res;

}

}