コード例 #1
0
        private static Article ParseDocument(string text, SummarizerArguments args)
        {
            Dictionary rules   = Dictionary.LoadFromFile(args.DictionaryLanguage);
            Article    article = new Article(rules);

            article.ParseText(text);
            return(article);
        }
コード例 #2
0
        private static SummarizedDocument CreateSummarizedDocument(Article article, SummarizerArguments args)
        {
            SummarizedDocument sumDoc = new SummarizedDocument();

            sumDoc.Concepts = article.Concepts;
            foreach (Sentence sentence in article.Sentences)
            {
                if (sentence.Selected)
                {
                    sumDoc.Sentences.Add(sentence.OriginalSentence);
                }
            }
            return(sumDoc);
        }
コード例 #3
0
 internal static void Highlight(Article article, SummarizerArguments args)
 {
     if (args.DisplayPercent == 0 && args.DisplayLines == 0)
     {
         return;
     }
     if (args.DisplayPercent == 0)
     {
         //get the highest scored n lines, without reordering the list.
         SelectNumberOfSentences(article, args.DisplayLines);
     }
     else
     {
         SelectSentencesByPercent(article, args.DisplayPercent);
     }
 }
コード例 #4
0
        private void button2_Click(object sender, EventArgs e)
        {
            string    text;
            string    word = textBox2.Text;
            WebClient web  = new WebClient();

            HtmlAgilityPack.HtmlDocument Htmldoc = new HtmlAgilityPack.HtmlDocument();
            Process.Start("https://en.wikipedia.org/wiki/" + word);
            byte[] byteArray = web.DownloadData(new Uri("https://en.wikipedia.org/wiki/" + word));
            Stream stream    = new MemoryStream(byteArray);

            Htmldoc.Load(stream);
            FileStream fs     = new FileStream("D:\\htmltext.pdf", FileMode.Create, FileAccess.Write, FileShare.None);
            Document   pdfDoc = new Document();
            PdfWriter  writer = PdfWriter.GetInstance(pdfDoc, fs);

            pdfDoc.Open();
            foreach (HtmlNode node in Htmldoc.DocumentNode.SelectNodes("//text()"))
            {
                text = node.InnerText.Trim();
                pdfDoc.Add(new Paragraph(text));
            }
            pdfDoc.Close();

            if (textBox2.Text != null)
            {
                int sentCount = 1;
                int.TryParse(textBox3.Text, out sentCount);
                SummarizerArguments sumargs = new SummarizerArguments
                {
                    DictionaryLanguage = "en",
                    DisplayLines       = sentCount,
                    DisplayPercent     = 0,
                    InputFile          = @"D:\\htmltext.pdf",
                };
                SummarizedDocument doc     = Summarizer.Summarize(sumargs);
                string             summary = string.Join("\r\n\r\n", doc.Sentences.ToArray());
                richTextBox1.Text = summary;
            }
            else
            {
                richTextBox1.Text = "Please give the query value!!!";
            }
        }
コード例 #5
0
        public static SummarizedDocument Summarize(SummarizerArguments args)
        {
            if (args == null)
            {
                return(null);
            }
            Article article = null;

            if (args.InputString.Length > 0 && args.InputFile.Length == 0)
            {
                article = ParseDocument(args.InputString, args);
            }
            else
            {
                article = ParseFile(args.InputFile, args);
            }
            Grader.Grade(article);
            Highlighter.Highlight(article, args);
            SummarizedDocument sumdoc = CreateSummarizedDocument(article, args);

            return(sumdoc);
        }
コード例 #6
0
 private void button3_Click(object sender, EventArgs e)
 {
     if (textBox1.Text != null)
     {
         int sentCount = 1;
         int.TryParse(SentenceCountTextBox.Text, out sentCount);
         SummarizerArguments sumargs = new SummarizerArguments
         {
             DictionaryLanguage = "en",
             DisplayLines       = sentCount,
             DisplayPercent     = 0,
             InputFile          = textBox1.Text
         };
         SummarizedDocument doc     = Summarizer.Summarize(sumargs);
         string             summary = string.Join("\r\n\r\n", doc.Sentences.ToArray());
         richTextBox1.Text = summary;
     }
     else
     {
         richTextBox1.Text = "Sorry there is no file!!!";
     }
 }
コード例 #7
0
        private static Article ParseFile(string fileName, SummarizerArguments args)
        {
            string text = LoadFile(fileName);

            return(ParseDocument(text, args));
        }