Esempio n. 1
0
 public Boolean IsEqual(Way OtherWay)
 {
     if (this.Steps.Count != OtherWay.Steps.Count)
     {
         return false;
     }
     int index = 0;
     foreach (int step in this.Steps)
     {
         if (step != OtherWay.Steps[index])
         {
             return false;
         }
         index++;
     }
     return true;
 }
Esempio n. 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            TagsOfSentence = new List<string>();
            GrammersOfSentence = new List<string>();
            GrammersPossible = new List<string>();
            BadWays = new List<Way>();
            MyWay = new Way();
            string[] Tags = textBox1.Text.Split(' ');
            foreach (string tag in Tags)
            {
                MyWordsDataTable = MyWordsTableAdapter.GetTag(tag);
                string temp="";
                Boolean WordInDB = false;

                foreach (DataSet1.WordsRow row in MyWordsDataTable)
                {
                    WordInDB = true;
                    temp = row.Tag;
                }
                if (WordInDB)
                {
                    label1.Text = label1.Text + temp + " ";
                    TagsOfSentence.Add(temp);
                }
            }
            //int index;
            Boolean IsBadWay = false;
            GrammersPossible = TagsOfSentence.ToList();
            for (int indexGrammers = 0; indexGrammers < listGrammers.Count; indexGrammers++)
            {

                if (listGrammers[indexGrammers].MyTags.Count <= GrammersPossible.Count)
                {
                    continue;
                }
                //index = 0;
                //this Grammer same "Grammers Possible" ?
                for (int indexTags = 0; indexTags < GrammersPossible.Count; indexTags++)
                {
                    if (GrammersPossible[indexTags] != listGrammers[indexGrammers].MyTags[indexTags])
                    {
                        break;
                    }

                    if (indexTags == listGrammers[indexGrammers].MyTags.Count - 1)
                    {
                        foreach (Way way in BadWays)
                        {
                            if(this.MyWay.IsEqual(way))
                            {
                                IsBadWay = true;
                            }
                        }
                        if (IsBadWay )
                        {
                            continue;
                        }
                        else // good way
                        {
                            List<string> copy = new List<string>();
                            for (int j = 0; j < indexTags - (listGrammers[indexGrammers].MyTags.Count - 1); j++)
                            {
                                copy.Add(GrammersPossible[j]);
                            }
                            copy.Add(listGrammers[indexGrammers].LeftSide);
                            for (int j = indexTags + 1; j < GrammersPossible.Count; j++)
                            {
                                copy.Add(GrammersPossible[j]);
                            }
                            GrammersPossible = new List<string>();
                            GrammersPossible = copy.ToList();
                            MyWay.AddStep(listGrammers[indexGrammers].ID);
                            GrammersOfSentence.Add(listGrammers[indexGrammers].grammer);
                            indexGrammers = 0;
                            continue;
                        }
                    }
                }
                if (listGrammers.Count - 1 == indexGrammers && GrammersPossible.Count != 1 && MyWay.Steps.Count !=0)
                {
                    GrammersPossible = GrammersOfSentence.ToList();
                    BadWays.Add(MyWay);
                    MyWay = new Way();
                    indexGrammers = 0;
                    if (BadWays.Count == 50)
                    {
                        int m = 0;
                    }
                //    foreach (GrammerOp gr in listGrammers)
                //    {
                //        if (gr.IsMaster == true)
                //        {
                //            if (gr.LeftSide != GrammersPossible.First())
                //            {
                //                GrammersPossible = GrammersOfSentence.ToList();
                //                BadWays.Add(MyWay);
                //                MyWay = new Way();
                //                break;
                //            }
                //       }
                //    }
                }
            }
            //TagsOfSentence
            foreach (string gra in GrammersOfSentence)
            {
                textBox2.Text = textBox2.Text + gra + "\r\n";
            }
        }