예제 #1
0
        public static void Main(string[] args)
        {
            // Main Input Arguments      //
            // args[0] inference method	 //
            // args[1] filename			 //

            String  fileName  = "default";
            String  inference = "default";
            Boolean Debug     = false;

            if (args.Length < 2)
            {
                Console.WriteLine("ERROR: NOT ENOUGH INPUT PARAMETERS");
                return;
            }
            else if (args.Length == 2)
            {
                inference = args [0];
                fileName  = args [1];
            }
            else if (args.Length == 3)
            {
                inference = args [0];
                fileName  = args [1];
                if (args[2] == "DEBUG")
                {
                    Debug = true;
                }
            }
            else
            {
                Console.WriteLine("ERROR: TOO MANY INPUT PARAMETERS");
                return;
            }

            if (Debug)
            {
                Console.WriteLine("Program begin");
            }



            //String inference = args[0];
            //String fileName = args [1];

            // debugging stuff for 3rd argument, error checking in input?

            Parser        P = new Parser();
            InferenceType iEngine;

            List <HornClauseClass> parsedKB    = P.GetKB(fileName);
            QueryClass             parsedQuery = new QueryClass(P.GetQuery(fileName));

            switch (inference)
            {
            case "TT":
                iEngine = new TruthTableClass(parsedKB, parsedQuery);
                break;

            case "FC":
                iEngine = new ForwardChaining(parsedKB);
                break;

            case "BC":
                iEngine = new BackwardChaining(parsedKB);
                break;

            default:
                Console.WriteLine("Inference Type code invalid");
                return;
            }
            String Result = iEngine.EvaluateQuery(parsedQuery, Debug);

            Console.WriteLine(Result);
        }
예제 #2
0
        static int Main(string[] args)
        {
            if (args.Count() != 2)
            {
                Console.WriteLine("ERROR: incorrect arguments");
#if DEBUG
                Console.ReadLine(); //stops the console from closing
#endif
                return(1);
            }

            string method   = args[0];
            string filename = args[1];

            KnowledgeBase knowledgeBase = new KnowledgeBase();
            string        query         = "";

            try
            {
                if (!ParseFile(filename, ref knowledgeBase, ref query))
                {
                    Console.WriteLine("ERROR: incorrect file format");
#if DEBUG
                    Console.ReadLine(); //stops the console from closing
#endif
                    return(2);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("ERROR: {0}", ex.Message);
#if DEBUG
                Console.ReadLine(); //stops the console from closing
#endif
                return(3);
            }

            Result result;
            try
            {
                switch (method)
                {
                case "TT":
                    result = TruthTableChecking.TT(knowledgeBase, query);
                    break;

                case "FC":
                    result = ForwardChaining.FC(knowledgeBase, query);
                    break;

                case "BC":
                    result = BackwardChaining.BC(knowledgeBase, query);
                    break;

                default:
                    Console.WriteLine("ERROR: invalid method provided");
#if DEBUG
                    Console.ReadLine();     //stops the console from closing
#endif
                    return(4);
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("ERROR: {0}", ex.Message);
#if DEBUG
                Console.ReadLine(); //stops the console from closing
#endif
                return(5);
            }

            if (result.Success)
            {
                string second;
                if (result.Symbols is null)
                {
                    second = result.Count.ToString();
                }
                else
                {
                    second = string.Join(", ", result.Symbols);
                }
                Console.WriteLine("YES: {0}", second);
            }
            else
            {
                Console.WriteLine("NO");
            }
#if DEBUG
            Console.ReadLine(); //stops the console from closing
#endif
            return(0);
        }