public IEnumerable <SwiPrologQueryResult> Query(string query) { using (var q = new SwiPrologQuery(module, query)) { foreach (SwiPrologQueryResult v in q.SolutionVariables) { yield return(v); } } }
/// <summary> /// /// </summary> /// <param name="module"></param> /// <param name="goal"></param> /// <returns></returns> public static bool Call(string module, string goal) { bool bRet; using (var q = new SwiPrologQuery(module, "call", new SwiPrologTermVector(new SwiPrologTerm(goal)))) { bRet = q.NextSolution(); q.Free(true); } return(bRet); }
#pragma warning disable 1573 // Parameter 'predicate' has no matching param tag in the XML comment for 'SbsSW.SwiPlCs.PlQuery.PlCall(string, string, SbsSW.SwiPlCs.PlTermV)' (but other parameters do) /// <inheritdoc cref="Call(string, SwiPrologTermVector)" /> /// <summary>As <see cref="Call(string, SwiPrologTermVector)"/> but locating the predicate in the named module.</summary> /// <param name="module">locating the predicate in the named module.</param> public static bool Call(string module, string predicate, SwiPrologTermVector args) { bool bRet; using (var q = new SwiPrologQuery(module, predicate, args)) { bRet = q.NextSolution(); q.Free(false); } return(bRet); }
#pragma warning disable 1573 /// <inheritdoc cref="CallQuery(System.String)" /> /// <summary>As <see cref="CallQuery(string)"/> but executed in the named module.</summary> /// <param name="module">The modulename in which the query is executed</param> public static SwiPrologTerm CallQuery(string module, string goal) { SwiPrologTerm retVal; using (var q = new SwiPrologQuery(module, goal)) { // find the variable or throw an exception SwiPrologTerm?t = null; if (q.Variables.Count == 1) { t = new SwiPrologTerm(q.Variables[0].Value.TermRef); } else { for (int i = 0; i < q._av.Size; i++) { if (!q._av[i].IsVariable) { continue; } if (t == null) { t = new SwiPrologTerm(q._av[i].TermRef); } else { throw new ArgumentException("More than one Variable in " + goal); } } } if (t == null) { throw new ArgumentException("No Variable found in " + goal); } if (q.NextSolution()) { retVal = (SwiPrologTerm)t; } else { retVal = new SwiPrologTerm(); // null } q.Free(false); } return(retVal); }
public IEnumerable <SwiPrologQueryResult> Query(SwiPrologTerm query) { //return Query(query.ToString()); var count = query.Arity; var array = new SwiPrologTerm[count]; for (int index = 0; index < count; ++index) { array[index] = query[index + 1]; } using (var q = new SwiPrologQuery(module, query.Name, new SwiPrologTermVector(array))) { foreach (SwiPrologQueryResult v in q.SolutionVariables) { yield return(v); } } }
public bool Call(string goal) { return(SwiPrologQuery.Call(module, goal)); }
public bool RetractRule(string head, string body) { return(SwiPrologQuery.Call(module, "retract((" + head + " :- " + body + "))")); }
public bool AssertRule(string head, string body) { return(SwiPrologQuery.Call(module, "assert((" + head + " :- " + body + "))")); }
public bool Contains(string term) { return(SwiPrologQuery.Call(module, term)); }
public bool RetractAll(string term) { return(SwiPrologQuery.Call(module, "retractall(" + term + ")")); }
public bool Assert(string term) { return(SwiPrologQuery.Call(module, "assert(" + term + ")")); }