package ir.ac.iust.nlp.dependencyparser;
import ir.ac.iust.nlp.dependencyparser.converter.ConverterPanel;
import ir.ac.iust.nlp.dependencyparser.dependencygraph.CreateDGPanel;
import ir.ac.iust.nlp.dependencyparser.evaluation.EvalPanel;
import ir.ac.iust.nlp.dependencyparser.hybrid.EnsemblePanel;
import ir.ac.iust.nlp.dependencyparser.hybrid.StackingPanel;
import ir.ac.iust.nlp.dependencyparser.inputoutput.ReadingPanel;
import ir.ac.iust.nlp.dependencyparser.optomization.OptimizerPanel;
import ir.ac.iust.nlp.dependencyparser.parsing.ParsePanel;
import ir.ac.iust.nlp.dependencyparser.phrasestructuregraph.CreatePSGPanel;
import ir.ac.iust.nlp.dependencyparser.projection.DeprojectivizePanel;
import ir.ac.iust.nlp.dependencyparser.projection.ProjectivizePanel;
import ir.ac.iust.nlp.dependencyparser.training.TrainPanel;
import java.awt.Desktop;
import java.awt.GridLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import se.vxu.msi.malteval.treeviewer.MaltTreeViewerGui;
/**
*
* @author Mojtaba Khallash
*/
public class DependencyParserApp extends javax.swing.JFrame {
String curDir;
BasePanel myPnl = null;
MaltTreeViewerGui gui;
/**
* Creates new form DependencyParserApp
*/
public DependencyParserApp() {
initComponents();
optimizer.Optimizer.ExitInEnd = false;
curDir = System.getProperty("user.dir");
clearTempFolder();
this.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
clearTempFolder();
}
});
// not complete
mnuiCreatePSG.setVisible(false);
}
private void clearTempFolder() {
File dir = new File(curDir + File.separator + "tmp");
if (dir.exists()) {
// Get all files in directory
File[] files = dir.listFiles();
for (File file : files) {
// Delete each folder
if (file.isDirectory()) {
BasePanel.deleteDirectory(file);
}
}
}
}
/**
* 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() {
pnlMain = new javax.swing.JPanel();
menuBar = new javax.swing.JMenuBar();
fileMenu = new javax.swing.JMenu();
saveMenuItem = new javax.swing.JMenuItem();
jSeparator1 = new javax.swing.JPopupMenu.Separator();
exitMenuItem = new javax.swing.JMenuItem();
toolsMenu = new javax.swing.JMenu();
mnuiFormatConverter = new javax.swing.JMenuItem();
mnuiReadTreebank = new javax.swing.JMenuItem();
jSeparator2 = new javax.swing.JPopupMenu.Separator();
mnuiCreateDG = new javax.swing.JMenuItem();
mnuiCreatePSG = new javax.swing.JMenuItem();
jSeparator3 = new javax.swing.JPopupMenu.Separator();
mnuiProjectivize = new javax.swing.JMenuItem();
mnuiDeprojectivize = new javax.swing.JMenuItem();
jSeparator4 = new javax.swing.JPopupMenu.Separator();
mnuiOptimizer = new javax.swing.JMenuItem();
jSeparator5 = new javax.swing.JPopupMenu.Separator();
mnuiTraining = new javax.swing.JMenuItem();
mnuiParsing = new javax.swing.JMenuItem();
mnuiEvaluation = new javax.swing.JMenuItem();
jSeparator6 = new javax.swing.JPopupMenu.Separator();
mnuiHybrid = new javax.swing.JMenu();
mnuiEnsemble = new javax.swing.JMenuItem();
mnuiStacking = new javax.swing.JMenuItem();
helpMenu = new javax.swing.JMenu();
mnuiDPTBH = new javax.swing.JMenuItem();
jSeparator7 = new javax.swing.JPopupMenu.Separator();
aboutMenuItem = new javax.swing.JMenuItem();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Dependency Parser Toolbox");
setMinimumSize(new java.awt.Dimension(740, 700));
setName("frmDependencyParsing"); // NOI18N
setPreferredSize(new java.awt.Dimension(760, 450));
javax.swing.GroupLayout pnlMainLayout = new javax.swing.GroupLayout(pnlMain);
pnlMain.setLayout(pnlMainLayout);
pnlMainLayout.setHorizontalGroup(
pnlMainLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 760, Short.MAX_VALUE)
);
pnlMainLayout.setVerticalGroup(
pnlMainLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 370, Short.MAX_VALUE)
);
fileMenu.setMnemonic('f');
fileMenu.setText("File");
fileMenu.addMenuListener(new javax.swing.event.MenuListener() {
public void menuCanceled(javax.swing.event.MenuEvent evt) {
}
public void menuSelected(javax.swing.event.MenuEvent evt) {
fileMenu_Selected(evt);
}
public void menuDeselected(javax.swing.event.MenuEvent evt) {
}
});
saveMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
saveMenuItem.setMnemonic('s');
saveMenuItem.setText("Save");
saveMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
saveMenuItem_Click(evt);
}
});
fileMenu.add(saveMenuItem);
fileMenu.add(jSeparator1);
exitMenuItem.setMnemonic('x');
exitMenuItem.setText("Exit");
exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
exitMenuItemActionPerformed(evt);
}
});
fileMenu.add(exitMenuItem);
menuBar.add(fileMenu);
toolsMenu.setText("Tools");
mnuiFormatConverter.setText("Format Converter");
mnuiFormatConverter.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
mnuiFormatConverterActionPerformed(evt);
}
});
toolsMenu.add(mnuiFormatConverter);
mnuiReadTreebank.setText("Read From Treebank");
mnuiReadTreebank.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ReadTreebank_click(evt);
}
});
toolsMenu.add(mnuiReadTreebank);
toolsMenu.add(jSeparator2);
mnuiCreateDG.setText("Create Dependency Graph");
mnuiCreateDG.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
mnuiCreateDG_Click(evt);
}
});
toolsMenu.add(mnuiCreateDG);
mnuiCreatePSG.setText("Create Phrase Structure Graph");
mnuiCreatePSG.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
mnuiCreatePSG_Click(evt);
}
});
toolsMenu.add(mnuiCreatePSG);
toolsMenu.add(jSeparator3);
mnuiProjectivize.setText("Projectivize");
mnuiProjectivize.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
mnuiProjectivize_Click(evt);
}
});
toolsMenu.add(mnuiProjectivize);
mnuiDeprojectivize.setText("Deprojectivize");
mnuiDeprojectivize.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
mnuiDeprojectivize_Click(evt);
}
});
toolsMenu.add(mnuiDeprojectivize);
toolsMenu.add(jSeparator4);
mnuiOptimizer.setText("Optimizer");
mnuiOptimizer.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
mnuiOptimizerActionPerformed(evt);
}
});
toolsMenu.add(mnuiOptimizer);
toolsMenu.add(jSeparator5);
mnuiTraining.setText("Training");
mnuiTraining.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
mnuiTraining_Click(evt);
}
});
toolsMenu.add(mnuiTraining);
mnuiParsing.setText("Parsing");
mnuiParsing.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
mnuiParsing_Click(evt);
}
});
toolsMenu.add(mnuiParsing);
mnuiEvaluation.setText("Evaluation");
mnuiEvaluation.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
mnuiEvaluation_Click(evt);
}
});
toolsMenu.add(mnuiEvaluation);
toolsMenu.add(jSeparator6);
mnuiHybrid.setText("Hybrid");
mnuiEnsemble.setText("Ensemble");
mnuiEnsemble.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
mnuiEnsemble_Click(evt);
}
});
mnuiHybrid.add(mnuiEnsemble);
mnuiStacking.setText("Stacking");
mnuiStacking.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
mnuiStacking_Click(evt);
}
});
mnuiHybrid.add(mnuiStacking);
toolsMenu.add(mnuiHybrid);
menuBar.add(toolsMenu);
helpMenu.setMnemonic('h');
helpMenu.setText("Help");
mnuiDPTBH.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_H, java.awt.event.InputEvent.CTRL_MASK));
mnuiDPTBH.setText("Dependency Parsing Toolbox Homepage");
mnuiDPTBH.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
mnuiDPTBHActionPerformed(evt);
}
});
helpMenu.add(mnuiDPTBH);
helpMenu.add(jSeparator7);
aboutMenuItem.setMnemonic('a');
aboutMenuItem.setText("About");
aboutMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
aboutMenuItem_Click(evt);
}
});
helpMenu.add(aboutMenuItem);
menuBar.add(helpMenu);
setJMenuBar(menuBar);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(pnlMain, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(pnlMain, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed
System.exit(0);
}//GEN-LAST:event_exitMenuItemActionPerformed
private void ReadTreebank_click(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ReadTreebank_click
myPnl = new ReadingPanel(curDir);
putPanelOnForm();
}//GEN-LAST:event_ReadTreebank_click
private void mnuiCreateDG_Click(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuiCreateDG_Click
myPnl = new CreateDGPanel(curDir);
putPanelOnForm();
}//GEN-LAST:event_mnuiCreateDG_Click
private void mnuiCreatePSG_Click(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuiCreatePSG_Click
myPnl = new CreatePSGPanel(curDir);
putPanelOnForm();
}//GEN-LAST:event_mnuiCreatePSG_Click
private void mnuiParsing_Click(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuiParsing_Click
myPnl = new ParsePanel(curDir);
putPanelOnForm();
}//GEN-LAST:event_mnuiParsing_Click
private void saveMenuItem_Click(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveMenuItem_Click
myPnl.save();
}//GEN-LAST:event_saveMenuItem_Click
private void mnuiProjectivize_Click(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuiProjectivize_Click
myPnl = new ProjectivizePanel(curDir);
putPanelOnForm();
}//GEN-LAST:event_mnuiProjectivize_Click
private void mnuiDeprojectivize_Click(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuiDeprojectivize_Click
myPnl = new DeprojectivizePanel(curDir);
putPanelOnForm();
}//GEN-LAST:event_mnuiDeprojectivize_Click
private void mnuiTraining_Click(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuiTraining_Click
myPnl = new TrainPanel(curDir);
putPanelOnForm();
}//GEN-LAST:event_mnuiTraining_Click
private void mnuiOptimizerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuiOptimizerActionPerformed
myPnl = new OptimizerPanel(curDir);
putPanelOnForm();
}//GEN-LAST:event_mnuiOptimizerActionPerformed
private void aboutMenuItem_Click(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aboutMenuItem_Click
DpAbout about = new DpAbout(this, true);
about.setVisible(true);
}//GEN-LAST:event_aboutMenuItem_Click
private void mnuiEvaluation_Click(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuiEvaluation_Click
myPnl = new EvalPanel(curDir);
putPanelOnForm();
}//GEN-LAST:event_mnuiEvaluation_Click
private void mnuiEnsemble_Click(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuiEnsemble_Click
myPnl = new EnsemblePanel(curDir);
putPanelOnForm();
}//GEN-LAST:event_mnuiEnsemble_Click
private void mnuiStacking_Click(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuiStacking_Click
myPnl = new StackingPanel(curDir);
putPanelOnForm();
}//GEN-LAST:event_mnuiStacking_Click
private void fileMenu_Selected(javax.swing.event.MenuEvent evt) {//GEN-FIRST:event_fileMenu_Selected
if (myPnl != null) {
saveMenuItem.setEnabled(myPnl.canSave());
}
else {
saveMenuItem.setEnabled(false);
}
}//GEN-LAST:event_fileMenu_Selected
private void mnuiFormatConverterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuiFormatConverterActionPerformed
myPnl = new ConverterPanel(curDir);
putPanelOnForm();
}//GEN-LAST:event_mnuiFormatConverterActionPerformed
private void mnuiDPTBHActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuiDPTBHActionPerformed
try {
URI url = new URI("http://nlp.iust.ac.ir");
Desktop.getDesktop().browse(url);
}
catch(URISyntaxException | IOException ex) {}
}//GEN-LAST:event_mnuiDPTBHActionPerformed
private void putPanelOnForm() {
pnlMain.removeAll();
pnlMain.setLayout(new GridLayout());
pnlMain.add(myPnl);
pnlMain.revalidate();
saveMenuItem.setEnabled(myPnl.canSave());
}
/**
* @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. For details see
* http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
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 | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(DependencyParserApp.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/*
* Create and display the form
*/
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
new DependencyParserApp().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JMenuItem aboutMenuItem;
private javax.swing.JMenuItem exitMenuItem;
private javax.swing.JMenu fileMenu;
private javax.swing.JMenu helpMenu;
private javax.swing.JPopupMenu.Separator jSeparator1;
private javax.swing.JPopupMenu.Separator jSeparator2;
private javax.swing.JPopupMenu.Separator jSeparator3;
private javax.swing.JPopupMenu.Separator jSeparator4;
private javax.swing.JPopupMenu.Separator jSeparator5;
private javax.swing.JPopupMenu.Separator jSeparator6;
private javax.swing.JPopupMenu.Separator jSeparator7;
private javax.swing.JMenuBar menuBar;
private javax.swing.JMenuItem mnuiCreateDG;
private javax.swing.JMenuItem mnuiCreatePSG;
private javax.swing.JMenuItem mnuiDPTBH;
private javax.swing.JMenuItem mnuiDeprojectivize;
private javax.swing.JMenuItem mnuiEnsemble;
private javax.swing.JMenuItem mnuiEvaluation;
private javax.swing.JMenuItem mnuiFormatConverter;
private javax.swing.JMenu mnuiHybrid;
private javax.swing.JMenuItem mnuiOptimizer;
private javax.swing.JMenuItem mnuiParsing;
private javax.swing.JMenuItem mnuiProjectivize;
private javax.swing.JMenuItem mnuiReadTreebank;
private javax.swing.JMenuItem mnuiStacking;
private javax.swing.JMenuItem mnuiTraining;
private javax.swing.JPanel pnlMain;
private javax.swing.JMenuItem saveMenuItem;
private javax.swing.JMenu toolsMenu;
// End of variables declaration//GEN-END:variables
}