示例#1
0
        public void DocLuatTuFfile() //Read Rule
        {
            string    qr     = "select noidung from tblluat";
            DataTable tbLuat = kn.getTable(qr);

            for (int i = 0; i < tbLuat.Rows.Count; i++)
            {
                string     buff           = tbLuat.Rows[i][0].ToString();
                RuleDefine luatTG         = new RuleDefine();
                char[]     delimiterChars = { '>' };
                string[]   tg             = buff.Split(delimiterChars);

                //ben trai (Left)
                char[]   delimiterChars1 = { '^' };
                string[] left            = tg[0].Split(delimiterChars1);
                int      j     = 0;
                string   buff1 = left[0];
                while (buff1 != null)
                {
                    luatTG.left.Add(buff1);
                    j++;
                    try
                    {
                        buff1 = left[j];
                    }
                    catch { buff1 = null; };
                }

                j = 0;


                //ben phai (Right)
                char[]   delimiterChars2 = { ',' };
                string[] right           = tg[1].Split(delimiterChars2);

                buff1 = right[0];
                while (buff1 != null)
                {
                    luatTG.right.Add(buff1);
                    j++;
                    try
                    {
                        buff1 = right[j];
                    }
                    catch { buff1 = null; };
                }

                bin.Add(luatTG);
                demLuat++;
            }
        }
示例#2
0
        public bool SuyDien(List <string> left, List <string> right)  //deduction
        {
            List <RuleDefine> mangLuat = new List <RuleDefine>();

            mangLuat = bin;
            List <string> KL = right;
            List <string> TG = left;

            TimTapSat(TG, mangLuat);
            while (SAT.Count > 0 && CheckIn(KL, TG) == false)
            {
                //lay luat r cuoi cung ra ap dung (Get the last rule to apply)
                RuleDefine r = SAT.ElementAt(0);
                mangLuat.Remove(r);
                SAT.RemoveAt(0);
                //them cai chua co vao TG (Add not have to TG)
                foreach (string tg in r.right)
                {
                    if (!TG.Contains(tg))
                    {
                        TG.Add(tg);
                        Console.WriteLine(tg);
                    }
                }

                TimTapSat(TG, mangLuat);
            }

            if (CheckIn(KL, TG) == false)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }