Java tutorial
/* * 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 summarizer; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JFileChooser; import javax.swing.filechooser.FileNameExtensionFilter; import twitter4j.Query; import twitter4j.QueryResult; import twitter4j.Status; import twitter4j.Twitter; import twitter4j.TwitterException; import twitter4j.TwitterFactory; import twitter4j.conf.ConfigurationBuilder; /** * * @author Surya */ public class NewApplication extends javax.swing.JFrame { /** * Creates new form NewApplication */ public NewApplication() { initComponents(); StartPageLabel.setVisible(false); StartPageTextArea.setVisible(false); EndPageLabel.setVisible(false); EndPageTextArea.setVisible(false); } /** * 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() { TextFileChooser = new javax.swing.JFileChooser(); IntroPanel = new javax.swing.JPanel(); Heading = new javax.swing.JLabel(); StartButton = new javax.swing.JButton(); HelpButton = new javax.swing.JButton(); ExitButton = new javax.swing.JButton(); MainPanel = new javax.swing.JPanel(); jScrollPane1 = new javax.swing.JScrollPane(); InputTextArea = new javax.swing.JTextArea(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); ChooseFileButton = new javax.swing.JButton(); jLabel3 = new javax.swing.JLabel(); ThresholdTextField = new javax.swing.JTextField(); MainPanelBackButton = new javax.swing.JButton(); SummarizeButton = new javax.swing.JButton(); jLabel4 = new javax.swing.JLabel(); HashtagTextField = new javax.swing.JTextField(); HashtagSearchButton = new javax.swing.JButton(); jLabel5 = new javax.swing.JLabel(); TwitterComboBox = new javax.swing.JComboBox(); StartPageLabel = new javax.swing.JLabel(); StartPageTextArea = new javax.swing.JTextField(); EndPageLabel = new javax.swing.JLabel(); EndPageTextArea = new javax.swing.JTextField(); FinalOutputPanel = new javax.swing.JPanel(); ExportAsTxtButton = new javax.swing.JButton(); ExportAsPdfButton = new javax.swing.JButton(); SummarizeOtherButton = new javax.swing.JButton(); jSplitPane1 = new javax.swing.JSplitPane(); jScrollPane2 = new javax.swing.JScrollPane(); SummaryOutputTextArea = new javax.swing.JTextArea(); jScrollPane3 = new javax.swing.JScrollPane(); SummaryInputTextArea = new javax.swing.JTextArea(); jLabel6 = new javax.swing.JLabel(); jLabel7 = new javax.swing.JLabel(); HelpPanel = new javax.swing.JPanel(); jLabel8 = new javax.swing.JLabel(); jLabel9 = new javax.swing.JLabel(); jLabel10 = new javax.swing.JLabel(); jLabel11 = new javax.swing.JLabel(); jLabel12 = new javax.swing.JLabel(); jLabel13 = new javax.swing.JLabel(); jLabel14 = new javax.swing.JLabel(); jLabel15 = new javax.swing.JLabel(); jLabel16 = new javax.swing.JLabel(); jLabel17 = new javax.swing.JLabel(); jLabel18 = new javax.swing.JLabel(); jLabel19 = new javax.swing.JLabel(); jLabel20 = new javax.swing.JLabel(); jLabel21 = new javax.swing.JLabel(); jLabel22 = new javax.swing.JLabel(); HelpBackButton = new javax.swing.JButton(); menuBar = new javax.swing.JMenuBar(); fileMenu = new javax.swing.JMenu(); openMenuItem = new javax.swing.JMenuItem(); saveMenuItem = new javax.swing.JMenuItem(); saveAsMenuItem = new javax.swing.JMenuItem(); exitMenuItem = new javax.swing.JMenuItem(); editMenu = new javax.swing.JMenu(); cutMenuItem = new javax.swing.JMenuItem(); copyMenuItem = new javax.swing.JMenuItem(); pasteMenuItem = new javax.swing.JMenuItem(); deleteMenuItem = new javax.swing.JMenuItem(); helpMenu = new javax.swing.JMenu(); contentsMenuItem = new javax.swing.JMenuItem(); aboutMenuItem = new javax.swing.JMenuItem(); TextFileChooser.setApproveButtonText("Okay"); TextFileChooser.setApproveButtonToolTipText("Open selected file"); TextFileChooser.setDialogTitle("Open"); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setMinimumSize(new java.awt.Dimension(850, 550)); setPreferredSize(new java.awt.Dimension(800, 550)); getContentPane().setLayout(new java.awt.CardLayout()); Heading.setFont(new java.awt.Font("Tahoma", 1, 36)); // NOI18N Heading.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); Heading.setText("TEXT SUMMARIZER"); StartButton.setText("Start"); StartButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { StartButtonActionPerformed(evt); } }); HelpButton.setText("Help"); HelpButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { HelpButtonActionPerformed(evt); } }); ExitButton.setText("Exit"); ExitButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { ExitButtonActionPerformed(evt); } }); javax.swing.GroupLayout IntroPanelLayout = new javax.swing.GroupLayout(IntroPanel); IntroPanel.setLayout(IntroPanelLayout); IntroPanelLayout.setHorizontalGroup(IntroPanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(IntroPanelLayout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(IntroPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(Heading, javax.swing.GroupLayout.PREFERRED_SIZE, 407, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(IntroPanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addComponent(ExitButton, javax.swing.GroupLayout.DEFAULT_SIZE, 234, Short.MAX_VALUE) .addComponent(HelpButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(StartButton, javax.swing.GroupLayout.DEFAULT_SIZE, 234, Short.MAX_VALUE))) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); IntroPanelLayout .setVerticalGroup( IntroPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup( IntroPanelLayout.createSequentialGroup().addGap(47, 47, 47) .addComponent(Heading, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(82, 82, 82) .addComponent(StartButton, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(29, 29, 29) .addComponent(HelpButton, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(35, 35, 35) .addComponent(ExitButton, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(144, Short.MAX_VALUE))); getContentPane().add(IntroPanel, "card2"); InputTextArea.setColumns(20); InputTextArea.setRows(5); jScrollPane1.setViewportView(InputTextArea); jLabel1.setText("Search Hashtag"); jLabel2.setText("or Choose a file"); ChooseFileButton.setText("Choose File"); ChooseFileButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { ChooseFileButtonActionPerformed(evt); } }); jLabel3.setText("Output % :"); jLabel3.setToolTipText("Indicates the percentage of selected lines to be shown in final summary"); ThresholdTextField.setText("50"); ThresholdTextField .setToolTipText("Indicates the percentage of selected lines to be shown in final summary"); MainPanelBackButton.setText("< Back"); MainPanelBackButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { MainPanelBackButtonActionPerformed(evt); } }); SummarizeButton.setText("Summarize >"); SummarizeButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { SummarizeButtonActionPerformed(evt); } }); jLabel4.setText("a value between (0,100)"); HashtagTextField.setToolTipText("Enter a word to search"); HashtagSearchButton.setText("Go"); HashtagSearchButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { HashtagSearchButtonActionPerformed(evt); } }); jLabel5.setFont(new java.awt.Font("Ubuntu", 0, 13)); // NOI18N jLabel5.setText("or Type text to be summarized"); TwitterComboBox .setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Mixed", "Recent", "Popular" })); StartPageLabel.setText("Starting Page :"); StartPageTextArea.setText("1"); EndPageLabel.setText("Ending Page :"); EndPageTextArea.setText("2"); EndPageTextArea.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { EndPageTextAreaActionPerformed(evt); } }); javax.swing.GroupLayout MainPanelLayout = new javax.swing.GroupLayout(MainPanel); MainPanel.setLayout(MainPanelLayout); MainPanelLayout.setHorizontalGroup(MainPanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(MainPanelLayout.createSequentialGroup().addContainerGap().addGroup(MainPanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(MainPanelLayout.createSequentialGroup().addGroup(MainPanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane1) .addGroup(MainPanelLayout.createSequentialGroup().addComponent(MainPanelBackButton) .addGap(0, 0, Short.MAX_VALUE)) .addGroup(MainPanelLayout.createSequentialGroup().addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(HashtagTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(TwitterComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(HashtagSearchButton) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel5) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(ChooseFileButton))) .addContainerGap()) .addGroup(MainPanelLayout.createSequentialGroup().addComponent(jLabel3) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(ThresholdTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(3, 3, 3).addComponent(jLabel4).addGap(36, 36, 36) .addComponent(StartPageLabel) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(StartPageTextArea, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18).addComponent(EndPageLabel) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(EndPageTextArea, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(SummarizeButton).addGap(32, 32, 32))))); MainPanelLayout.setVerticalGroup(MainPanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(MainPanelLayout.createSequentialGroup().addComponent(MainPanelBackButton) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(MainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(MainPanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1).addComponent(jLabel2).addComponent(ChooseFileButton) .addComponent(HashtagTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(TwitterComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(HashtagSearchButton))) .addGap(5, 5, 5) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 391, Short.MAX_VALUE) .addGap(18, 18, 18) .addGroup(MainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel3) .addComponent(ThresholdTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(SummarizeButton).addComponent(jLabel4).addComponent(StartPageLabel) .addComponent(StartPageTextArea, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(EndPageLabel).addComponent(EndPageTextArea, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(29, 29, 29))); getContentPane().add(MainPanel, "card3"); ExportAsTxtButton.setText("Export as .txt"); ExportAsPdfButton.setText("Export as PDF"); SummarizeOtherButton.setText("Summarize Other Text"); SummarizeOtherButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { SummarizeOtherButtonActionPerformed(evt); } }); SummaryOutputTextArea.setEditable(false); SummaryOutputTextArea.setColumns(20); SummaryOutputTextArea.setRows(5); jScrollPane2.setViewportView(SummaryOutputTextArea); jSplitPane1.setRightComponent(jScrollPane2); SummaryInputTextArea.setEditable(false); SummaryInputTextArea.setColumns(20); SummaryInputTextArea.setRows(5); jScrollPane3.setViewportView(SummaryInputTextArea); jSplitPane1.setLeftComponent(jScrollPane3); jLabel6.setText("INPUT TEXT"); jLabel7.setText("SUMMARIZED OUTPUT "); javax.swing.GroupLayout FinalOutputPanelLayout = new javax.swing.GroupLayout(FinalOutputPanel); FinalOutputPanel.setLayout(FinalOutputPanelLayout); FinalOutputPanelLayout.setHorizontalGroup( FinalOutputPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(FinalOutputPanelLayout.createSequentialGroup().addContainerGap() .addGroup(FinalOutputPanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jSplitPane1) .addGroup(FinalOutputPanelLayout.createSequentialGroup() .addComponent(ExportAsTxtButton).addGap(18, 18, 18) .addComponent(ExportAsPdfButton) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(SummarizeOtherButton))) .addContainerGap()) .addGroup(FinalOutputPanelLayout.createSequentialGroup().addGap(21, 21, 21) .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 365, Short.MAX_VALUE) .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 182, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(183, 183, 183))); FinalOutputPanelLayout.setVerticalGroup(FinalOutputPanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(FinalOutputPanelLayout.createSequentialGroup().addGap(8, 8, 8) .addGroup(FinalOutputPanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel6).addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 443, Short.MAX_VALUE) .addGap(18, 18, 18) .addGroup(FinalOutputPanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(ExportAsTxtButton).addComponent(ExportAsPdfButton) .addComponent(SummarizeOtherButton)) .addContainerGap())); getContentPane().add(FinalOutputPanel, "card4"); jLabel8.setFont(new java.awt.Font("Ubuntu", 1, 24)); // NOI18N jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel8.setText("INSTRUCTIONS"); jLabel9.setFont(new java.awt.Font("Ubuntu", 0, 14)); // NOI18N jLabel9.setText("Click the start button."); jLabel10.setFont(new java.awt.Font("Ubuntu", 0, 18)); // NOI18N jLabel10.setText("To Summarize Text files :"); jLabel11.setFont(new java.awt.Font("Ubuntu", 0, 14)); // NOI18N jLabel11.setText("Enter the hashtag/word to be searched."); jLabel12.setFont(new java.awt.Font("Ubuntu", 0, 14)); // NOI18N jLabel12.setText("Select the search result : mixed, recent or popular."); jLabel13.setFont(new java.awt.Font("Ubuntu", 0, 14)); // NOI18N jLabel13.setText( "Click \"go\" button, and wait for sometime, inorder to fetch the recent/popular/mixed tweets."); jLabel14.setFont(new java.awt.Font("Ubuntu", 0, 14)); // NOI18N jLabel14.setText("Input the output %, which is by default 50."); jLabel15.setFont(new java.awt.Font("Ubuntu", 0, 14)); // NOI18N jLabel15.setText("Click the summarize button."); jLabel16.setFont(new java.awt.Font("Ubuntu", 0, 18)); // NOI18N jLabel16.setText("To Summarize Twitter Tweets :"); jLabel17.setFont(new java.awt.Font("Ubuntu", 0, 14)); // NOI18N jLabel17.setText("Click the choose button and select the text file(.txt) which is to be summarized."); jLabel18.setFont(new java.awt.Font("Ubuntu", 0, 14)); // NOI18N jLabel18.setText("Click the summarize button."); jLabel19.setFont(new java.awt.Font("Ubuntu", 0, 18)); // NOI18N jLabel19.setText("To Summarize PDF files :"); jLabel20.setFont(new java.awt.Font("Ubuntu", 0, 14)); // NOI18N jLabel20.setText("Click the choose button and select the pdf file(.pdf) which is to be summarized."); jLabel21.setFont(new java.awt.Font("Ubuntu", 0, 14)); // NOI18N jLabel21.setText("Input the starting and ending page numbers of the pdf which are to be summarized."); jLabel22.setFont(new java.awt.Font("Ubuntu", 0, 14)); // NOI18N jLabel22.setText("Click the summarize button."); HelpBackButton.setText("< Back"); HelpBackButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { HelpBackButtonActionPerformed(evt); } }); javax.swing.GroupLayout HelpPanelLayout = new javax.swing.GroupLayout(HelpPanel); HelpPanel.setLayout(HelpPanelLayout); HelpPanelLayout.setHorizontalGroup(HelpPanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(HelpPanelLayout.createSequentialGroup().addGroup(HelpPanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(HelpPanelLayout.createSequentialGroup().addContainerGap() .addComponent(HelpBackButton, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(226, 226, 226).addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 211, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(HelpPanelLayout.createSequentialGroup().addGap(97, 97, 97) .addGroup(HelpPanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel12).addComponent(jLabel11).addComponent(jLabel13) .addComponent(jLabel14).addComponent(jLabel15))) .addGroup(HelpPanelLayout.createSequentialGroup().addGap(85, 85, 85) .addGroup(HelpPanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel16).addComponent(jLabel9))) .addGroup(HelpPanelLayout.createSequentialGroup().addGap(85, 85, 85) .addGroup(HelpPanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel10).addComponent(jLabel19) .addGroup(HelpPanelLayout.createSequentialGroup().addGap(12, 12, 12) .addGroup(HelpPanelLayout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel18).addComponent(jLabel17) .addComponent(jLabel20).addComponent(jLabel21) .addComponent(jLabel22)))))) .addContainerGap(184, Short.MAX_VALUE))); HelpPanelLayout.setVerticalGroup(HelpPanelLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(HelpPanelLayout.createSequentialGroup().addContainerGap() .addGroup(HelpPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(HelpBackButton)) .addGap(31, 31, 31).addComponent(jLabel9) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jLabel16).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel11).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel12).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel13).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel14).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel15) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jLabel10).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel17).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel18).addGap(18, 18, 18).addComponent(jLabel19) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jLabel20) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jLabel21) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jLabel22) .addContainerGap(100, Short.MAX_VALUE))); getContentPane().add(HelpPanel, "card5"); fileMenu.setMnemonic('f'); fileMenu.setText("File"); openMenuItem.setMnemonic('o'); openMenuItem.setText("Open"); fileMenu.add(openMenuItem); saveMenuItem.setMnemonic('s'); saveMenuItem.setText("Save"); fileMenu.add(saveMenuItem); saveAsMenuItem.setMnemonic('a'); saveAsMenuItem.setText("Save As ..."); saveAsMenuItem.setDisplayedMnemonicIndex(5); fileMenu.add(saveAsMenuItem); 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); editMenu.setMnemonic('e'); editMenu.setText("Edit"); cutMenuItem.setMnemonic('t'); cutMenuItem.setText("Cut"); editMenu.add(cutMenuItem); copyMenuItem.setMnemonic('y'); copyMenuItem.setText("Copy"); editMenu.add(copyMenuItem); pasteMenuItem.setMnemonic('p'); pasteMenuItem.setText("Paste"); editMenu.add(pasteMenuItem); deleteMenuItem.setMnemonic('d'); deleteMenuItem.setText("Delete"); editMenu.add(deleteMenuItem); menuBar.add(editMenu); helpMenu.setMnemonic('h'); helpMenu.setText("Help"); contentsMenuItem.setMnemonic('c'); contentsMenuItem.setText("Contents"); helpMenu.add(contentsMenuItem); aboutMenuItem.setMnemonic('a'); aboutMenuItem.setText("About"); helpMenu.add(aboutMenuItem); menuBar.add(helpMenu); setJMenuBar(menuBar); 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 StartButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_StartButtonActionPerformed // TODO add your handling code here: IntroPanel.setVisible(false); MainPanel.setVisible(true); FinalOutputPanel.setVisible(false); }//GEN-LAST:event_StartButtonActionPerformed private void ExitButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ExitButtonActionPerformed // TODO add your handling code here: System.exit(0); }//GEN-LAST:event_ExitButtonActionPerformed private void MainPanelBackButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MainPanelBackButtonActionPerformed // TODO add your handling code here: MainPanel.setVisible(false); IntroPanel.setVisible(true); FinalOutputPanel.setVisible(false); HelpPanel.setVisible(false); }//GEN-LAST:event_MainPanelBackButtonActionPerformed private void SummarizeOtherButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SummarizeOtherButtonActionPerformed // TODO add your handling code here: IntroPanel.setVisible(false); MainPanel.setVisible(true); FinalOutputPanel.setVisible(false); HelpPanel.setVisible(false); }//GEN-LAST:event_SummarizeOtherButtonActionPerformed private void SummarizeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SummarizeButtonActionPerformed // TODO add your handling code here: String fileName = filePath; // Input fileName int noLines = Integer.parseInt(ThresholdTextField.getText()); // output percentage //boolean pdfB = false; //If the input is pdf set to true else false int pdfStartPage = 14; // Starting page of the pdf int pdfEndPage = 16; // till Page of extraction boolean newLine = true; // List<String> allStrings ; int threshold = 10; // BufferedReader in = null; // String s = ""; List<String> allStrings = new ArrayList<String>(); String s = ""; BufferedReader in = null; if (!"".equals(fileName)) { //System.out.println(fileName.substring(fileName.length()-3,fileName.length())); //System.out.println(fileName.substring(fileName.length()-3,fileName.length())); if ("pdf".equals(fileName.substring(fileName.length() - 3, fileName.length()))) { //System.out.println("PDF"); pdfReader pd = new pdfReader(); allStrings = pd.parsePdf(fileName, pdfStartPage, pdfEndPage, newLine); } else { //System.out.println("Mot pdf"); try { in = new BufferedReader(new FileReader(fileName)); } catch (FileNotFoundException ex) { Logger.getLogger(NewApplication.class.getName()).log(Level.SEVERE, null, ex); } try { while ((s = in.readLine()) != null) { if (s.compareTo("") != 0) { allStrings.add(s); } } } catch (IOException ex) { Logger.getLogger(NewApplication.class.getName()).log(Level.SEVERE, null, ex); } } } else { for (String line : InputTextArea.getText().split("\\n")) { if (line.compareTo("") != 0) { allStrings.add(line); } } } String inputSummary = ""; for (int i = 0; i < allStrings.size(); i++) { inputSummary += i + "-> " + allStrings.get(i) + "\n"; } SummaryInputTextArea.setText(inputSummary); //*************************Finding Cosine Similary Graph**********************// CosineSimilarity cs = new CosineSimilarity(); PrintWriter writer = null; try { writer = new PrintWriter("graph.wpairs", "UTF-8"); } catch (FileNotFoundException ex) { Logger.getLogger(NewApplication.class.getName()).log(Level.SEVERE, null, ex); } catch (UnsupportedEncodingException ex) { Logger.getLogger(NewApplication.class.getName()).log(Level.SEVERE, null, ex); } double[][] similarity = new double[allStrings.size()][allStrings.size()]; for (int i = 0; i < (allStrings.size()); i++) { for (int j = i; j < (allStrings.size()); j++) { double sim = cs.CosineSimilarity_Score(allStrings.get(i), allStrings.get(j)); double si = sim * 100; int num = (int) si; // System.out.println("num = "+ num+ " sim "+sim); if ((i != j) && (sim != 0) && (!Double.isNaN(sim)) && (sim >= (threshold / 100)) && (num > 0)) { writer.println(i + " " + j + " " + num); similarity[i][j] = sim; } else { if (i == j) { similarity[i][j] = 1.00; } else { similarity[i][j] = 0.00; } } } } writer.close(); noLines = (int) Math.floor(allStrings.size() * (float) noLines / 100); //*************************Finding communities**********************// File f = new File("FastCommunity_wMH"); //./FastCommunity_wMH -f current.wpairs -l firstRun if (f.exists() && !f.isDirectory()) { Process process = null; try { process = Runtime.getRuntime().exec("./FastCommunity_wMH -f graph.wpairs -l firstRun"); } catch (IOException ex) { Logger.getLogger(NewApplication.class.getName()).log(Level.SEVERE, null, ex); } try { process.waitFor(); } catch (InterruptedException ex) { Logger.getLogger(NewApplication.class.getName()).log(Level.SEVERE, null, ex); } } int i = 0; List<List<Integer>> modules = new ArrayList<List<Integer>>(); int selectedIndex = 0; int minModuleSize = 9999; for (int k = 1; k < allStrings.size(); k++) { if (f.exists() && !f.isDirectory()) { Process process = null; try { process = Runtime.getRuntime().exec("./FastCommunity_wMH -f graph.wpairs -l secondRun -c " + k); } catch (IOException ex) { Logger.getLogger(NewApplication.class.getName()).log(Level.SEVERE, null, ex); } try { process.waitFor(); } catch (InterruptedException ex) { Logger.getLogger(NewApplication.class.getName()).log(Level.SEVERE, null, ex); } } BufferedReader in1 = null; try { in1 = new BufferedReader(new FileReader("graph-fc_secondRun.groups")); } catch (FileNotFoundException ex) { Logger.getLogger(NewApplication.class.getName()).log(Level.SEVERE, null, ex); } List<Integer> tempList = new ArrayList<Integer>(); try { s = in1.readLine(); } catch (IOException ex) { Logger.getLogger(NewApplication.class.getName()).log(Level.SEVERE, null, ex); } try { while ((s = in1.readLine()) != null) { if (s.compareTo("") != 0) { if ((s.charAt(0) == 'G')) { modules.add(tempList); tempList = new ArrayList<Integer>(); } else { tempList.add(Integer.valueOf(s)); } } } } catch (IOException ex) { Logger.getLogger(NewApplication.class.getName()).log(Level.SEVERE, null, ex); } modules.add(tempList); //System.out.println(k+ "-> Size of modules is "+modules.size() + " Minmodulesize = " + minModuleSize + " no Lines = "+ noLines + " selectedIndex " + selectedIndex); if (Math.abs(modules.size() - noLines) < minModuleSize) { minModuleSize = Math.abs(modules.size() - noLines); selectedIndex = k; } modules = new ArrayList<List<Integer>>(); } //System.out.println("no Lines = "+ noLines + " minModuleSize "+ minModuleSize + " selectedIndex " + selectedIndex); if (f.exists() && !f.isDirectory()) { Process process; try { process = Runtime.getRuntime() .exec("./FastCommunity_wMH -f graph.wpairs -l secondRun -c " + selectedIndex); process.waitFor(); } catch (IOException ex) { Logger.getLogger(NewApplication.class.getName()).log(Level.SEVERE, null, ex); } catch (InterruptedException ex) { Logger.getLogger(NewApplication.class.getName()).log(Level.SEVERE, null, ex); } } BufferedReader in1 = null; try { in1 = new BufferedReader(new FileReader("graph-fc_secondRun.groups")); } catch (FileNotFoundException ex) { Logger.getLogger(NewApplication.class.getName()).log(Level.SEVERE, null, ex); } List<Integer> tempList = new ArrayList<Integer>(); try { s = in1.readLine(); } catch (IOException ex) { Logger.getLogger(NewApplication.class.getName()).log(Level.SEVERE, null, ex); } try { while ((s = in1.readLine()) != null) { if (s.compareTo("") != 0) { if ((s.charAt(0) == 'G')) { modules.add(tempList); tempList = new ArrayList<Integer>(); } else { tempList.add(Integer.valueOf(s)); } } } } catch (IOException ex) { Logger.getLogger(NewApplication.class.getName()).log(Level.SEVERE, null, ex); } modules.add(tempList); //*************************Build Lex Rank **********************// /* for(i = 0;i < allStrings.size();i++) for(int j = 0;j < allStrings.size();j++) System.out.println(similarity[i][j]); */ List<DummyItem> items = new ArrayList<DummyItem>(); for (i = 0; i < similarity.length; ++i) { items.add(new DummyItem(i, similarity)); } LexRankResults<DummyItem> results = LexRanker.rank(items, 0.2, true); String[] names = { "d1s1", "d2s1", "d2s2", "d2s3", "d3s1", "d3s2", "d3s3", "d4s1", "d5s1", "d5s2", "d5s3" }; double max = results.scores.get(results.rankedResults.get(0)); // System.out.println("Max is "+max + "similarity "+ similarity.length); /* for (i = 0; i < similarity.length; ++i) { System.out.println(i + ": " + (results.scores.get(items.get(i)) / max)); } */ //*************************Another Algo for Lex Rank **********************// double[] sum = new double[similarity.length]; int[] degree = new int[similarity.length]; for (i = 0; i < similarity.length; i++) { sum[i] = 0; for (int j = 1; j < similarity.length; j++) { if (similarity[i][j] > threshold / 100) { sum[i] = similarity[i][j] + sum[i]; degree[i]++; } } } /* System.out.println("** The ranking is ** "); for (i = 0; i < similarity.length; i++) { System.out.println("for " + i + ": " + sum[i] / degree[i] + " sum : " + sum[i] + " degree : " + degree[i]); } */ //*************************Generating Output **********************// int[] selected = new int[modules.size()]; i = 0; for (List<Integer> tempL : modules) { selected[i] = tempL.get(0); double x = sum[tempL.get(0)] / degree[tempL.get(0)]; for (Integer y : tempL) { if ((sum[y] / degree[y]) > x) { x = (sum[y] / degree[y]); selected[i] = y; } } i++; } String finsummary = ""; Arrays.sort(selected); for (i = 0; i < selected.length; i++) { finsummary += selected[i] + " -> " + allStrings.get(selected[i]) + "\n"; } SummaryOutputTextArea.setText(finsummary); MainPanel.setVisible(false); IntroPanel.setVisible(false); FinalOutputPanel.setVisible(true); HelpPanel.setVisible(false); }//GEN-LAST:event_SummarizeButtonActionPerformed private void ChooseFileButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ChooseFileButtonActionPerformed // TODO add your handling code here: FileNameExtensionFilter filter = new FileNameExtensionFilter(".pdf", "pdf"); TextFileChooser.setFileFilter(filter); filter = new FileNameExtensionFilter(".txt", "txt", "text"); TextFileChooser.setFileFilter(filter); filter = new FileNameExtensionFilter("Text Documents", "txt", "text", "pdf"); TextFileChooser.setFileFilter(filter); int returnval = TextFileChooser.showOpenDialog(this); if (returnval == JFileChooser.APPROVE_OPTION) { filePath = TextFileChooser.getSelectedFile().getAbsolutePath(); if ("pdf".equals(TextFileChooser.getSelectedFile().getName().substring( TextFileChooser.getSelectedFile().getName().length() - 3, TextFileChooser.getSelectedFile().getName().length()))) { StartPageLabel.setVisible(true); StartPageTextArea.setVisible(true); EndPageLabel.setVisible(true); EndPageTextArea.setVisible(true); } else { StartPageLabel.setVisible(false); StartPageTextArea.setVisible(false); EndPageLabel.setVisible(false); EndPageTextArea.setVisible(false); } InputTextArea.setText(filePath); } }//GEN-LAST:event_ChooseFileButtonActionPerformed private void HashtagSearchButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_HashtagSearchButtonActionPerformed // TODO add your handling code here: ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("uEeExq1FHARMvAGTJAY0dGxPh") .setOAuthConsumerSecret("jMcofTKFsayd4bpA6HFNlgkMfiveoS3ffRSCy9FCSs9pWYqdAD") .setOAuthAccessToken("2443437752-PrbVsDrQCxthX3T7lV3dtHs3FCXFXfBBHsdNrOS") .setOAuthAccessTokenSecret("MbauBu7R6vUUKqFD9ogK7VTIfce4nmvewYsgYqBOQ2ZbC"); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance(); String hashtag; hashtag = HashtagTextField.getText(); Query query = new Query(hashtag); query.count(100); if (TwitterComboBox.getSelectedIndex() == 0) { query.resultType(Query.ResultType.mixed); } else if (TwitterComboBox.getSelectedIndex() == 0) { query.resultType(Query.ResultType.recent); } else { query.resultType(Query.ResultType.popular); } QueryResult result = null; try { result = twitter.search(query); } catch (TwitterException ex) { Logger.getLogger(NewApplication.class.getName()).log(Level.SEVERE, null, ex); } String alltweets = "", temp = ""; for (Status status : result.getTweets()) { temp = status.getText(); temp = temp.replaceAll("[\\t\\n\\r]", " "); if (!"".equals(temp)) { if ("RT".equals(temp.substring(0, 2))) { temp = temp.split(":", 2)[1]; } alltweets += (temp + "\n"); } } InputTextArea.setText(alltweets); }//GEN-LAST:event_HashtagSearchButtonActionPerformed private void EndPageTextAreaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_EndPageTextAreaActionPerformed // TODO add your handling code here: }//GEN-LAST:event_EndPageTextAreaActionPerformed private void HelpButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_HelpButtonActionPerformed // TODO add your handling code here: IntroPanel.setVisible(false); MainPanel.setVisible(false); FinalOutputPanel.setVisible(false); HelpPanel.setVisible(true); }//GEN-LAST:event_HelpButtonActionPerformed private void HelpBackButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_HelpBackButtonActionPerformed // TODO add your handling code here: IntroPanel.setVisible(true); MainPanel.setVisible(false); FinalOutputPanel.setVisible(false); HelpPanel.setVisible(false); }//GEN-LAST:event_HelpBackButtonActionPerformed /** * @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 ex) { java.util.logging.Logger.getLogger(NewApplication.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(NewApplication.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(NewApplication.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(NewApplication.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 NewApplication().setVisible(true); } }); } String filePath = ""; // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton ChooseFileButton; private javax.swing.JLabel EndPageLabel; private javax.swing.JTextField EndPageTextArea; private javax.swing.JButton ExitButton; private javax.swing.JButton ExportAsPdfButton; private javax.swing.JButton ExportAsTxtButton; private javax.swing.JPanel FinalOutputPanel; private javax.swing.JButton HashtagSearchButton; private javax.swing.JTextField HashtagTextField; private javax.swing.JLabel Heading; private javax.swing.JButton HelpBackButton; private javax.swing.JButton HelpButton; private javax.swing.JPanel HelpPanel; private javax.swing.JTextArea InputTextArea; private javax.swing.JPanel IntroPanel; private javax.swing.JPanel MainPanel; private javax.swing.JButton MainPanelBackButton; private javax.swing.JButton StartButton; private javax.swing.JLabel StartPageLabel; private javax.swing.JTextField StartPageTextArea; private javax.swing.JButton SummarizeButton; private javax.swing.JButton SummarizeOtherButton; private javax.swing.JTextArea SummaryInputTextArea; private javax.swing.JTextArea SummaryOutputTextArea; private javax.swing.JFileChooser TextFileChooser; private javax.swing.JTextField ThresholdTextField; private javax.swing.JComboBox TwitterComboBox; private javax.swing.JMenuItem aboutMenuItem; private javax.swing.JMenuItem contentsMenuItem; private javax.swing.JMenuItem copyMenuItem; private javax.swing.JMenuItem cutMenuItem; private javax.swing.JMenuItem deleteMenuItem; private javax.swing.JMenu editMenu; private javax.swing.JMenuItem exitMenuItem; private javax.swing.JMenu fileMenu; private javax.swing.JMenu helpMenu; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel10; private javax.swing.JLabel jLabel11; private javax.swing.JLabel jLabel12; private javax.swing.JLabel jLabel13; private javax.swing.JLabel jLabel14; private javax.swing.JLabel jLabel15; private javax.swing.JLabel jLabel16; private javax.swing.JLabel jLabel17; private javax.swing.JLabel jLabel18; private javax.swing.JLabel jLabel19; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel20; private javax.swing.JLabel jLabel21; private javax.swing.JLabel jLabel22; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel6; private javax.swing.JLabel jLabel7; private javax.swing.JLabel jLabel8; private javax.swing.JLabel jLabel9; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JScrollPane jScrollPane3; private javax.swing.JSplitPane jSplitPane1; private javax.swing.JMenuBar menuBar; private javax.swing.JMenuItem openMenuItem; private javax.swing.JMenuItem pasteMenuItem; private javax.swing.JMenuItem saveAsMenuItem; private javax.swing.JMenuItem saveMenuItem; // End of variables declaration//GEN-END:variables }