public override Boolean CompareTo(_Term p)
        {
            if (p.GetType() != _TypeOfTerm.COMPOSITE)
            {
                return(false);
            }

            if (Name != p.Name)
            {
                return(false);
            }

            _Composite temp = (_Composite)p;

            if (mComponents.Count != temp.mComponents.Count)
            {
                return(false);
            }

            for (int i = 0; i < mComponents.Count; ++i)
            {
                _Term temp1 = (_Term)mComponents[i];
                _Term temp2 = (_Term)temp.mComponents[i];
                if (temp1.CompareTo(temp2) == false)
                {
                    return(false);
                }
            }

            return(true);
        }
        public override Boolean IsAppear(_Term p)
        {
            Boolean flag = false;

            if (p.GetType() == _TypeOfTerm.COMPOSITE)
            {
                return(false);
            }

            for (int i = 0; i < mComponents.Count; ++i)
            {
                _Term temp = (_Term)mComponents[i];
                if (temp.GetType() == _TypeOfTerm.COMPOSITE)
                {
                    flag = temp.IsAppear(p);
                }
                else
                {
                    flag = temp.CompareTo(p);
                }

                if (flag == true)
                {
                    return(true);
                }
            }
            return(false);
        }
        public ArrayList GetArguments()
        {
            ArrayList result = new ArrayList();

            for (int i = 0; i < mComponents.Count; ++i)
            {
                _Term p = (_Term)mComponents[i];
                result.Add(_Term.arrPatternObject[(int)p.GetType()].NewObject(p));
            }
            return(result);
        }
Ejemplo n.º 4
0
        public override Boolean CompareTo(_Term p)
        {
            if (p.GetType() != _TypeOfTerm.VARIABLE)
            {
                return(false);
            }

            if (Name != p.Name)
            {
                return(false);
            }

            return(true);
        }
        public override _Term Replace(_MGU s)
        {
            _Term     result = null;
            ArrayList temp   = new ArrayList();

            for (int i = 0; i < mComponents.Count; ++i)
            {
                temp.Add(this[i].Replace(s));
            }

            result = new _Composite(Name, temp);

            return(result);
        }
Ejemplo n.º 6
0
        private Boolean Run(_Term x, _Term y, ref _MGU s)
        {
            if (x.CompareTo(y))
            {
                return(true);
            }
            else
            if (x.GetType() == _TypeOfTerm.VARIABLE)
            {
                return(Unify_var((_Variable)x, y, ref s));
            }
            else
            if (y.GetType() == _TypeOfTerm.VARIABLE)
            {
                return(Unify_var((_Variable)y, x, ref s));
            }
            else
            if (x.GetType() == _TypeOfTerm.COMPOSITE && y.GetType() == _TypeOfTerm.COMPOSITE)
            {
                if (x.Name != y.Name)
                {
                    return(false);
                }

                _Composite comX = (_Composite)x;
                _Composite comY = (_Composite)y;

                if (comX.Count != comY.Count)             // Khong cung toan tu
                {
                    return(false);
                }

                for (int i = 0; i < comX.Count; ++i)
                {
                    _Term tempArrX = comX[i].Replace(s);
                    _Term tempArrY = comY[i].Replace(s);

                    if (Run(tempArrX, tempArrY, ref s) == false)
                    {
                        return(false);
                    }
                }

                return(true);
            }
            else             // x hoac y la hang
            {
                return(false);
            }
        }
Ejemplo n.º 7
0
        public _Element Find(_Term x)
        {
            _Element result = null;
            _Element temp;

            for (int i = 0; i < mContent.Count; ++i)
            {
                temp = (_Element)mContent[i];
                if (temp.IsBelong(x) == true)
                {
                    result = new _Element(temp);
                }
            }
            return(result);
        }
        private void Init(ArrayList Components)
        {
            if (Components == null)
            {
                mComponents = null;
            }
            else
            {
                mComponents = new ArrayList();

                for (int i = 0; i < Components.Count; ++i)
                {
                    _Term p = (_Term)Components[i];
                    mComponents.Add(_Term.arrPatternObject[(int)p.GetType()].NewObject(p));
                }
            }
        }
        public override String ToString()
        {
            String result = Name + "(";

            if (mComponents != null)
            {
                for (int i = 0; i < mComponents.Count; ++i)
                {
                    _Term x = (_Term)mComponents[i];
                    result += x.ToString();
                    if (i < mComponents.Count - 1)
                    {
                        result += ", ";
                    }
                }
            }
            result += ")";


            return(result);
        }
Ejemplo n.º 10
0
        private Boolean Unify_var(_Variable var, _Term x, ref _MGU s)
        {
            _Element val;

            if ((val = s.Find(var)) != null)
            {
                return(Run(val.Arg2, x, ref s));
            }
            else
            if ((val = s.Find(x)) != null)
            {
                return(Run(var, val.Arg1, ref s));
            }
            else
            if (x.IsAppear(var) == true)
            {
                return(false);
            }
            else
            {
                s.Add(new _Element(var, x));
                return(true);
            }
        }
Ejemplo n.º 11
0
 public override _Term NewObject(_Term p)
 {
     return(new _Variable(p));
 }
Ejemplo n.º 12
0
        // Chuyen chuoi thanh _Composite
        public override _Term NewObject(String str)
        {
            _Term result = null;
            Stack stack  = new Stack();
            int   index;

            str = str.Trim();

            while (str != "")
            {
                #region ...
                index = str.IndexOfAny(new char[] { '(', ',', ')' });
                if (index == -1) // Chi xay ra khi do la bien hoac hang
                {
                    #region ...
                    str = str.Trim();
                    char c = str[0];

                    if (Char.IsUpper(c)) // La hang
                    {
                        stack.Push(new _Constant(str));
                    }
                    else
                    {
                        stack.Push(new _Variable(str));
                    }

                    str = "";
                    #endregion
                }
                else
                {
                    #region ...
                    String tempstr = str.Substring(0, index).Trim();
                    if (tempstr != "")
                    {
                        stack.Push(tempstr);
                    }

                    #region switch (str[index])
                    switch (str[index])
                    {
                    case '(':
                        stack.Push("(");
                        break;

                    case ')':
                        ArrayList arr = new ArrayList();
                        Object    temp;
                        temp = stack.Pop();
                        while (temp.ToString() != "(")
                        {
                            if (temp.GetType() == "".GetType())     // Kieu chuoi
                            {
                                String strTemp = (String)temp;
                                char   c       = strTemp[0];

                                if (Char.IsUpper(c))     // La hang
                                {
                                    arr.Add(new _Constant(strTemp));
                                }
                                else
                                {
                                    arr.Add(new _Variable(strTemp));
                                }
                            }
                            else
                            {
                                arr.Add(temp);
                            }
                            temp = stack.Pop();
                        }

                        // Chinh lai vi tri cua cac tham so theo dung thu tu
                        ArrayList arrTemp = new ArrayList();
                        for (int i = arr.Count - 1; i >= 0; --i)
                        {
                            arrTemp.Add(arr[i]);
                        }

                        // Ten ham hoac ten vi tu
                        temp = stack.Pop();

                        // Dua doi tuong moi vao stack
                        stack.Push(new _Composite((String)temp, arrTemp));
                        break;
                    }
                    #endregion
                    str = str.Substring(index + 1);
                    #endregion
                }
                #endregion
            }

            result = (_Term)stack.Pop();

            return(result);
        }
Ejemplo n.º 13
0
 public _Variable(_Term p) : base(p.Name.ToLower())
 {
 }
Ejemplo n.º 14
0
 public override _Term NewObject(_Term p)
 {
     return(new _Constant(p));
 }
Ejemplo n.º 15
0
 public override _Term NewObject(_Term p)
 {
     return(new _Composite((_Composite)p));
 }
Ejemplo n.º 16
0
 public _Term(_Term p)
 {
     mName = String.Copy(p.mName);
 }
Ejemplo n.º 17
0
 public _Constant(_Term p)
     : base(char.ToUpper(p.Name[0]) + p.Name.Substring(1).ToLower())
 {
 }
Ejemplo n.º 18
0
 public abstract _Term NewObject(_Term p);
Ejemplo n.º 19
0
 // Kiem tra 2 bieu thuc co bang nhau khong
 public abstract Boolean CompareTo(_Term p);
Ejemplo n.º 20
0
 // Kiem tra p co xuat hien trong bieu thuc hay khong
 public abstract Boolean IsAppear(_Term p);
Ejemplo n.º 21
0
 public override Boolean IsAppear(_Term p)
 {
     return(CompareTo(p));
 }
Ejemplo n.º 22
0
 public _Element(_Variable var, _Term x)
 {
     Init(var, x);
 }
Ejemplo n.º 23
0
 private void Init(_Variable var, _Term x)
 {
     mArg1 = new _Variable(var);
     mArg2 = _Term.arrPatternObject[(int)x.GetType()].NewObject(x);
 }
Ejemplo n.º 24
0
 public _Unify(_Term x, _Term y)
 {
     Init(x, y);
 }
Ejemplo n.º 25
0
 public Boolean IsBelong(_Term x)
 {
     return(mArg2.CompareTo(x));
 }
Ejemplo n.º 26
0
 private void Init(_Term x, _Term y)
 {
     mArg1 = _Term.arrPatternObject[(int)x.GetType()].NewObject(x);
     mArg2 = _Term.arrPatternObject[(int)y.GetType()].NewObject(y);
 }