Exemple #1
0
        private void FrmSettings_Load(object sender, EventArgs e)
        {
            txtRegExp.Text = Utils.StgGetString("TxtRegExp").Replace(@"\\", @"\");

            if (Utils.StgGetInt("TxtCodepage") == 0)
            {
                comboBox1.Text = "Автоопределение";
            }
            else
            {
                // Saved encoding
                Encoding enc = Encoding.GetEncoding(Utils.StgGetInt("TxtCodepage"));
                comboBox1.Text = enc.WebName;
            }
        }
Exemple #2
0
        public FrmMain()
        {
            /*  ANNOTATION
             *  The software should be able to read pdf,doc,txt and odf
             *  The software should take all files in the input folder and read them one at a time
             *  The software should prepare lists of words with their frequencie
             *  The software should be awesome
             *
             *  TODO:
             *  1.v  Import doc, docx reader library
             *  2.v  Import pdf reader library
             *  3.v  Import odf reader library
             *  4.v  Create functions for each supporting format
             *  5.v  Create open file dialog to show the location of files
             *  6.v  List the files filtering the extension
             *  7.v  Take a file, read all of its contents
             *  8.v  Scan through file and create a list of frequencies for each file
             *  9.v  Sum-up the frequency files
             *  10.v  Percentage
             *  11.v  Percentage in export and in selection
             *  12.v  Общая частотность
             *  13.v  Add date from and date to, to SELECT for all history requests
             *  14.v  Окно со статистикой сразу после Начать
             *  15.v  Excel выгружать числа как числа а не текст!
             *  16.v  Статистика по слову
             *  17.   Import DB
             *  18.   Read line by line
             *  19.   Embed a log
             */

            InitializeComponent();

            // Load settings
            if (Utils.StgGetString("WorkingDir") == "")
            {
                Utils.WorkDirPath = Environment.CurrentDirectory;
            }
            else
            {
                Utils.WorkDirPath = Utils.StgGetString("WorkingDir");
            }

            Utils.StgSet("TxtCodepage", Convert.ToInt32(Properties.Settings.Default["TxtCodepage"]));
            chkSubdirectories.Checked = Utils.StgGetBool("ChkSubdirectories");
        }
Exemple #3
0
        private void bgwCounter_DoWork(object sender, DoWorkEventArgs e)
        {
            foreach (xTextFile xFile in Utils.fList)
            {
                if (bgwCounter.CancellationPending)
                {
                    bgwCounter.ReportProgress(-1, xFile);
                    return;
                }
                bgwCounter.ReportProgress(-2, xFile);

                string contents = xFile.Processor.GetAllText(xFile.filePath);


                xFile.charactersCount = contents.Length;

                xFile.frequencies = new List <xWordFrequencies>();
                var    words       = new Dictionary <string, int>(StringComparer.CurrentCultureIgnoreCase);
                string stRegExp    = Utils.StgGetString("TxtRegExp");
                var    wordPattern = new Regex(stRegExp.Replace(@"\\", @"\").Trim());
                xFile.wordsCount = wordPattern.Matches(contents).Count;
                if (xFile.wordsCount == 0)
                {
                    continue;
                }
                // Check if exists
                if (DbHelper.ifExists(xFile.charactersCount, xFile.wordsCount))
                {
                    continue;
                }

                int progress = 0;
                foreach (Match match in wordPattern.Matches(contents))
                {
                    if (bgwCounter.CancellationPending)
                    {
                        bgwCounter.ReportProgress(-1, xFile);
                        return;
                    }
                    progress++;
                    int currentCount = 0;
                    words.TryGetValue(match.Value, out currentCount);
                    bgwCounter.ReportProgress(progress, xFile);
                    currentCount++;
                    words[match.Value] = currentCount;
                }

                // Add words to object's list of words with frequencies
                int rank = 0;
                foreach (var row in words.OrderByDescending(pair => pair.Value))
                {
                    xWordFrequencies xwf = new xWordFrequencies();
                    xwf.word      = row.Key.ToLower();
                    xwf.word      = xwf.word.Substring(0, 1).ToUpper() + xwf.word.Substring(1);
                    xwf.frequency = row.Value;

                    if (rank != 0)
                    {
                        // It's not the first iteration
                        if (xFile.frequencies[xFile.frequencies.Count - 1].frequency > xwf.frequency)
                        {
                            rank++;
                        }
                    }
                    else
                    {
                        rank++;
                    }

                    xwf.rank = rank;
                    float freq = xwf.frequency;

                    // Why it doesn't work with xwf.frequency?
                    xwf.percentage = (freq / xFile.wordsCount) * 100;
                    xFile.frequencies.Add(xwf);
                }
                xFile.uniqueWordsCount = xFile.frequencies.Count();
                xFile.SaveFileInfo();
            }

            bgwCounter.ReportProgress(-3, null);
        }