Esempio n. 1
0
        private void importInSynonyms_Click(object sender, EventArgs e)
        {
            if (paste.Checked)
            {
                OpenFileDialog ofd = new OpenFileDialog();
                ofd.DefaultExt = "*.xls;*.xlsx";
                ofd.Filter     = " Excel 2003(*.xls)|*.xls|Excel 2007(*.xlsx)|*.xlsx";
                ofd.Title      = "Выберите документ для загрузки данных";
                ExcellObj.Application app = new ExcellObj.Application();
                ExcellObj.Workbook    workbook;
                ExcellObj.Worksheet   NwSheet;
                ExcellObj.Range       ShtRange;
                DataTable             dt = new DataTable();
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    workbook = app.Workbooks.Open(ofd.FileName, Missing.Value,
                                                  Missing.Value, Missing.Value, Missing.Value, Missing.Value,
                                                  Missing.Value, Missing.Value, Missing.Value, Missing.Value,
                                                  Missing.Value, Missing.Value, Missing.Value, Missing.Value,
                                                  Missing.Value
                                                  );
                    NwSheet = (ExcellObj.Worksheet)workbook.Sheets.get_Item(1);
                    //    ShtRange = NwSheet.UsedRange;
                    string range = col_import.Text + ":" + col_import.Text;

                    ShtRange = NwSheet.get_Range(range);

                    int empty_count = 0;
                    int start       = first_column_import.Checked ? 1 : 2;

                    for (int Rnum = start; Rnum <= ShtRange.Rows.Count; Rnum++)
                    {
                        if (empty_count == 10)
                        {
                            break;
                        }
                        if (Rnum - start >= dataGridView1.Rows.Count)
                        {
                            dataGridView1.Rows.Add();
                        }
                        for (int Cnum = 1; Cnum <= ShtRange.Columns.Count; Cnum++)
                        {
                            if ((ShtRange.Cells[Rnum, Cnum] as ExcellObj.Range).Value2 != null)
                            {
                                empty_count = 0;
                                dataGridView1["synonyms", Rnum - start].Value = (ShtRange.Cells[Rnum, Cnum] as ExcellObj.Range).Value2.ToString();
                            }
                            else
                            {
                                // MessageBox.Show((ShtRange.Cells[Rnum, Cnum] as ExcellObj.Range).Value2.ToString());
                            }
                            //   MessageBox.Show(Rnum.ToString() + " and " + Cnum.ToString());
                        }
                        empty_count++;
                    }
                    app.Quit();
                }
            }
            else
            {
                //Парсинг синонимов
                OpenFileDialog ofd = new OpenFileDialog();
                ofd.DefaultExt = "*.xls;*.xlsx";
                ofd.Filter     = " Excel 2003(*.xls)|*.xls|Excel 2007(*.xlsx)|*.xlsx";
                ofd.Title      = "Выберите документ для загрузки данных";
                ExcellObj.Application app = new ExcellObj.Application();
                ExcellObj.Workbook    workbook;
                ExcellObj.Worksheet   NwSheet;
                ExcellObj.Range       ShtRange;
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    workbook = app.Workbooks.Open(ofd.FileName, Missing.Value,
                                                  Missing.Value, Missing.Value, Missing.Value, Missing.Value,
                                                  Missing.Value, Missing.Value, Missing.Value, Missing.Value,
                                                  Missing.Value, Missing.Value, Missing.Value, Missing.Value,
                                                  Missing.Value
                                                  );
                    NwSheet = (ExcellObj.Worksheet)workbook.Sheets.get_Item(1);
                    string range = col_import.Text + ":" + col_import.Text;

                    ShtRange = NwSheet.get_Range(range);
                    int start       = first_column_import.Checked ? 1 : 2;
                    int empty_count = 0;

                    for (int Rnum = start; Rnum <= ShtRange.Rows.Count; Rnum++)
                    {
                        if (empty_count == 10)
                        {
                            break;
                        }
                        if (Rnum - start >= dataGridView1.Rows.Count)
                        {
                            dataGridView1.Rows.Add();
                        }
                        for (int Cnum = 1; Cnum <= ShtRange.Columns.Count; Cnum++)
                        {
                            if ((ShtRange.Cells[Rnum, Cnum] as ExcellObj.Range).Value2 != null)
                            {
                                empty_count = 0;
                                string value = (ShtRange.Cells[Rnum, Cnum] as ExcellObj.Range).Value2.ToString().Trim();
                                this.Text = "Парсинг: " + value;
                                dataGridView1["synonyms", Rnum - start].Value = SynomymsParse.GetWord(value, pluralToOne.Checked);
                                if (cbx_ping.Checked)
                                {
                                    Random rnd = new Random();
                                    Thread.Sleep(rnd.Next(1000, 3000));
                                }
                            }
                        }
                        empty_count++;
                    }
                    this.Text = "Парснг завершен";
                    app.Quit();
                }
            }
        }
Esempio n. 2
0
        public static string GetWord(string word, bool toOne)
        {
            try
            {
                string ending = word.Substring(word.Length - 2);

                string result = "";

                bool isPlural = ending == "ие" || ending == "ые";
                if (isPlural && toOne)
                {
                    Queue <string> wordsArray = PluralToOne.getOne(word);

                    string synonimsLine = "";
                    foreach (string w in wordsArray)
                    {
                        try
                        {
                            string href = @"https://text.ru/synonym/" + w;
                            var    pc   = SynomymsParse.LoadPage(href);
                            var    doc  = new HtmlDocument();
                            doc.LoadHtml(pc);
                            HtmlNodeCollection wds = doc.DocumentNode.SelectNodes("//table[@id='table_list_synonym']//td[@class='ta-l']/a");
                            int j = 0;
                            foreach (HtmlNode elem in wds)
                            {
                                j++;
                                synonimsLine += " +" + elem.InnerText + " |";
                            }
                        }
                        catch
                        {
                            continue;
                        }
                    }
                    if (synonimsLine.Length != 0)
                    {
                        synonimsLine = synonimsLine.Trim('|');
                        string variants = String.Join(" | +", wordsArray);
                        foreach (string w in wordsArray)
                        {
                        }
                        return("(+" + variants + " |" + synonimsLine + ")");
                    }
                }

                word = word.Trim();
                string url         = @"https://text.ru/synonym/" + word;
                var    pageContent = SynomymsParse.LoadPage(url);
                var    document    = new HtmlDocument();
                document.LoadHtml(pageContent);
                HtmlNodeCollection words = document.DocumentNode.SelectNodes("//table[@id='table_list_synonym']//td[@class='ta-l']/a");
                // HtmlNode tableNode = document.DocumentNode.SelectSingleNode("//table[@id='table_list_synonym']");
                if (words == null)
                {
                    return("(+" + word + ")");
                }
                result += "(+" + word + " |";
                int i = 0;
                foreach (HtmlNode elem in words)
                {
                    i++;
                    if (i != words.Count)
                    {
                        result += " +" + elem.InnerText + " |";
                    }
                    else
                    {
                        result += " +" + elem.InnerText;
                    }
                }
                result += ")";
                return(result);
            }
            catch (Exception)
            {
                return("(" + word + ")");
            }
        }