예제 #1
0
        private void InputButton_Click(object sender, EventArgs e)
        {
            OutputTextBox.Clear();
            try
            {
                if (prolog == null)
                {
                    labelError.Text = "Please Select Theory";
                    return;
                }
                if (prolog is Perm)
                {
                    Term      goal = new Struct("perm", Term.createTerm(InputTextBox.Text), new Var("R"));
                    SolveInfo SI   = prolog.solve(goal);

                    if (!SI.isSuccess())
                    {
                        OutputTextBox.AppendText("no");
                    }

                    while (SI.isSuccess())
                    {
                        OutputTextBox.AppendText(SI.getTerm("R").toString() + "\n");
                        if (prolog.hasOpenAlternatives())
                        {
                            SI = prolog.solveNext();
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                else if (prolog is PrologDerivate)
                {
                    Term      goal = new Struct("dExpr", Term.createTerm(InputTextBox.Text), new Var("DT"));
                    SolveInfo SI   = prolog.solve(goal);

                    if (!SI.isSuccess())
                    {
                        OutputTextBox.AppendText("no");
                    }
                    else
                    {
                        OutputTextBox.AppendText(SI.getTerm("DT").toString() + "\n");
                    }
                }
            }
            catch (MalformedGoalException ex) {
                OutputTextBox.AppendText("Malformed Goal\n");
            }
        }
예제 #2
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            String inputString = inputTextBox.Text;

            try
            {
                Term      goal   = new Struct("dExpr", Term.createTerm(inputString), new Var("Der"));
                SolveInfo answer = engine.solve(goal);
                if (answer.isSuccess())
                {
                    Term derivata = answer.getTerm("Der");
                    lblRes.Text = derivata.toString();
                }
                else
                {
                    lblRes.Text = "Error: no solution";
                }
            }
            catch (InvalidTermException e3)
            {
                Console.WriteLine("The esxpression is not a valid Prolog Term.");
            }
            catch (UnknownVarException e4)
            {
                Console.WriteLine("Variable not valid.");
            }
            catch (NoSolutionException e5)
            {
                Console.WriteLine("No solutions.");
            }
        }
예제 #3
0
 public bool hasSolutionWithOutput()
 {
     output = "";
     engine.addOutputListener(new StringOutputListener(output));
     result = engine.solve(query);
     engine.removeAllOutputListeners();
     return(result.isSuccess());
 }
예제 #4
0
        public bool Success()
        {
            Prolog engine = new Prolog();

            OOLibrary.OOLibrary lib = new OOLibrary.OOLibrary();
            engine.unloadLibrary("alice.tuprolog.lib.JavaLibrary");
            engine.loadLibrary(lib);
            SolveInfo info = engine.solve(goal);

            return(info.isSuccess());
        }
예제 #5
0
 public bool hasAnotherSolution()
 {
     try
     {
         result = engine.solveNext();
         return(result.isSuccess());
     }
     catch (PrologException e)
     {
         return(false);
     }
 }
예제 #6
0
 public bool hasAnotherSolutionWithOutput()
 {
     output = "";
     engine.addOutputListener(new StringOutputListener(output));
     try
     {
         result = engine.solveNext();
         engine.removeAllOutputListeners();
         return(result.isSuccess());
     }
     catch (PrologException e)
     {
         return(false);
     }
 }
예제 #7
0
        public static void Main(string[] args)
        {
            //OpenFileDialog dialog = new OpenFileDialog();
            //dialog.ShowDialog();

            OOLibrary   lib    = new OOLibrary();
            InputStream stream = new FileInputStream(@"Test.pl");
            // InputStream stream = new FileInputStream("C:\\Users\\Administrator\\Desktop\\Test.pl");


            Prolog engine = new Prolog();
            //engine.unloadLibrary("alice.tuprolog.lib.JavaLibrary");
            //engine.loadLibrary(lib);

            Theory th = new Theory(stream);

            engine.addTheory(th);
            SolveInfo info = engine.solve("testInteroperation(X).");

            System.Console.WriteLine(info.isSuccess());
            System.Console.WriteLine(info.isHalted());

            //info = engine.solve("testBasicsWithJava.");
            //System.Console.WriteLine(info.isSuccess());
            //System.Console.WriteLine(info.isHalted());


            //java.util.List[] primitives = lib.getPrimitives();

            //for (int i = 0; i < primitives.Length; i++)
            //{
            //    PrimitiveInfo p = (PrimitiveInfo)primitives[i];
            //}



            System.Console.ReadLine();
        }
예제 #8
0
        /* Meters */

        public bool hasSolution()
        {
            result = engine.solve(this.query);
            return(result.isSuccess());
        }