Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
#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);
        }
Exemplo n.º 3
0
#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);
        }