Example #1
0
        void ok_Click(object sender, EventArgs e)
        {
            tvS1.Nodes.Clear();
            tvS2.Nodes.Clear();
            tvNorm1.Nodes.Clear();
            tvNorm2.Nodes.Clear();
            List <WordRu> lRoot1 = SyntaxRu.Analize(tbT1.Text), lRoot2 = SyntaxRu.Analize(tbT2.Text);

            SyntaxRu.RemovePrepPunc(lRoot1);
            SyntaxRu.RemovePrepPunc(lRoot2);
            tvS1.Nodes.AddRange(TNodes(lRoot1));
            tvS2.Nodes.AddRange(TNodes(lRoot2));
            int x = SyntaxRu.Syn(lRoot1, lRoot2);

            tvNorm1.Nodes.AddRange(TNodes(lRoot1));
            tvNorm2.Nodes.AddRange(TNodes(lRoot2));
            double cmp = SyntaxRu.Compare(lRoot1, lRoot2);
            string res = "совпадают";

            if (cmp < 0.4)
            {
                res = "отличаются";
            }
            MessageBox.Show(string.Format("Тексты {0} по смыслу ({1})", res, cmp));
        }
Example #2
0
        static public int Freq(string file)
        {
            StreamReader  sr    = new StreamReader(file, System.Text.Encoding.Default);
            string        s     = sr.ReadToEnd();
            List <WordRu> lRoot = Analize(s);

            SyntaxRu.RemovePrepPunc(lRoot);
            List <string>  lNorm = new List <string>();
            List <int>     lFreq = new List <int>();
            Stack <WordRu> st    = new Stack <WordRu>();

            foreach (WordRu r in lRoot)
            {
                st.Push(r);
                while (st.Count > 0)
                {
                    WordRu w     = st.Pop();
                    int    index = lNorm.BinarySearch(w.norm);
                    if (index < 0)
                    {
                        lNorm.Insert(~index, w.norm);
                        lFreq.Insert(~index, 1);
                    }
                    else
                    {
                        lFreq[index]++;
                    }
                    foreach (WordRu c in w.lCh)
                    {
                        st.Push(c);
                    }
                }
            }
            DSDict.FreqDataTable ft = new DSDict.FreqDataTable();
            DSDictTableAdapters.FreqTableAdapter fta = new Semantics.DSDictTableAdapters.FreqTableAdapter();
            int count = 0;

            for (int i = 0; i < lNorm.Count; i++)
            {
                fta.FillByWord(ft, lNorm[i]);
                if (ft.Rows.Count == 0)
                {
                    fta.Insert(lNorm[i], lFreq[i]);
                }
                else
                {
                    fta.UpdateByWord(lNorm[i], (int)ft[0]["freq"] + lFreq[i], lNorm[i]);
                }
                count++;
            }
            return(count);
        }