Exemple #1
0
        /* Atom Utils */
        /// <summary>
        /// Resolves all Function predicates by replacing them by their String representations.
        /// </summary>
        /// <param name="atom">The Atom to resolve.</param>
        /// <returns>A new Atom where all Function predicates have been resolved. If no
        /// Function predicate exists, it returns a clone of the current Atom.</returns>
        internal static Atom ResolveFunctions(Atom atom)
        {
            if (atom.HasFunction) {
                IPredicate[] predicates = new IPredicate[atom.Members.Length];

                for(int i=0; i<atom.Members.Length; i++)
                    if (atom.Members[i] is Function) predicates[i] = new Individual(atom.Members[i].ToString());
                    else predicates[i] = atom.Members[i];
                return new Atom(atom.Negative, atom.Type, predicates);
            }
            else
                return (Atom)atom.Clone();
        }
Exemple #2
0
        public void AtomSlots()
        {
            Atom atom = new Atom("spending", new Slot("client", new Variable("buyer")), new Function(Function.FunctionResolutionType.Binder, "min(5000,EUR)", null, "min", new string[]{"5000","EUR"}));

            Assert.AreEqual(typeof(Variable), atom.GetPredicate("client").GetType(), "Slot predicate");

            Atom clone = (Atom)atom.Clone();
            atom = null;

            Assert.AreEqual(typeof(Variable), clone.GetPredicate("client").GetType(), "Slot predicate after cloning");
        }