Exercise (HashTables – managing a dictionary) Create a small GUI program using j
ID: 3870376 • Letter: E
Question
Exercise (HashTables – managing a dictionary)
Create a small GUI program using javax.swing components. This is just a dummy UI with no
search capabilites in this Part 1.
Part 2: Find an API to downlown the database of English words, their type (noun, verb) and their
meaning; create a word object store that information into an an AVL tree.
Note: Your java program above should have the ability to utilize the API and download the information –
no manual steps, unless the scope changes.
Part 3: Create an efficient hash function to convert each word into an int Key:
Part 4: Implement Linear Probing, Quadtratic Probing, Separate Chaining, Double Hashing techniques
discussed in class. Chose an appropriate Lamda value per implementation. Utilize the AVL tree to
retreive the object and store into the hash table along with the Key.
Part 5: Once a word is searched, output its meaning and provide the information related to each specific
implementation in the ouput. For example:
CS 3345: Data Structures and Algorithms Exercise (HashTables-managing a dictionary)- all parts are due on 10/3 at 11:30pm Part 1: Create a small GUI program using javax.swing components. This is just a dummy UI with no search capabilites in this Part 1 Word to search for Data Structure Search WordNet Noun data structure ((computer science) the organization of data (and its storage allocations in a computer) Part 2: Find an API to downlown the database of English words, their type (noun, verb) and their meaning; create a word object store that information into an an AVL tree Note: Your java program above should have the ability to utilize the API and download the information no manual steps, unless the scope changes. Part 3: Create an efficient hash function to convert each word into an int Key: hash function Part 4: Implement Linear Probing, Quadtratic Probing, Separate Chaining, Double Hashing techniques discussed in class. Chose an appropriate Lamda value per implementation. Utilize the AVL tree to retreive the object and store into the hash table along with the Key Part 5: Once a word is searched, output its meaning and provide the information related to each specific implementation in the ouput. For example Word to search for Data Structure Search WordNet Noun data structure ((computer science) the organization of data (and its storage allocations in a computer) Total Words: XXXXXXX Data Structure Linear Probing Quadratic Probing Xxx Separate Chaining XXX Double Hashing: Table Size ambda Items investigated Success Yes or No Yes or No Yes or No Yes or No xxX xXXExplanation / Answer
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package dictionary;
import javax.swing.JOptionPane;
import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
/**
*
* @author seabirds
*/
public class MainFrame extends javax.swing.JFrame {
/**
* Creates new form MainFrame
*/
public MainFrame() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN: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)); // NOI18N
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)); // NOI18N
jLabel2.setText("Enter Query");
jTextArea1.setColumns(20);
jTextArea1.setFont(new java.awt.Font("Cambria Math", 0, 17)); // NOI18N
jTextArea1.setRows(5);
jScrollPane1.setViewportView(jTextArea1);
jButton1.setFont(new java.awt.Font("Cambria Math", 0, 17)); // NOI18N
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();
}// </editor-fold>//GEN-END:initComponents
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
// TODO add your handling code here:
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);
/* SenseFrame sf=new SenseFrame(qry);
sf.setVisible(true);
sf.setResizable(false);
sf.setTitle("Reverse Mapping Set");*/
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();
}
}//GEN-LAST:event_jButton1ActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
*/
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);
}
//</editor-fold>
/* Create and display the form */
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
}
//Find Word
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
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;
/**
*
* @author admin
*/
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++)
{
//System.out.println("wd= " +wd[k].getWordForm());
//System.out.println("wd= " +wd[k].toString());
Synset st=wd[k].getSynset();
String sh[]=st.getWordForms();
for(int m=0;m<sh.length;m++)
{
// System.out.println("wd == "+sh[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;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.