コード例 #1
0
ファイル: Clause.cs プロジェクト: hackerlank/trunk-chatbot
        private int CompareArgs(IList <IFOLNode> args1, IList <IFOLNode> args2)
        {
            // Compare argument sizes first
            var rVal = args1.Count - args2.Count;

            if (rVal == 0 && args1.Count > 0)
            {
                // Move forward and compare the
                // first arguments
                ITerm t1 = (ITerm)args1[0];
                ITerm t2 = (ITerm)args2[0];

                if (t1.GetType() == t2.GetType())
                {
                    // Note: Variables are considered to have
                    // the same order
                    if (t1 is Constant)
                    {
                        rVal = t1.GetSymbolicName().CompareTo(t2.GetSymbolicName());
                    }
                    else if (t1 is Function)
                    {
                        rVal = t1.GetSymbolicName().CompareTo(t2.GetSymbolicName());
                        if (0 == rVal)
                        {
                            // Same function names, therefore
                            // compare the function arguments
                            rVal = this.CompareArgs(t1.GetArgs(), t2.GetArgs());
                        }
                    }

                    // If the first args are the same
                    // then compare the ordering of the
                    // remaining arguments
                    if (0 == rVal)
                    {
                        rVal = this.CompareArgs(args1.Skip(1).ToList(), args2.Skip(1).ToList());
                    }
                }
                else
                {
                    // Order for different Terms is:
                    // Constant > Function > Variable
                    if (t1 is Constant)
                    {
                        rVal = 1;
                    }
                    else if (t2 is Constant)
                    {
                        rVal = -1;
                    }
                    else if (t1 is Function)
                    {
                        rVal = 1;
                    }
                    else
                    {
                        rVal = -1;
                    }
                }
            }

            return(rVal);
        }