Exemplo n.º 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());
                }
            }
        }
Exemplo n.º 2
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
 }