Exemple #1
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 Boolean IsBelong(_Variable x)
 {
     return(mArg1.CompareTo(x));
 }