示例#1
0
        private ImageDTO backgroundProcessingParagraph(ImageDTO data)
        {
            Bitmap imageRaw             = data.Raw;
            var    lengthGaussianFilter = Convert.ToInt32(numLengthGaussian.Value);
            var    weightGaussianFilter = Convert.ToInt32(numWeightGaussian.Value);

            preprocessing = new Preprocessing.Preprocessing(imageRaw, lengthGaussianFilter, weightGaussianFilter);

            data.GrayScalling = preprocessing.GrayscalingImage;
            data.Gaussian     = preprocessing.FilterImage;
            data.Binary       = preprocessing.RemoveBorderImage;

            var imageListGrayscalling = new ImageList {
                ImageSize = new Size(1000, 1000)
            };
            var imageListGaussian = new ImageList {
                ImageSize = new Size(1000, 1000)
            };
            var imageListBinary = new ImageList {
                ImageSize = new Size(1000, 1000)
            };

            imageListGrayscalling.Images.Add(data.ClassName, data.GrayScalling);
            imageListGaussian.Images.Add(data.ClassName, data.Gaussian);
            imageListBinary.Images.Add(data.ClassName, data.Binary);
            var classNames = new List <string>();

            classNames.Add(data.ClassName);

            setImagetoListView(listViewGrayscallingParagraph, imageListGrayscalling, classNames.ToArray());
            setImagetoListView(listViewGaussianFilteringParagraph, imageListGaussian, classNames.ToArray());
            setImagetoListView(listViewBinerisasiParagraph, imageListBinary, classNames.ToArray());
            return(data);
        }
示例#2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Summarization.LuhnMethod"/> class.
        /// </summary>
        public LuhnMethod(Preprocessing.Preprocessing preprocEngine, string text, string title)
        {
            prep = preprocEngine;

            idf       = prep.IDF;
            medianIDF = prep.MedianIDF;

            rawText    = text;
            this.title = title + " " + this.title;
        }
示例#3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Summarization.Heuristic"/> class.
 /// </summary>
 /// <param name='rawText'>
 /// Raw text.
 /// </param>
 /// <param name='title'>
 /// Title.
 /// </param>
 /// <param name='lang'>
 /// Language of input text.
 /// </param>
 public Heuristic(Preprocessing.Preprocessing prepEngine, string rawText, string title)
 {
     this.rawText = rawText;
     if (title != "")
     {
         this.title = title;
     }
     else
     {
         this.title = null;
     }
     prep = prepEngine;
 }
示例#4
0
        private List <ImageDTO> backgroundPreprocessing(List <ImageDTO> imageDTOs, List <ListView> inFormListView)
        {
            int    lengthGaussianFilter  = Convert.ToInt32(numLengthGaussian.Value);
            double weightGaussianFilter  = Convert.ToDouble(numWeightGaussian.Value);
            var    imageListGrayscalling = new ImageList {
                ImageSize = new Size(200, 200)
            };
            var imageListGaussian = new ImageList {
                ImageSize = new Size(200, 200)
            };
            var imageListBinary = new ImageList {
                ImageSize = new Size(200, 200)
            };

            Parallel.For(0, imageDTOs.Count, i =>
            {
                ImageDTO imageDTO     = imageDTOs[i];
                preprocessing         = new Preprocessing.Preprocessing(imageDTO.Raw, lengthGaussianFilter, weightGaussianFilter);
                imageDTO.GrayScalling = preprocessing.GrayscalingImage;
                imageDTO.Gaussian     = preprocessing.FilterImage;
                resizeImage           = new ResizeImage(preprocessing.RemoveBorderImage, Constants.FIX_WIDTH, Constants.FIX_HEIGHT);
                imageDTO.Binary       = resizeImage.Output;

                imageDTOs[i] = imageDTO;
            });
            List <string> classNames = new List <string>();

            for (int i = 0; i < imageDTOs.Count; i++)
            {
                ImageDTO imageDTO = imageDTOs[i];
                imageListGrayscalling.Images.Add(imageDTO.ClassName, imageDTO.GrayScalling);
                imageListGaussian.Images.Add(imageDTO.ClassName, imageDTO.Gaussian);
                imageListBinary.Images.Add(imageDTO.ClassName, imageDTO.Binary);
                classNames.Add(imageDTO.ClassName);
            }

            setImagetoListView(inFormListView[0] /*listViewGrayscallingTraining*/, imageListGrayscalling, classNames.ToArray());
            setImagetoListView(inFormListView[1] /*listViewGaussianFilteringTraining*/, imageListGaussian, classNames.ToArray());
            setImagetoListView(inFormListView[2] /*listViewBinerisasiTraining*/, imageListBinary, classNames.ToArray());
            return(imageDTOs);
        }
示例#5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Summarization.LSA"/> class.
        /// </summary>
        /// <param name='text'>
        /// Text.
        /// </param>
        /// <param name='jazyk'>
        /// Jazyk.
        /// </param>
        /// <param name='useCZ_IDF'>
        /// Use C z_ identifier.
        /// </param>
        public LSA(Preprocessing.Preprocessing prepEngine, string text, string title, bool useCZ_IDF)
        {
            prep        = prepEngine;
            this.useIDF = useCZ_IDF;
            this.file   = text;
            string temp;

            if (title != "")
            {
                if (jazyk == "cz")
                {
                    temp = prep.GetLemma(new string[] { title }, (int)DateTime.Now.Ticks)[0].LemmatizedText;
                }
                //temp = prep.GetLemma(new string[] { title }, (int)DateTime.Now.Ticks, "hunspell", "cs")[0].LemmatizedText;
                else
                {
                    temp = title;
                }
                this.titleLem = temp.Split(separatorsWord, StringSplitOptions.RemoveEmptyEntries);
            }
        }
示例#6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Summarization.Randomsents"/> class.
 /// </summary>
 /// <param name='text'>
 /// Text.
 /// </param>
 public Randomsents(Preprocessing.Preprocessing prepEngine, string text)
 {
     prep    = prepEngine;
     rawText = text;
 }
示例#7
0
        public void Spust(Object state)
        {
            Console.WriteLine("spousti se sumarizacni vlakno");
            try
            {
                Encoding encoder = Encoding.UTF8;
                if (client == null)
                {
                    throw new Exception("client je null");
                }
                Summarization.SummarizationMethod summary = null;
                NetworkStream webStream = client.GetStream();
                string        ipPort    = client.Client.RemoteEndPoint.ToString();
                string        ip        = ipPort.Remove(ipPort.IndexOf(':'), ipPort.Length - ipPort.IndexOf(':'));
                ///TODO: replace with ip
                if (ip == Dns.GetHostAddresses("localhost")[1].ToString() || ip == "replace with ip" || ip == "replace with ip")
                {
                    bool received = false;
                    while (received == false)
                    {
                        if (webStream.DataAvailable)
                        {
                            Console.WriteLine("Prichozi zprava v " + DateTime.Now);

                            byte[] message = new byte[client.ReceiveBufferSize];
                            client.Client.Receive(message);
                            string msg = encoder.GetString(message);
                            // Console.WriteLine("Client: " + msg);
                            received = true;

                            XmlDocument doc = new XmlDocument();
                            try
                            {
                                doc.LoadXml(msg);
                                doc.Save("zprava.xml");
                                XmlNode root  = doc.DocumentElement;
                                XmlNode node  = root.SelectSingleNode("title");
                                string  title = node.InnerText;
                                if (title == "")
                                {
                                    title = "důležitý významný výsledek"; //TODO: replace with wider list
                                }
                                node = root.SelectSingleNode("text");
                                string text = node.InnerText.Replace("\r\n\r\n", ".\r\n\r\n").Replace("\n\n", ".\n\n");
                                node = root.SelectSingleNode("lang");
                                string lang = node.InnerText;
                                node = root.SelectSingleNode("sumCount");
                                bool procenta = true;
                                uint sumCount = 5;
                                if (node.InnerText.Length != 0)
                                {
                                    procenta = false;
                                    try
                                    {
                                        sumCount = Convert.ToUInt32(node.InnerText);
                                    }

                                    catch (FormatException)
                                    {
                                        Console.WriteLine("Prisel nespravny pocet vet (chyba konvertace):" + sumCount);
                                        sumCount = 5;
                                    }
                                }
                                else
                                {
                                    sumCount = 25;
                                    node     = root.SelectSingleNode("percent");
                                    try
                                    {
                                        sumCount = Convert.ToUInt32(node.InnerText);
                                    }
                                    catch (FormatException)
                                    {
                                        Console.WriteLine("Chyba v zadani procent (chyba konvertace):" + sumCount);
                                        sumCount = 25;
                                    }
                                }
                                node = root.SelectSingleNode("method");
                                string metoda = node.InnerText;

                                if (!Enum.GetValues(typeof(Preprocessing.Preprocessing.Language))
                                    .Cast <Preprocessing.Preprocessing.Language>()
                                    .Select(v => v.ToString())
                                    .ToList().Contains(lang))
                                {
                                    lang = "sr";
                                }
                                Console.WriteLine("Vstup nacten");

                                text = text.Replace("\r", "\n");

                                if (lang != prepMorp.Lang.ToString())
                                {
                                    prepMorp = new Preprocessing.Preprocessing(new FileInfo("linux.cfg/Preprocessing." + lang + ".txt"));
                                    Console.WriteLine("Preprocessing change to " + lang);
                                }

                                int      COS = 0;
                                string[] sum = new string[] { "" };
                                if ("heuristic" == metoda)
                                {
                                    summary = new Summarization.Heuristic(prepMorp, text, title);
                                }

                                if ("statistic" == metoda)
                                {
                                    summary = new Summarization.LuhnMethod(prepMorp, text, title);
                                }

                                if ("LSA" == metoda)
                                {
                                    summary = new Summarization.LSA(prepMorp, text, title, false);
                                }

                                if ("LSAIDF" == metoda)
                                {
                                    summary = new Summarization.LSA(prepMorp, text, title, true);
                                }

                                summary.CreateSummary();
                                COS = summary.CountOfsents();
                                if (!procenta)
                                {
                                    sum = summary.GetSummaryByCountOfsents(sumCount);
                                }
                                else
                                {
                                    sum = summary.GetSummaryByPercentOfText(sumCount);
                                }

                                string text2CL = "";
                                try
                                {
                                    text2CL = summary.LemmatizedText();
                                }
                                catch (NullReferenceException nre)
                                {
                                    client.Client.Send(encoder.GetBytes(HttpUtility.HtmlEncode("neošetřená chyba při preprocesingu")));
                                    throw new ApplicationException("neošetřená chyba při preprocesingu");
                                }

                                try
                                {
                                    StringBuilder response = new StringBuilder();
                                    response.AppendLine("<summary>Nastaveni: <br/> Jazyk:<span id='lang'>" + lang + "</span> <br/>Rozsah souhrnu:<span id='ratio'>");
                                    if (procenta)
                                    {
                                        response.AppendLine(sumCount + "% (" + Math.Round((double)((double)sumCount / 100) * (COS)) + " vět)</span>");
                                    }
                                    else
                                    {
                                        response.AppendLine(Math.Round((double)(sumCount * 100) / COS) + "% (" + sumCount + " vět)</span>");
                                    }
                                    response.AppendLine("<br/>Celkem vět:" + COS + "<br/><br/><br/>");
                                    response.AppendLine("<h3>Summary:</h3><div id='summary'>");
                                    foreach (string sentence in sum)
                                    {
                                        try
                                        {
                                            response.AppendLine(sentence + "<br/><br/>");
                                        }
                                        catch (NullReferenceException e)
                                        {
                                            response.AppendLine("chybna veta <br/><br/>");
                                            Console.WriteLine(e.Data);
                                        }
                                    }
                                    response.AppendLine("</div></summary>");
                                    client.Client.Send(encoder.GetBytes(HttpUtility.HtmlEncode(response.ToString())));
                                }
                                catch (Exception e)
                                { Console.WriteLine(e.StackTrace); Console.WriteLine(lang + " " + sumCount + " " + sum + "." + sum.Length); }
                            }
                            catch (XmlException)
                            {
                                Console.WriteLine("Příchozí komunikace nebyla ve formátu XML! => zahazuji");
                            }
                        }
                    }
                }
                else
                {
                    client.Client.Send(Encoding.UTF8.GetBytes(HttpUtility.HtmlEncode("Spatna IP clienta.")));
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                client.Client.Send(Encoding.UTF8.GetBytes(HttpUtility.HtmlEncode("Chyba:" + e.Message + "</br>" + e.StackTrace)));
            }
            client.Client.Disconnect(true);
            client = null;
        }