예제 #1
0
        protected static void lovesAnimalDemo(InferenceProcedure ip)
        {
            StandardizeApartIndexicalFactory.flush();

            FOLKnowledgeBase kb = FOLKnowledgeBaseFactory.createLovesAnimalKnowledgeBase(ip);

            string kbStr = kb.ToString();

            ICollection <Term> terms = CollectionFactory.CreateQueue <Term>();

            terms.Add(new Constant("Curiosity"));
            terms.Add(new Constant("Tuna"));
            Predicate query = new Predicate("Kills", terms);

            InferenceResult answer = kb.ask(query);

            System.Console.WriteLine("Loves Animal Knowledge Base:");
            System.Console.WriteLine(kbStr);
            System.Console.WriteLine("Query: " + query);
            foreach (Proof p in answer.getProofs())
            {
                System.Console.Write(ProofPrinter.printProof(p));
                System.Console.WriteLine("");
            }
        }
예제 #2
0
        /**
         * Utility method for outputting InferenceResults in a formatted textual
         * representation.
         *
         * @param ir
         *            an InferenceResult
         * @return a String representation of the InferenceResult.
         */
        public static String printInferenceResult(InferenceResult ir)
        {
            StringBuilder 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;
            List <Proof> proofs  = ir.getProofs();

            foreach (Proof p in proofs)
            {
                proofNo++;
                sb.Append("InferenceResult.Proof#" + proofNo + "=\n"
                          + ProofPrinter.printProof(p));
            }
            return(sb.ToString());
        }
예제 #3
0
        private static void kingsDemo1(InferenceProcedure ip)
        {
            StandardizeApartIndexicalFactory.flush();

            FOLKnowledgeBase kb = FOLKnowledgeBaseFactory
                                  .createKingsKnowledgeBase(ip);

            String kbStr = kb.ToString();

            List <Term> terms = new List <Term>();

            terms.Add(new Constant("John"));
            Predicate query = new Predicate("Evil", terms);

            InferenceResult answer = kb.ask(query);

            System.Console.WriteLine("Kings Knowledge Base:");
            System.Console.WriteLine(kbStr);
            System.Console.WriteLine("Query: " + query);
            foreach (Proof p in answer.getProofs())
            {
                System.Console.Write(ProofPrinter.printProof(p));
                System.Console.WriteLine("");
            }
        }
예제 #4
0
        public List <string> GetProof(InferenceResult result)
        {
            var      toReturn = new List <string>();
            Iterator terator  = result.getProofs().iterator();

            while (terator.hasNext())
            {
                toReturn.AddRange(ProofPrinter.printProof((Proof)terator.next()).Split(new string[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries));
            }
            return(toReturn);
        }
예제 #5
0
        protected static void abcEqualityNoAxiomDemo(InferenceProcedure ip)
        {
            StandardizeApartIndexicalFactory.flush();

            FOLKnowledgeBase kb = FOLKnowledgeBaseFactory.createABCEqualityKnowledgeBase(ip, false);

            string kbStr = kb.ToString();

            TermEquality query = new TermEquality(new Constant("A"), new Constant("C"));

            InferenceResult answer = kb.ask(query);

            System.Console.WriteLine("ABC Equality No Axiom Knowledge Base:");
            System.Console.WriteLine(kbStr);
            System.Console.WriteLine("Query: " + query);
            foreach (Proof p in answer.getProofs())
            {
                System.Console.Write(ProofPrinter.printProof(p));
                System.Console.WriteLine("");
            }
        }
예제 #6
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());
        }
예제 #7
0
        protected static void weaponsDemo(InferenceProcedure ip)
        {
            StandardizeApartIndexicalFactory.flush();

            FOLKnowledgeBase kb = FOLKnowledgeBaseFactory.createWeaponsKnowledgeBase(ip);

            string kbStr = kb.ToString();

            ICollection <Term> terms = CollectionFactory.CreateQueue <Term>();

            terms.Add(new Variable("x"));
            Predicate query = new Predicate("Criminal", terms);

            InferenceResult answer = kb.ask(query);

            System.Console.WriteLine("Weapons Knowledge Base:");
            System.Console.WriteLine(kbStr);
            System.Console.WriteLine("Query: " + query);
            foreach (Proof p in answer.getProofs())
            {
                System.Console.Write(ProofPrinter.printProof(p));
                System.Console.WriteLine("");
            }
        }
예제 #8
0
        /**
         * Utility method for outputting InferenceResults in a formatted textual
         * representation.
         *
         * @param ir
         *            an InferenceResult
         * @return a string representation of the InferenceResult.
         */
        public static string printInferenceResult(InferenceResult ir)
        {
            IStringBuilder sb = TextFactory.CreateStringBuilder();

            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().Size());
            sb.Append("\n");
            int proofNo = 0;

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

            return(sb.ToString());
        }