コード例 #1
0
        public ActionResult UploadFile(HttpPostedFileBase file, string abstractPercent = "20", string targetLanguage = "hi", string textType = "Default")
        {
            try
            {
                var summarization = new Summarization();
                summarization.supportedLanguages = summarization.GetSupportedAzureTranslationLanguages();
                ViewBag.supportedLanguages       = ToSelectList(summarization.supportedLanguages);

                if (file?.ContentLength > 0 || file?.ContentLength < 22528)
                {
                    if (!string.IsNullOrEmpty(file.FileName))
                    {
                        string extension = Path.GetExtension(file.FileName);
                        if (!".txt".Equals(extension?.ToLower()))
                        {
                            ViewBag.Message = "Please upload text file with extension '.txt'";
                            return(View());
                        }

                        var lines = new List <string>();
                        using (StreamReader reader = new StreamReader(file.InputStream))
                        {
                            do
                            {
                                string textLine = reader.ReadLine();
                                if (!string.IsNullOrEmpty(textLine))
                                {
                                    lines.Add(textLine);
                                }
                            } while (reader.Peek() != -1);
                        }
                        var keyPhraseExtract           = new KeyPhraseExtract();
                        List <RawTextAnalytics> result = keyPhraseExtract.ExtractEntities(lines, textType);
                        ViewBag.Message             = "File Analyzed Successfully!!";
                        ViewBag.logFileContent      = String.Join("", lines);
                        ViewBag.AnalyzedFileContent = result;

                        summarization.allInputLineDelimitedByDot = lines;
                        summarization.summaryTextAnalyticsList   = keyPhraseExtract.CreateSummary(abstractPercent);
                        summarization.targetTranslationLanguage  = targetLanguage; // ToDo Use summarization.supportedLanguages to take input
                        summarization.translatedText             = summarization.TranslateSummary();

                        ViewBag.SummarizedContent = string.Join("", summarization.translatedText);
                    }
                }
                else
                {
                    ViewBag.Message = "File content is too less(<0) or too long(>22528).";
                }
                return(View());
            }
            catch (Exception ex)
            {
                ViewBag.Message = "File upload failed!!";
                return(View());
            }
        }
コード例 #2
0
        public ActionResult TextEntityLinking(string inputFile)
        {
            //var response = AnalyticsClient.RecognizeLinkedEntities(
            //    "Microsoft was founded by Bill Gates and Paul Allen on April 4, 1975, " +
            //    "to develop and sell BASIC interpreters for the Altair 8800. " +
            //    "During his career at Microsoft, Gates held the positions of chairman, " +
            //    "chief executive officer, president and chief software architect, " +
            //    "while also being the largest individual shareholder until May 2014.");
            string[] lines            = System.IO.File.ReadAllLines(inputFile);
            var      keyPhraseExtract = new KeyPhraseExtract();
            //It seems that this path is not used.
            List <RawTextAnalytics> result = keyPhraseExtract.ExtractEntities(lines, "Default");

            return(PartialView(result));
        }