Beispiel #1
0
        public static SummarizedDocument Summarize(SummarizerArguments args)
        {
            if (args == null)
            {
                return(null);
            }

            Article article;

            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 summarizedDocument = CreateSummarizedDocument(article);

            return(summarizedDocument);
        }
Beispiel #2
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);
        }
Beispiel #3
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);
        }
Beispiel #4
0
    public static String Summarize(String text)
    {
        var summaryArgs = new SummarizerArguments();

        summaryArgs.DictionaryLanguage = "en";
        //summaryArgs.DisplayLines = 3;
        summaryArgs.DisplayPercent = 50;
        summaryArgs.InputString = text;

        SummarizedDocument doc = OpenTextSummarizer.Summarizer.Summarize(summaryArgs);
        var output = doc.Sentences;
        var summary = string.Concat(output.ToArray());

        return summary;
    }
Beispiel #5
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);
     }
 }
Beispiel #6
0
        /// <summary>
        /// encapsulates the algorithm for summarizing the help files
        /// </summary>
        /// <param name="toSummarize">responses from data access tier that will be summarized</param>
        public string[] summarize(string[] toSummarize)//List<QueryResponseList> toSummarize)
        {
            List <string> sumList = new List <string>();

            /*foreach (string input in getInputStringList(toSummarize))
             * {
             *  OpenTextSummarizer.SummarizerArguments args = new OpenTextSummarizer.SummarizerArguments();
             *  args.InputString = input;
             *  OpenTextSummarizer.SummarizedDocument sd = OpenTextSummarizer.Summarizer.Summarize(args);
             *  sumList.Add(sd.Sentences.Aggregate((x,y)=> { return x + y; }));
             * }
             * return sumList.ToArray();*/
            OpenTextSummarizer.SummarizerArguments args = new OpenTextSummarizer.SummarizerArguments();
            args.InputString = String.Join(" ", toSummarize);
            OpenTextSummarizer.SummarizedDocument sd = OpenTextSummarizer.Summarizer.Summarize(args);
            return(sd.Sentences.ToArray());
        }
        private DataFeed EnrichWithConcepts(DataFeed feed)
        {
            try
            {
                var args = new SummarizerArguments
                {
                    DictionaryLanguage = "en",
                    DisplayLines = 1,
                    InputString = feed.Title
                };

                var summary = Summarizer.Summarize(args);
                feed.Concepts = summary.Concepts.ToArray();
            }
            catch (Exception)
            {
            }
            
            return feed;
        }
        internal static void Highlight(Article article, SummarizerArguments args)
        {
            switch (args.DisplayPercent)
            {
            case 0 when args.DisplayLines == 0:

                return;

            case 0:

                //get the highest scored n lines, without reordering the list.
                SelectNumberOfSentences(article, args.DisplayLines);

                break;

            default:

                SelectSentencesByPercent(article, args.DisplayPercent);

                break;
            }
        }
Beispiel #9
0
        private static Article ParseFile(string fileName, SummarizerArguments args)
        {
            string text = LoadFile(fileName);

            return(ParseDocument(text, args));
        }
Beispiel #10
0
        static void summarizeData(string query)
        {
            outputLabelText("   SUMMARIZING:", query);
            string finalSummary = "";
            string outputFileSummaryFinal = System.IO.Path.GetFullPath(query.Replace(":", "-")) + "\\index.html";
            string outputFileSummaryRaw = System.IO.Path.GetFullPath(query.Replace(":", "-")) + "\\__summaryRaw.txt";
            System.IO.StreamReader file = new System.IO.StreamReader(outputFileSummaryRaw);
            string row = "";
            //string summary = "";
            while ((row = file.ReadLine()) != null)
            {
                if (row != cr.ToString() || row != cr.ToString() + lf.ToString())  {
                    //summary += row + System.Environment.NewLine;

                    string[] split = row.Split(delimiter.ToCharArray());
                    string g = split[0];
                    string url = split[1];
                    string title = split[2];
                    string data = split[3];

                    var uri = new Uri(url);

                    var host = uri.Host;

                    SummarizerArguments sumargs = new SummarizerArguments();
                    sumargs.DictionaryLanguage = "en";
                    sumargs.DisplayLines = 10;
                    sumargs.DisplayPercent = 0;
                    sumargs.InputString = data;
                    SummarizedDocument doc = Summarizer.Summarize(sumargs);

                    var concepts = doc.Concepts.Select(p => p + ", ");
                    finalSummary += "<h1>" + title + "<span class='datasource'>versions: <a href='pages\\" + g + ".html' target='_blank'>local</a> | <a href='" + url + "' target='_blank'>web</a></span></h1>" + System.Environment.NewLine;
                    finalSummary += "<blockquote>";
                    finalSummary += "<p><strong>Site:</strong> " + host + "</p>";

                    var conceptSumary = doc.Concepts
                        .Where(p => p.ToString() != "" && p.Length >= 3)
                        .Select(p => "<li>'" + p + "'</li>");

                    finalSummary += "<h2>Concepts</h2><ul>" + string.Concat(conceptSumary.ToArray()) + "</ul>";
                    finalSummary += System.Environment.NewLine + System.Environment.NewLine;

                    var sentenceSummary = doc.Sentences
                        .Select(p => "<li>" + p.Trim() + "</li>");
                    string oneMore = string.Concat(sentenceSummary.ToArray());

                    foreach (string c in doc.Concepts) {
                        if (c.Length > 3) {
                            oneMore = oneMore.Replace(c, "<span class='hlPink'>" + c + "</span>");
                        }
                    }

                    foreach (string c in query.Split(' '))
                    {
                        if ((c.Length > 3) && (!c.StartsWith("-")))
                        {
                            oneMore = oneMore.Replace(c, "<span class='hlYellow'>" + c + "</span>");
                        }
                    }

                    finalSummary += "<h2>Summary</h2><ul>" + oneMore + "</ul>";
                    finalSummary += "</blockquote>";
                    finalSummary += System.Environment.NewLine + System.Environment.NewLine + System.Environment.NewLine + "<hr>";

                }
            }

            #region
            //SummarizerArguments sumargs = new SummarizerArguments();
            //sumargs.DictionaryLanguage = "en";
            //sumargs.DisplayLines = 10;
            //sumargs.DisplayPercent = 0;
            //sumargs.InputString = summary;
            //SummarizedDocument doc = Summarizer.Summarize(sumargs);

            //var concepts = doc.Concepts.Select(p => p + ", ");
            //finalSummary += "Concepts - [" + string.Concat(concepts.ToArray()) + "]";
            //finalSummary += System.Environment.NewLine + System.Environment.NewLine;
            //var sentenceSummary = doc.Sentences.Select(p => p + System.Environment.NewLine + System.Environment.NewLine);
            //finalSummary += "Sentence Summary - " + System.Environment.NewLine + string.Concat(sentenceSummary.ToArray()) + "]";
            #endregion

            string outputTemplate = htmlTemplate;
            outputTemplate = outputTemplate
                .Replace("{{query}}", query)
                .Replace("{{timeStamp}}", DateTime.Now.ToString("dd MMM yyyy HH:mm"))
                .Replace("{{output}}", finalSummary);

            //string finalSummary = string.Join("\r\n\r\n", doc.Sentences.ToArray());
            // do some stuff with summary. It is your result.
            System.IO.File.WriteAllText(outputFileSummaryFinal, outputTemplate);
            Process.Start(outputFileSummaryFinal);
        }