예제 #1
0
        public static void HomographsImport()
        {
            // Clear collections for new data
            WordForm.Homographs = new List <List <WordForm> >();
            WordRoot.Roots      = new HashSet <WordRoot>();

            using (StreamReader sr = new StreamReader("export.txt", System.Text.Encoding.UTF8)) {
                string[]        lineParts = { };
                int             wId, rId;
                string          wTitle, wDef, rTitle, rDef;
                List <WordForm> homos = new List <WordForm>();

                while (!sr.EndOfStream)
                {
                    lineParts = sr.ReadLine().Split('║');

                    wId    = Convert.ToInt32(lineParts[3].Split(':')[1].Trim());
                    wTitle = lineParts[4].Split(':')[1].Trim();
                    wDef   = lineParts[5].Split(':')[1].Trim();

                    rId    = Convert.ToInt32(lineParts[0].Split(':')[1].Trim());
                    rTitle = lineParts[1].Split(':')[1].Trim();
                    rDef   = lineParts[2].Split(':')[1].Trim();

                    WordForm wf = new WordForm(wId, rId, wTitle, wDef);
                    WordRoot wr = new WordRoot(rId, rTitle, rDef);

                    // Prevent duplicates
                    if (!WordRoot.Roots.Any(item => item.Id == rId))
                    {
                        WordRoot.Roots.Add(wr);
                    }

                    if (homos.LastOrDefault() != null && wf.Title.Equals(homos.LastOrDefault().Title))
                    {
                        homos.Add(wf);
                    }
                    else if (homos.LastOrDefault() != null)
                    {
                        WordForm.Homographs.Add(homos);
                        homos = new List <WordForm>();
                        homos.Add(wf);
                    }
                    else
                    {
                        homos.Add(wf);
                    }
                }

                // Add the last homographs collection because the check happens only after the each iteration
                WordForm.Homographs.Add(homos);
                Console.WriteLine("HomographsImport - Done");
            }
        }
예제 #2
0
        private void FrmHomographs_Load(object sender, EventArgs e)
        {
            // Grouping by courses==========================================
            OLVColumn clm = ((OLVColumn)olvHomographs.Columns[0]);

            /* clm.GroupKeyGetter = delegate (object rowObject) {
             *   WordForm wf = (WordForm)rowObject;
             *   return wf.Title;
             * };
             *
             * clm.GroupKeyToTitleConverter = delegate (object groupKey) {
             *   return groupKey.ToString();
             * };
             * clm.Groupable = true;
             * // ==============================================================
             *
             */

            olvHomographs.SetObjects(WordForm.GetHomographsList());
            label1.Text = "Количество омографов:" + olvHomographs.Items.Count;
            olvHomographs.Refresh();
        }