Prolog.KnowledgeBase.IsTrue C# (CSharp) Method

IsTrue() public method

True if the specified goal is provable within this KnowledgeBase.
public IsTrue ( object goal, object thisValue = null ) : bool
goal object Goal to attempt to prove
thisValue object The value to give ot the $this indexical while running the goal
return bool
        public bool IsTrue(object goal, object thisValue=null)
        {
            var t = Term.Structurify(goal, "Argument to IsTrue() should be a valid Prolog goal.");
            bool result;
            using (var prologContext = PrologContext.Allocate(this, thisValue))
            {
                try
                {
                    result = Prove(t.Functor, t.Arguments, prologContext, 0).GetEnumerator().MoveNext();
                }
                catch (InferenceStepsExceededException)
                {
                    throw;
                }
                catch (Exception e)
                {
                    throw new PrologError(
                        e,
                        prologContext.StackTrace(
                            Prolog.CurrentSourceFile,
                            Prolog.CurrentSourceLineNumber,
                            "IsTrue()",
                            false) + e.StackTrace);
                }
            }
            return result;
        }

Usage Example

Ejemplo n.º 1
0
        /// <summary>
        /// Call prolog query specified by string.
        /// Provided as UI glue.
        /// </summary>
        /// <param name="prologCode">Source code for Prolog query</param>
        public void Run(string prologCode)
        {
            var code = prologCode.EndsWith(".") ? prologCode : prologCode + '.';

            kb.IsTrue(ISOPrologReader.Read(code));
        }