package ir.ac.iust.nlp.dependencyparser.projection; import edu.stanford.nlp.parser.ensemble.utils.ProjectivizeCorpus; import ir.ac.iust.nlp.dependencyparser.BasePanel; import ir.ac.iust.nlp.dependencyparser.utility.ExampleFileFilter; import ir.ac.iust.nlp.dependencyparser.utility.enumeration.TransformType; import java.awt.Color; import java.awt.GridLayout; import java.io.File; import java.io.IOException; import java.io.OutputStream; import java.io.PrintStream; import java.util.Calendar; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import javax.swing.JOptionPane; import javax.swing.JSplitPane; import org.apache.commons.io.FileUtils; import org.maltparser.core.exception.MaltChainedException; import se.vxu.msi.malteval.treeviewer.MaltTreeViewerGui; import se.vxu.msi.malteval.treeviewer.gui.TreeViewer; /** * * @author Mojtaba Khallash */ public class ProjectivizePanel extends BasePanel { boolean isInit = false; String inputFile; String outputFile; String currentTempFolder; /** * Creates new form ProjectivizePanel */ public ProjectivizePanel(String dir) { super(dir); initComponents(); setDrop(); txtInputFile.setText(dir + File.separator + "Treebank" + File.separator + "non-projective" + File.separator + "nonproj.conll"); txtOutputPath.setText(dir + File.separator + "Output" + File.separator + "projectivize" + File.separator); txtModelPath.setText(dir + File.separator + "Output" + File.separator + "projectivize" + File.separator); lblVertical.setVisible(false); AdjustDividerLocation(); } private void setDrop() { initDrop(txtInputFile, false); initDrop(txtOutputPath, true); initDrop(txtModelPath, true); } @Override public boolean canSave() { return true; } @Override public void save() { switch (tabDependencyInfo.getSelectedIndex()) { case 0: // Output ExampleFileFilter filter = new ExampleFileFilter("txt", "Text Files"); saveText(filter, "Projectivizing_log.txt", txtLog.getText()); break; case 1: // Tree saveTree(1); break; } } @Override public void saveAs() { save(); } /** * 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() { pnlParameter = new javax.swing.JPanel(); lblInputFile = new javax.swing.JLabel(); txtInputFile = new javax.swing.JTextField(); btnBrowseInputFile = new javax.swing.JButton(); lblOutputPath = new javax.swing.JLabel(); txtOutputPath = new javax.swing.JTextField(); btnBrowseOutputPath = new javax.swing.JButton(); lblModelPath = new javax.swing.JLabel(); txtModelPath = new javax.swing.JTextField(); btnBrowseModelPath = new javax.swing.JButton(); lblMarkingStrategy = new javax.swing.JLabel(); cboMarkingStrategy = new javax.swing.JComboBox(); lblCoveredRoot = new javax.swing.JLabel(); cboCoveredRoot = new javax.swing.JComboBox(); lblLiftingOrder = new javax.swing.JLabel(); cboLiftingOrder = new javax.swing.JComboBox(); btnStartProjectivize = new javax.swing.JButton(); tabDependencyInfo = new javax.swing.JTabbedPane(); pnlLog = new javax.swing.JPanel(); jScrollPane1 = new javax.swing.JScrollPane(); txtLog = new javax.swing.JTextArea(); pnlTrees = new javax.swing.JPanel(); splitTrees = new javax.swing.JSplitPane(); pnlLeft = new javax.swing.JPanel(); lblInputTree = new javax.swing.JLabel(); pnlFirstDT = new javax.swing.JPanel(); pnlRight = new javax.swing.JPanel(); lblProjectivizeTree = new javax.swing.JLabel(); pnlProjectivizeDT = new javax.swing.JPanel(); lblViewMode = new javax.swing.JLabel(); cboViewMode = new javax.swing.JComboBox(); pnlDirection = new javax.swing.JPanel(); lblVertical = new javax.swing.JLabel(); lblHorizontal = new javax.swing.JLabel(); btnPrevChange = new javax.swing.JButton(); btnNextChange = new javax.swing.JButton(); pnlNavigation = new javax.swing.JPanel(); btnPrev = new javax.swing.JButton(); sliderSentences = new javax.swing.JSlider(); btnNext = new javax.swing.JButton(); lblCurrentTotal = new javax.swing.JLabel(); jLabel1 = new javax.swing.JLabel(); jPanel1 = new javax.swing.JPanel(); addHierarchyBoundsListener(new java.awt.event.HierarchyBoundsListener() { public void ancestorMoved(java.awt.event.HierarchyEvent evt) { } public void ancestorResized(java.awt.event.HierarchyEvent evt) { ProjectivizePanel_Resized(evt); } }); pnlParameter.setBorder(javax.swing.BorderFactory.createTitledBorder("Settings")); lblInputFile.setText("Input File:"); txtInputFile.setEditable(false); btnBrowseInputFile.setText("..."); btnBrowseInputFile.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnBrowseInputFile_Click(evt); } }); lblOutputPath.setText("Output Path:"); txtOutputPath.setEditable(false); btnBrowseOutputPath.setText("..."); btnBrowseOutputPath.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnBrowseOutputPath_Click(evt); } }); lblModelPath.setText("Model Path:"); txtModelPath.setEditable(false); btnBrowseModelPath.setText("..."); btnBrowseModelPath.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnBrowseModelPath_Click(evt); } }); lblMarkingStrategy.setText("Marking Strategy:"); cboMarkingStrategy.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "None", "Baseline", "Head", "Path", "Head+Path" })); cboMarkingStrategy.setSelectedItem("Head"); lblCoveredRoot.setText("Covered Root:"); cboCoveredRoot.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "None", "Ignore", "Left", "Right", "Head" })); cboCoveredRoot.setSelectedItem("Head"); cboCoveredRoot.setPreferredSize(new java.awt.Dimension(80, 20)); lblLiftingOrder.setText("Lifting Order:"); cboLiftingOrder.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Shortest", "Deepest" })); cboLiftingOrder.setSelectedItem("Head"); cboLiftingOrder.setPreferredSize(new java.awt.Dimension(80, 20)); btnStartProjectivize.setText("Start"); btnStartProjectivize.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnStartProjectivize_Click(evt); } }); javax.swing.GroupLayout pnlParameterLayout = new javax.swing.GroupLayout(pnlParameter); pnlParameter.setLayout(pnlParameterLayout); pnlParameterLayout.setHorizontalGroup( pnlParameterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pnlParameterLayout.createSequentialGroup() .addContainerGap() .addGroup(pnlParameterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pnlParameterLayout.createSequentialGroup() .addComponent(lblInputFile) .addGap(24, 24, 24) .addComponent(txtInputFile) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnBrowseInputFile, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlParameterLayout.createSequentialGroup() .addGroup(pnlParameterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(lblOutputPath) .addComponent(lblModelPath)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(pnlParameterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(txtModelPath) .addComponent(txtOutputPath)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(pnlParameterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(btnBrowseOutputPath, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(btnBrowseModelPath, javax.swing.GroupLayout.PREFERRED_SIZE, 1, Short.MAX_VALUE))) .addGroup(pnlParameterLayout.createSequentialGroup() .addComponent(lblMarkingStrategy) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(cboMarkingStrategy, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(34, 34, 34) .addComponent(lblCoveredRoot) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(cboCoveredRoot, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(49, 49, 49) .addComponent(lblLiftingOrder) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(cboLiftingOrder, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, Short.MAX_VALUE) .addComponent(btnStartProjectivize))) .addContainerGap()) ); pnlParameterLayout.setVerticalGroup( pnlParameterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pnlParameterLayout.createSequentialGroup() .addContainerGap() .addGroup(pnlParameterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(lblInputFile) .addComponent(txtInputFile, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(btnBrowseInputFile)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(pnlParameterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(lblOutputPath) .addComponent(txtOutputPath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(btnBrowseOutputPath)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(pnlParameterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(lblModelPath) .addComponent(txtModelPath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(btnBrowseModelPath)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(pnlParameterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pnlParameterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(btnStartProjectivize) .addComponent(lblLiftingOrder) .addComponent(cboLiftingOrder, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(lblCoveredRoot) .addComponent(cboCoveredRoot, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(pnlParameterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(lblMarkingStrategy) .addComponent(cboMarkingStrategy, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); txtLog.setColumns(20); txtLog.setEditable(false); txtLog.setRows(5); jScrollPane1.setViewportView(txtLog); javax.swing.GroupLayout pnlLogLayout = new javax.swing.GroupLayout(pnlLog); pnlLog.setLayout(pnlLogLayout); pnlLogLayout.setHorizontalGroup( pnlLogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 679, Short.MAX_VALUE) ); pnlLogLayout.setVerticalGroup( pnlLogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 158, Short.MAX_VALUE) ); tabDependencyInfo.addTab("Log", pnlLog); pnlTrees.addComponentListener(new java.awt.event.ComponentAdapter() { public void componentShown(java.awt.event.ComponentEvent evt) { pnlTrees_Shown(evt); } }); splitTrees.setDividerLocation(300); pnlLeft.setBackground(new java.awt.Color(255, 255, 255)); lblInputTree.setBackground(new java.awt.Color(255, 255, 255)); lblInputTree.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); lblInputTree.setText("Input Tree"); lblInputTree.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM); pnlFirstDT.setBackground(new java.awt.Color(255, 255, 255)); javax.swing.GroupLayout pnlFirstDTLayout = new javax.swing.GroupLayout(pnlFirstDT); pnlFirstDT.setLayout(pnlFirstDTLayout); pnlFirstDTLayout.setHorizontalGroup( pnlFirstDTLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 0, Short.MAX_VALUE) ); pnlFirstDTLayout.setVerticalGroup( pnlFirstDTLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 92, Short.MAX_VALUE) ); javax.swing.GroupLayout pnlLeftLayout = new javax.swing.GroupLayout(pnlLeft); pnlLeft.setLayout(pnlLeftLayout); pnlLeftLayout.setHorizontalGroup( pnlLeftLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(lblInputTree, javax.swing.GroupLayout.DEFAULT_SIZE, 299, Short.MAX_VALUE) .addComponent(pnlFirstDT, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) ); pnlLeftLayout.setVerticalGroup( pnlLeftLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pnlLeftLayout.createSequentialGroup() .addComponent(lblInputTree, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(pnlFirstDT, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); splitTrees.setLeftComponent(pnlLeft); pnlRight.setBackground(new java.awt.Color(255, 255, 255)); lblProjectivizeTree.setBackground(new java.awt.Color(255, 255, 255)); lblProjectivizeTree.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); lblProjectivizeTree.setText("Projectivize Tree"); lblProjectivizeTree.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM); pnlProjectivizeDT.setBackground(new java.awt.Color(255, 255, 255)); javax.swing.GroupLayout pnlProjectivizeDTLayout = new javax.swing.GroupLayout(pnlProjectivizeDT); pnlProjectivizeDT.setLayout(pnlProjectivizeDTLayout); pnlProjectivizeDTLayout.setHorizontalGroup( pnlProjectivizeDTLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 0, Short.MAX_VALUE) ); pnlProjectivizeDTLayout.setVerticalGroup( pnlProjectivizeDTLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 92, Short.MAX_VALUE) ); javax.swing.GroupLayout pnlRightLayout = new javax.swing.GroupLayout(pnlRight); pnlRight.setLayout(pnlRightLayout); pnlRightLayout.setHorizontalGroup( pnlRightLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(lblProjectivizeTree, javax.swing.GroupLayout.DEFAULT_SIZE, 373, Short.MAX_VALUE) .addComponent(pnlProjectivizeDT, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) ); pnlRightLayout.setVerticalGroup( pnlRightLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pnlRightLayout.createSequentialGroup() .addComponent(lblProjectivizeTree) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(pnlProjectivizeDT, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); splitTrees.setRightComponent(pnlRight); lblViewMode.setText("View Mode "); cboViewMode.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Inline Zoom", "Hierarchical Zoom", "NetGraph Zoom", "Inline Scroll" })); cboViewMode.addItemListener(new java.awt.event.ItemListener() { public void itemStateChanged(java.awt.event.ItemEvent evt) { cboViewMode_ValueChanged(evt); } }); pnlDirection.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(240, 240, 240))); lblVertical.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N lblVertical.setForeground(new java.awt.Color(153, 153, 153)); lblVertical.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ir/ac/iust/nlp/dependencyparser/evaluation/vertical.png"))); // NOI18N lblVertical.setText("Vertical "); lblVertical.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { lblVertical_mouseClick(evt); } public void mouseEntered(java.awt.event.MouseEvent evt) { lblVerticalpnlMore_mouseEnter(evt); } public void mouseExited(java.awt.event.MouseEvent evt) { lblVerticalpnlMore_mouseExit(evt); } }); lblHorizontal.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N lblHorizontal.setForeground(new java.awt.Color(153, 153, 153)); lblHorizontal.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ir/ac/iust/nlp/dependencyparser/evaluation/horizontal.png"))); // NOI18N lblHorizontal.setText("Horizontal"); lblHorizontal.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { lblHorizontal_mouseClick(evt); } public void mouseEntered(java.awt.event.MouseEvent evt) { lblHorizontalpnlMore_mouseEnter(evt); } public void mouseExited(java.awt.event.MouseEvent evt) { lblHorizontalpnlMore_mouseExit(evt); } }); javax.swing.GroupLayout pnlDirectionLayout = new javax.swing.GroupLayout(pnlDirection); pnlDirection.setLayout(pnlDirectionLayout); pnlDirectionLayout.setHorizontalGroup( pnlDirectionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlDirectionLayout.createSequentialGroup() .addGap(8, 8, 8) .addComponent(lblVertical, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(lblHorizontal) .addContainerGap()) ); pnlDirectionLayout.setVerticalGroup( pnlDirectionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pnlDirectionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(lblHorizontal, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(lblVertical, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)) ); btnPrevChange.setText("<< Prev Change"); btnPrevChange.setEnabled(false); btnPrevChange.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnPrevChangeActionPerformed(evt); } }); btnNextChange.setText("Next Change >>"); btnNextChange.setEnabled(false); btnNextChange.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnNextChangeActionPerformed(evt); } }); javax.swing.GroupLayout pnlTreesLayout = new javax.swing.GroupLayout(pnlTrees); pnlTrees.setLayout(pnlTreesLayout); pnlTreesLayout.setHorizontalGroup( pnlTreesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(splitTrees) .addGroup(pnlTreesLayout.createSequentialGroup() .addContainerGap() .addComponent(lblViewMode) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(cboViewMode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(48, 48, 48) .addComponent(btnPrevChange) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnNextChange) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(pnlDirection, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap()) ); pnlTreesLayout.setVerticalGroup( pnlTreesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlTreesLayout.createSequentialGroup() .addContainerGap() .addGroup(pnlTreesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(pnlTreesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(lblViewMode) .addComponent(cboViewMode, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(btnPrevChange) .addComponent(btnNextChange)) .addComponent(pnlDirection, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(splitTrees)) ); tabDependencyInfo.addTab("Tree", pnlTrees); btnPrev.setText("Prev"); btnPrev.setEnabled(false); btnPrev.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnPrev_Click(evt); } }); sliderSentences.setMaximum(0); sliderSentences.setEnabled(false); sliderSentences.addChangeListener(new javax.swing.event.ChangeListener() { public void stateChanged(javax.swing.event.ChangeEvent evt) { sliderSentences_StateChanged(evt); } }); btnNext.setText("Next"); btnNext.setEnabled(false); btnNext.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnNext_Click(evt); } }); lblCurrentTotal.setText("-/-"); javax.swing.GroupLayout pnlNavigationLayout = new javax.swing.GroupLayout(pnlNavigation); pnlNavigation.setLayout(pnlNavigationLayout); pnlNavigationLayout.setHorizontalGroup( pnlNavigationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pnlNavigationLayout.createSequentialGroup() .addContainerGap() .addComponent(btnPrev) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(sliderSentences, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnNext) .addGap(76, 76, 76) .addComponent(lblCurrentTotal) .addContainerGap()) ); pnlNavigationLayout.setVerticalGroup( pnlNavigationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlNavigationLayout.createSequentialGroup() .addGap(0, 0, Short.MAX_VALUE) .addGroup(pnlNavigationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(sliderSentences, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(btnPrev, javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(pnlNavigationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(lblCurrentTotal) .addComponent(btnNext)))) ); jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N jLabel1.setText("Projectivizing"); jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder()); jPanel1.setPreferredSize(new java.awt.Dimension(380, 2)); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 0, Short.MAX_VALUE) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 0, Short.MAX_VALUE) ); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(pnlNavigation, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(tabDependencyInfo, javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(pnlParameter, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 684, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup() .addComponent(jLabel1) .addGap(0, 0, Short.MAX_VALUE))) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(pnlParameter, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(tabDependencyInfo) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(pnlNavigation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) ); }// </editor-fold>//GEN-END:initComponents private void btnBrowseInputFile_Click(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBrowseInputFile_Click txtInputFile.setText(showFileDialog(txtInputFile.getText(), false)); }//GEN-LAST:event_btnBrowseInputFile_Click private void makeFormReady() { if (currentTempFolder != null) { File dir = new File(workingDir + File.separator + currentTempFolder); deleteDirectory(dir); } pnlFirstDT.removeAll(); pnlFirstDT.revalidate(); pnlProjectivizeDT.removeAll(); pnlProjectivizeDT.revalidate(); tabDependencyInfo.setEnabledAt(1, false); tabDependencyInfo.setSelectedIndex(0); btnStartProjectivize.setEnabled(false); } File dest_from; File dest_to; File model_from; File model_to; private void btnStartProjectivize_Click(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnStartProjectivize_Click gui = null; makeFormReady(); currentTempFolder = String.valueOf(Calendar.getInstance().getTimeInMillis()); String wd = "tmp" + File.separator + currentTempFolder; try { if (isInit == false) { isInit = true; String mark = cboMarkingStrategy.getSelectedItem().toString().toLowerCase(); String cover = cboCoveredRoot.getSelectedItem().toString().toLowerCase(); String order = cboLiftingOrder.getSelectedItem().toString().toLowerCase(); inputFile = txtInputFile.getText(); // Ensure have an absolute path File from = new File(inputFile).getAbsoluteFile(); String input = from.getName(); File to = new File(wd + File.separator + input); inputFile = to.getAbsolutePath(); // Copy input file to working directory if (!from.equals(to)) FileUtils.copyFile(from, to); String extension = input.substring(input.lastIndexOf(".") + 1, input.length()); outputFile = txtOutputPath.getText() + "projective_" + mark + "_" + cover + "_" + order + "." + extension; // Ensure have an absolute path dest_to = new File(outputFile).getAbsoluteFile(); String output = dest_to.getName(); dest_from = new File(wd + File.separator + output); outputFile = dest_from.getAbsolutePath(); String modelFile = txtModelPath.getText() + "projective_" + mark + "_" + cover + "_" + order + ".mco"; // Ensure have an absolute path model_to = new File(modelFile).getAbsoluteFile(); String modelName = model_to.getName(); model_from = new File(wd + File.separator + modelName); PrintStream out = new PrintStream(new OutputStream() { private StringBuffer buffer = new StringBuffer(); @Override public void write(int b) throws IOException { this.buffer.append((char) b); txtLog.setText(buffer.toString()); txtLog.setCaretPosition(txtLog.getDocument().getLength() - 1); } }); ProjectivizeCorpus.out = out; // Run in a new thread Runnable job = new RunnableProjectivize(this, TransformType.Projectivize, wd, input, output, modelName, mark, cover, order); ExecutorService threadPool = Executors.newFixedThreadPool(1); threadPool.execute(job); threadPool.shutdown(); } } catch (Exception ex) { JOptionPane.showMessageDialog( null, ex.getMessage(), "Reading Error", JOptionPane.ERROR_MESSAGE); try { File dir = new File(wd + File.separator); dir.deleteOnExit(); } catch (Exception e) {} isInit = false; } }//GEN-LAST:event_btnStartProjectivize_Click @Override public void threadFinished() { try { tabDependencyInfo.setEnabledAt(1, true); btnStartProjectivize.setEnabled(true); // Copy result to destination file if (!dest_from.equals(dest_to)) FileUtils.copyFile(dest_from, dest_to); // Copy model to destination file if (!model_from.equals(model_to)) FileUtils.copyFile(model_from, model_to); } catch (Exception e) { } finally { isInit = false; } } private void btnBrowseOutputPath_Click(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBrowseOutputPath_Click txtOutputPath.setText(showFileDialog(txtOutputPath.getText(), true)); }//GEN-LAST:event_btnBrowseOutputPath_Click private void ProjectivizePanel_Resized(java.awt.event.HierarchyEvent evt) {//GEN-FIRST:event_ProjectivizePanel_Resized AdjustDividerLocation(); ChangeViewMode(); }//GEN-LAST:event_ProjectivizePanel_Resized private void btnBrowseModelPath_Click(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBrowseModelPath_Click txtModelPath.setText(showFileDialog(txtModelPath.getText(), true)); }//GEN-LAST:event_btnBrowseModelPath_Click private void btnPrev_Click(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPrev_Click int val = sliderSentences.getValue(); int min = sliderSentences.getMinimum(); if (val > min) { sliderSentences.setValue(val - 1); } }//GEN-LAST:event_btnPrev_Click private void sliderSentences_StateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_sliderSentences_StateChanged try { UpdateTree(sliderSentences.getValue()); } catch (Exception ex) { } }//GEN-LAST:event_sliderSentences_StateChanged private void btnNext_Click(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNext_Click int val = sliderSentences.getValue(); int max = sliderSentences.getMaximum(); if (val < max) { sliderSentences.setValue(val + 1); } }//GEN-LAST:event_btnNext_Click private void pnlTrees_Shown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_pnlTrees_Shown if (splitTrees.getDividerLocation() == 0) { AdjustDividerLocation(); } try { if (gui == null && outputFile != null && outputFile.length() != 0) startGUI(); } catch(Exception ex) { } }//GEN-LAST:event_pnlTrees_Shown private void cboViewMode_ValueChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboViewMode_ValueChanged ChangeViewMode(); }//GEN-LAST:event_cboViewMode_ValueChanged private void lblVertical_mouseClick(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblVertical_mouseClick lblVertical.setVisible(false); lblHorizontal.setVisible(true); splitTrees.setOrientation(JSplitPane.HORIZONTAL_SPLIT); AdjustDividerLocation(); ChangeViewMode(); }//GEN-LAST:event_lblVertical_mouseClick private void lblVerticalpnlMore_mouseEnter(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblVerticalpnlMore_mouseEnter pnlDirection.setBackground(new Color(235, 232, 232)); pnlDirection.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(102, 102, 102), 1, false)); }//GEN-LAST:event_lblVerticalpnlMore_mouseEnter private void lblVerticalpnlMore_mouseExit(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblVerticalpnlMore_mouseExit pnlDirection.setBackground(new Color(240, 240, 240)); pnlDirection.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(240, 240, 240), 1, false)); }//GEN-LAST:event_lblVerticalpnlMore_mouseExit private void lblHorizontal_mouseClick(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblHorizontal_mouseClick lblHorizontal.setVisible(false); lblVertical.setVisible(true); splitTrees.setOrientation(JSplitPane.VERTICAL_SPLIT); AdjustDividerLocation(); ChangeViewMode(); }//GEN-LAST:event_lblHorizontal_mouseClick private void AdjustDividerLocation() { int area; if (lblHorizontal.isVisible() == false) area = splitTrees.getSize().height; else area = splitTrees.getSize().width; int loc = area / 2; splitTrees.setDividerLocation(loc); } private void lblHorizontalpnlMore_mouseEnter(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblHorizontalpnlMore_mouseEnter pnlDirection.setBackground(new Color(235, 232, 232)); pnlDirection.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(102, 102, 102), 1, false)); }//GEN-LAST:event_lblHorizontalpnlMore_mouseEnter private void lblHorizontalpnlMore_mouseExit(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblHorizontalpnlMore_mouseExit pnlDirection.setBackground(new Color(240, 240, 240)); pnlDirection.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(240, 240, 240), 1, false)); }//GEN-LAST:event_lblHorizontalpnlMore_mouseExit private void btnNextChangeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNextChangeActionPerformed if (sliderSentences.getValue() < sliderSentences.getMaximum()) { this.nextError.doClick(); lblCurrentTotal.setText(gui.getCurrentSentence() + " / " + gui.getSentenceCount()); sliderSentences.setValue(gui.getCurrentSentence()); } }//GEN-LAST:event_btnNextChangeActionPerformed private void btnPrevChangeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPrevChangeActionPerformed if (sliderSentences.getValue() > 0) { this.prevError.doClick(); lblCurrentTotal.setText(gui.getCurrentSentence() + " / " + gui.getSentenceCount()); sliderSentences.setValue(gui.getCurrentSentence()); } }//GEN-LAST:event_btnPrevChangeActionPerformed private void startGUI() throws Exception { String extension = inputFile.substring(inputFile.lastIndexOf(".") + 1, inputFile.length()); gui = new MaltTreeViewerGui( new String[]{outputFile}, extension, new String[]{inputFile}, extension); gui.setVisible(false); btnPrev.setEnabled(false); int size = gui.getSentenceCount(); if (size > 1) { btnNext.setEnabled(true); btnNextChange.setEnabled(true); btnPrevChange.setEnabled(true); } else { btnNext.setEnabled(false); btnNextChange.setEnabled(false); btnPrevChange.setEnabled(false); } lblCurrentTotal.setText("1 / " + size); sliderSentences.setMinimum(0); sliderSentences.setMaximum(size - 1); sliderSentences.setValue(0); sliderSentences.setEnabled(true); initTreeGui(); if (size == 1) UpdateTree(0); } private void ChangeViewMode() { if (gui != null) { gui.changeViewMode(cboViewMode.getSelectedIndex() + 1); } } private void UpdateTree(int index) throws MaltChainedException { gui.getCurrentSentenceListComponent().setSelectedSentence(index); gui.changeViewMode(cboViewMode.getSelectedIndex() + 1); TreeViewer tv = gui.getMediators().get(0); javax.swing.JPanel pnl = tv.getSplitPane(); pnlFirstDT.removeAll(); pnlFirstDT.setLayout(new GridLayout()); pnlFirstDT.add(pnl); pnlFirstDT.revalidate(); tv = gui.getMediators().get(1); pnl = tv.getSplitPane(); pnlProjectivizeDT.removeAll(); pnlProjectivizeDT.setLayout(new GridLayout()); pnlProjectivizeDT.add(pnl); pnlProjectivizeDT.revalidate(); lblCurrentTotal.setText((index + 1) + " / " + gui.getSentenceCount()); if (index == sliderSentences.getMaximum()) btnNext.setEnabled(false); else btnNext.setEnabled(true); if (index == sliderSentences.getMinimum()) btnPrev.setEnabled(false); else btnPrev.setEnabled(true); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton btnBrowseInputFile; private javax.swing.JButton btnBrowseModelPath; private javax.swing.JButton btnBrowseOutputPath; private javax.swing.JButton btnNext; private javax.swing.JButton btnNextChange; private javax.swing.JButton btnPrev; private javax.swing.JButton btnPrevChange; private javax.swing.JButton btnStartProjectivize; private javax.swing.JComboBox cboCoveredRoot; private javax.swing.JComboBox cboLiftingOrder; private javax.swing.JComboBox cboMarkingStrategy; private javax.swing.JComboBox cboViewMode; private javax.swing.JLabel jLabel1; private javax.swing.JPanel jPanel1; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JLabel lblCoveredRoot; private javax.swing.JLabel lblCurrentTotal; private javax.swing.JLabel lblHorizontal; private javax.swing.JLabel lblInputFile; private javax.swing.JLabel lblInputTree; private javax.swing.JLabel lblLiftingOrder; private javax.swing.JLabel lblMarkingStrategy; private javax.swing.JLabel lblModelPath; private javax.swing.JLabel lblOutputPath; private javax.swing.JLabel lblProjectivizeTree; private javax.swing.JLabel lblVertical; private javax.swing.JLabel lblViewMode; private javax.swing.JPanel pnlDirection; private javax.swing.JPanel pnlFirstDT; private javax.swing.JPanel pnlLeft; private javax.swing.JPanel pnlLog; private javax.swing.JPanel pnlNavigation; private javax.swing.JPanel pnlParameter; private javax.swing.JPanel pnlProjectivizeDT; private javax.swing.JPanel pnlRight; private javax.swing.JPanel pnlTrees; private javax.swing.JSlider sliderSentences; private javax.swing.JSplitPane splitTrees; private javax.swing.JTabbedPane tabDependencyInfo; private javax.swing.JTextField txtInputFile; private javax.swing.JTextArea txtLog; private javax.swing.JTextField txtModelPath; private javax.swing.JTextField txtOutputPath; // End of variables declaration//GEN-END:variables }