/// <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); }
public bool CompileQuery(IQueryUnifier query) { // The dependencies of the assignTo value indicate the parameters of this term var terms = _assignTo.Dependencies.ToArray(); // Put the structure if (!query.PutStructure(_assignTo.UnificationKey, terms.Length, _target)) { return(false); } // Put the variables foreach (var termVariable in terms) { if (query.HasVariable(termVariable)) { if (!query.SetValue(termVariable)) { return(false); } } else { if (!query.SetVariable(termVariable)) { return(false); } } } return(true); }
public bool CompileQuery(IQueryUnifier query) { if (query.HasVariable(_variable)) { return(query.PutValue(_variable, _argument)); } else { return(query.PutVariable(_variable, _argument)); } }
/// <summary> /// Compiles a series of assignments using a query unifier /// </summary> /// <returns> /// The list of variables in the literal /// </returns> public static bool Compile(this IQueryUnifier 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.OrderTermsAfterSubterms()) { if (!assign.CompileQuery(unifier)) { return(false); } } return(true); }
public bool CompileQuery(IQueryUnifier query) { return(true); }