예제 #1
0
        public bool CompileProgram(IProgramUnifier program)
        {
            // The dependencies of the assignTo value indicate the parameters of this term
            var terms = _assignTo.Dependencies.ToArray();

            // Put the structure
            if (!program.GetStructure(_assignTo.UnificationKey, terms.Length, _target))
            {
                return(false);
            }

            // Put the variables
            foreach (var termVariable in terms)
            {
                if (program.HasVariable(termVariable))
                {
                    if (!program.UnifyValue(termVariable))
                    {
                        return(false);
                    }
                }
                else
                {
                    if (!program.UnifyVariable(termVariable))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
예제 #2
0
        /// <summary>
        /// Compiles a literal for unification using a program unifier
        /// </summary>
        /// <returns>
        /// The list of variables in this literal
        /// </returns>
        public static IEnumerable <ILiteral> Compile(this IProgramUnifier unifier, ILiteral literal, IBindings bindings = null)
        {
            if (unifier == null)
            {
                throw new ArgumentNullException("unifier");
            }
            if (literal == null)
            {
                throw new ArgumentNullException("literal");
            }

            // Flatten the literal
            var assignments = literal.Flatten().ToList();

            // Bind the variables in order
            var freeVariables = unifier.Bind(assignments);

            // Rebind the assignments if necessary
            if (bindings != null)
            {
                assignments = assignments.BindVariables(bindings).ToList();
            }

            // Compile the result
            if (!unifier.Compile(assignments))
            {
                return(null);
            }

            return(freeVariables);
        }
예제 #3
0
 public bool CompileProgram(IProgramUnifier program)
 {
     if (program.HasVariable(_variable))
     {
         return(program.GetValue(_variable, _argument));
     }
     else
     {
         return(program.GetVariable(_variable, _argument));
     }
 }
예제 #4
0
        /// <summary>
        /// Compiles a series of assignments using a program unifier
        /// </summary>
        /// <returns>
        /// The list of variables in the literal
        /// </returns>
        public static bool Compile(this IProgramUnifier unifier, IEnumerable <IAssignmentLiteral> assignments)
        {
            if (unifier == null)
            {
                throw new ArgumentNullException("unifier");
            }
            if (assignments == null)
            {
                throw new ArgumentNullException("assignments");
            }

            // Compile subterms to terms
            foreach (var assign in assignments.OrderSubtermsAfterTerms())
            {
                if (!assign.CompileProgram(unifier))
                {
                    return(false);
                }
            }

            return(true);
        }
예제 #5
0
 public bool CompileProgram(IProgramUnifier program)
 {
     return(true);
 }