Example #1
0
        public IInferenceResult Ask(ISentence aQuery)
        {
            // Want to standardize apart the query to ensure
            // it does not clash with any of the sentences
            // in the database
            StandardizeApartResult saResult = standardizeApart.GetStandardizeApartResult(
                aQuery, queryIndexical);

            // Need to map the result variables (as they are standardized apart)
            // to the original queries variables so that the caller can easily
            // understand and use the returned set of substitutions
            IInferenceResult infResult = this.GetInferenceProcedure().Ask(this,
                                                                          saResult.Standardized);

            foreach (IProof p in infResult.GetProofs())
            {
                IDictionary <Variable, ITerm> im = p.GetAnswerBindings();
                IDictionary <Variable, ITerm> em = new Dictionary <Variable, ITerm>();
                foreach (Variable rev in saResult.ReverseSubstitution.Keys)
                {
                    em[(Variable)saResult.ReverseSubstitution[rev]] = im[rev];
                }
                p.ReplaceAnswerBindings(em);
            }

            return(infResult);
        }
Example #2
0
        /// <summary>
        /// Utility method for outputting InferenceResults in a formatted textual
        /// representation.
        /// </summary>
        /// <param name="ir">an InferenceResult</param>
        /// <returns>a String representation of the InferenceResult.</returns>
        public static string PrintInferenceResult(IInferenceResult ir)
        {
            var sb = new StringBuilder();

            sb.Append("InferenceResult.isTrue=" + ir.IsTrue());
            sb.Append("\n");
            sb.Append("InferenceResult.isPossiblyFalse=" + ir.IsPossiblyFalse());
            sb.Append("\n");
            sb.Append("InferenceResult.isUnknownDueToTimeout=" + ir.IsUnknownDueToTimeout());
            sb.Append("\n");
            sb.Append("InferenceResult.isPartialResultDueToTimeout=" + ir.IsPartialResultDueToTimeout());
            sb.Append("\n");
            sb.Append("InferenceResult.#Proofs=" + ir.GetProofs().Count);
            sb.Append("\n");
            int proofNo = 0;

            foreach (var p in ir.GetProofs())
            {
                proofNo++;
                sb.Append("InferenceResult.Proof#" + proofNo + "=\n" + ProofPrinter.PrintProof(p));
            }

            return(sb.ToString());
        }