Beispiel #1
0
        static void ReadFile(String FileName)
        {
            String str = _FileProcess.ReadFile(FileName);

            if (str == "")
            {
                Console.WriteLine("Khong mo duoc file");
            }
            else
            {
                String[] arrStr = str.Split(new String[] { "KB", "ENDKB" }, StringSplitOptions.RemoveEmptyEntries);
                // Xu ly co so tri thuc
                String[] temp = arrStr[0].Split(new String[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
                kb = new _KB();
                for (int i = 0; i < temp.Length; ++i)
                {
                    _Horn e = new _Horn(temp[i]);
                    kb.Add(e);
                }

//                Console.WriteLine(kb);

                temp = arrStr[1].Split(new String[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
                G    = new _Term[temp.Length];
                for (int i = 0; i < temp.Length; ++i)
                {
                    G[i] = _Term.arrPatternObject[2].NewObject(temp[i].Replace("G:", ""));
//                    Console.WriteLine(G[i].ToString());
                }
            }
        }
 public _Horn(_Horn p)
 {
     mLeft = new ArrayList();
     for (int i = 0; i < p.mLeft.Count; ++i)
     {
         _Term e = (_Term)p.mLeft[i];
         mLeft.Add(_Term.arrPatternObject[(int)e.GetType()].NewObject(e));
     }
     mRight = _Term.arrPatternObject[(int)p.mRight.GetType()].NewObject(p.mRight);
 }
Beispiel #3
0
 public _BackwardChaining(_KB p)
 {
     mKB = new _KB();
     #region for (int i = 0; i < p.Count; ++i)
     for (int i = 0; i < p.Count; ++i)
     {
         _Horn     horn = (_Horn)p[i];
         ArrayList left = new ArrayList();
         _Term     right;
         _MGU      tempMgu = new _MGU();
         #region Lay tat ca cac bien o 1 dong
         ArrayList arrVal = new ArrayList();
         arrVal = horn.Right.GetListOfVariable2();
         for (int j = 0; j < horn.Left.Count; ++j)
         {
             _Term     tempTerm   = (_Term)horn.Left[j];
             ArrayList arrValLeft = tempTerm.GetListOfVariable2();
             for (int l = 0; l < arrValLeft.Count; ++l)
             {
                 _Variable v1    = (_Variable)arrValLeft[l];
                 Boolean   flag1 = false;
                 for (int k = 0; k < arrVal.Count; ++k)
                 {
                     _Variable v2 = (_Variable)arrVal[k];
                     if (v1.CompareTo(v2))
                     {
                         flag1 = true;
                         break;
                     }
                 }
                 if (flag1 == false)
                 {
                     arrVal.Add(arrValLeft[l]);
                 }
             }
         }
         #endregion
         for (int j = 0; j < arrVal.Count; ++j)
         {
             _Variable t        = (_Variable)arrVal[j];
             _Term     tempArg2 = new _Variable(t.Name + "." + i);
             tempMgu.Add(new _Element(t, tempArg2));
         }
         for (int j = 0; j < horn.Left.Count; ++j)
         {
             _Term temp = (_Term)horn.Left[j];
             left.Add(temp.Replace(tempMgu));
         }
         right = horn.Right.Replace(tempMgu);
         mKB.Add(new _Horn(left, right));
     }
     #endregion
 }
        public override String ToString()
        {
            String result = "KB\n";

            for (int i = 0; i < mContent.Count; ++i)
            {
                _Horn temp = (_Horn)mContent[i];
                result += temp.ToString() + "\n";
            }
            result += "ENDKB";

            return(result);
        }
 public void Add(_Horn p)
 {
     mContent.Add(new _Horn(p));
 }