You are on page 1of 8

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.

Forms; using System.IO; using Word = Microsoft.Office.Interop.Word; namespace Project2009 { public partial class Summarizer : Form { Double i; public Summarizer() { InitializeComponent(); }private void label1_Click(object sender, EventArgs e) {}private void label3_Click(object sender, EventArgs e) { } private void Form1_Load(object sender, EventArgs e) { button3.Visible = false; MessageBox.Show("This program was developed as Final Year Project by Nitish Raj, Parantap Das and Nishant of Dr. MGR University, CSE Dept, 20052009 batch under the guidence of Mrs. Sumathi Eswaran."); }private void button2_Click(object sender, EventArgs e) { String path = textBox1.Text;

String keyword = textBox2.Text; String outdir = textBox3.Text; String summary_name = textBox4.Text; if (keyword.Length == 0) { MessageBox.Show("Oops! It seems you forgot to provide a keyword.Please provide a keyword."); goto Exit_error; }try{ Word_to_Text_Converter.converter(path); Formatting_Module.Formatter(@"C:\Program Files\Sonu\Summarizer\convertedtext.txt"); path = @"C:\Program Files\Sonu\Summarizer\convertedtext.txt"; } catch { goto Error2; }if (outdir.Length == 0) { try { String related_word = Database_Retriever.ConnectAndQuery(keyword); if (related_word == null) { richTextBox1.Text = "Keyword not in database. Please enter the keyword along with related words"; }else if (related_word == "DNE") { related_word = textBox3.Text; Writer.Write(keyword, related_word); //Application.Exit(); }else

{ Scoring_Module.score(keyword, related_word); } }catch { richTextBox1.Text = "Invalid format for related words. Please enter related words as shown: related_word1,related_word2,related_word3,related_word4,related_word5."; goto Error; } }else { try { Scoring_Module.score(keyword, outdir); String related_word = Database_Retriever.ConnectAndQuery(keyword); if (related_word == "DNE") Writer.Write(keyword, outdir); }catch { richTextBox1.Text = "Invalid format for related words. Please enter related words as shown: related_word1,related_word2,related_word3,related_word4,related_word5."; goto Error; } }Double initial_count = Counter.line_count(path); Double level_of_summarization = Summary_Generator.Summary_Write(initial_count,0); Writer.final_summary(summary_name); String disp_text = @"C:\Program Files\Sonu\Summarizer\" + summary_name + ".txt"; richTextBox1.Text = File.ReadAllText(disp_text); goto Msg; Error: { MessageBox.Show("Sorry!There was an exception during the

processing.Please try again."); Application.Exit(); goto X; } Error2: { MessageBox.Show("Unrecognised File Format.Please input a plaintext or Ms-Word file."); Application.Restart(); goto X; } Exit_error: { Application.Exit(); Application.Restart(); goto X; } Msg: { MessageBox.Show("Summarization is complete!"); button3.Visible = true; } X: { String s = "k"; } }private void button1_Click(object sender, EventArgs e) { OpenFileDialog dig = new OpenFileDialog(); dig.ShowDialog(); String str = dig.FileName; textBox1.Text = str; }private void label5_Click(object sender, EventArgs e) {} private void textBox4_TextChanged(object sender, EventArgs e)

{} private void button3_Click(object sender, EventArgs e) { i += 0.75; //int i = 0; String path = textBox1.Text; String summary_name = textBox4.Text; Double initial_count = Counter.line_count(path); Double level_of_summarization = Summary_Generator.Summary_Write(initial_count, i); Writer.final_summary(summary_name); String disp_text = @"C:\Program Files\Sonu\Summarizer\" + summary_name + ".txt"; richTextBox1.Text = File.ReadAllText(disp_text); MessageBox.Show("Done"); } }internal class Formatting_Module { internal static void Formatter(String path) { String npath = path, noutdir = @"C:\Program Files\Sonu\Summarizer\Temp.txt";

String temp = a; a = b; b = temp; return (a);

} internal static Double Summary_Write(Double initial_count,Double new_var) { String in_path = @"C:\Program Files\Sonu\Summarizer\temp1.txt"; String pathname_of_temp_file = @"C:\Program Files\Sonu\Summarizer\Temp_summary.txt"; Double score_max = max_score_calc(in_path); Double score_min = min_score_calc(in_path); Double score_temp = (score_max - score_min) / 2 + new_var; min_score_eliminator(in_path, score_temp); Double count_temp = Counter.line_count(pathname_of_temp_file); Double level_of_summarization = (count_temp / initial_count) * 100; return (level_of_summarization); }internal static Double max_score_calc(String path) { using (StreamReader sr = new StreamReader(@path)) { double max_score = 0, temp_score; String line; while ((line = sr.ReadLine()) != null) { temp_score = summa(line); if (temp_score > max_score) max_score = temp_score; }return (max_score); } } }internal class Writer { internal static void Write(String keyword, String rel_words) { String path = @"C:\Program Files\Sonu\Summarizer\keyword.txt";

String file_text = File.ReadAllText(path); file_text = file_text + keyword + " " + rel_words; using (StreamWriter sw = File.CreateText(path)) sw.WriteLine(file_text); }internal static void final_summary(string path) { String write_path = @"C:\Program Files\Sonu\Summarizer\" + path + ".txt"; using (StreamReader sr = new StreamReader(@"C:\Program Files\Sonu\Summarizer\Temp_Summary.txt")) using (StreamWriter sw = new StreamWriter(@write_path)) { String line; String text_write; while ((line = sr.ReadLine()) != null) { text_write = summ_wri(line); sw.WriteLine(text_write); } } } internal static String summ_wri(string line) { String s; if (line.Length >= 4) s = line.Substring(4); else s = ""; return (s); } }internal class Word_to_Text_Converter { internal static void converter(String path) { object fileName = @path ;

object oMissing = System.Reflection.Missing.Value; object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */ //Start Word and create a new document. Word._Application oWord; Word._Document oDoc; oWord = new Word.Application(); oWord.Visible = false; oDoc = oWord.Documents.Open(ref fileName, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,ref oMissing, ref oMissing, ref oMissing, ref oMissing,ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing); oDoc.ActiveWindow.Selection.WholeStory(); oDoc.ActiveWindow.Selection.Copy(); IDataObject data = Clipboard.GetDataObject(); String text = data.GetData(DataFormats.Text).ToString(); oDoc.Close(ref oMissing, ref oMissing, ref oMissing); oWord.Quit(ref oMissing, ref oMissing, ref oMissing); using (StreamWriter sw = new StreamWriter(@"C:\Program Files\Sonu\Summarizer\convertedtext.txt")) sw.WriteLine(text); } } }

You might also like