/// <summary> /// Compiles a literal for unification using a query unifier /// </summary> /// <returns> /// The list of variables in the literal /// </returns> public static IEnumerable <ILiteral> Compile(this IQueryUnifier 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); }
/// <summary> /// Compiles a literal for unification using a query unifier /// </summary> /// <returns> /// The list of variables in the literal /// </returns> public static IEnumerable<ILiteral> Compile(this IQueryUnifier 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; }
/// <summary> /// Adds a new argument to this object /// </summary> public void AddArgument(ILiteral argument) { // Get the assignments for this argument var assignments = argument.Flatten().ToArray(); // The first assignment defines the argument value, and the rest are just other variables var rootAssignment = assignments[0]; var variableAssignments = assignments.Skip(1); // If the root assignment is a variable, use a variable argument assignment instead if (rootAssignment.Value.UnificationKey == null) { var variableRoot = rootAssignment; variableAssignments = variableAssignments.Concat(new[] { variableRoot }); rootAssignment = new ArgumentAssignment(new Variable(), variableRoot.Variable); } // Store the list of other assignments _arguments.Add(rootAssignment); _otherAssignments.AddRange(variableAssignments); }