Example #1
0
        public static Goal Decompose(String s)
        {
            s = Regex.Replace(s, @"\s+", "");


            List <Literal> list = new List <Literal>();

            s = s.Substring(3);
            // s = "child_of(b, X), hate(Y, X), child_of(f2(f1(X)), f2(f1(X)))"

            Stack <int> OpenBracket  = new Stack <int>();
            Stack <int> CloseBracket = new Stack <int>();

            int startOfCurrentLiteral = 0;

            for (int i = 0; i < s.Length; i++)
            {
                // Bracket identification
                if (s[i] == '(')
                {
                    OpenBracket.Push(i);
                }
                else
                {
                    if (s[i] == ')')
                    {
                        CloseBracket.Push(i);
                    }
                }

                if (OpenBracket.Count != 0 && OpenBracket.Count == CloseBracket.Count)
                {
                    list.Add(Literal.Decompose(s.Substring(startOfCurrentLiteral, CloseBracket.Peek() + 1 - startOfCurrentLiteral)));
                    for (; i < s.Length && s[i] != ','; i++)
                    {
                        ;
                    }

                    // Reset, start processing a new Literal
                    if (i + 1 < s.Length)
                    {
                        startOfCurrentLiteral = i + 1;
                    }
                    OpenBracket.Clear();
                    CloseBracket.Clear();
                }
            }


            return(new Goal(list));
        }
Example #2
0
        public static Literal ApplySubstitution(Literal A, Substitution T)
        {
            String oldLiteral = A.Compose();

            for (int i = 0; i < T.replacementList.Count; i++)
            {
                Replacement R       = T.replacementList[i];
                String      varName = R.X.name;

                oldLiteral = oldLiteral.Replace(varName, R.t.Compose());
            }

            return(Literal.Decompose(oldLiteral));
        }