Example #1
0
    public void OpenRules(string rulesetfile, string arulespath)
    {
        string s;
        long   term;

        try
        {
            // Get our logicserver and initialize it
            ls = new LogicServer();
            ls.Init(DoubleSlashes(arulespath + "arulesrt.cfg"));

            // Load the arulesxl engine
            ls.Load(DoubleSlashes(arulespath + "arulesrt.xpl"));

            // Load the ruleset
            if (rulesetfile != null)
            {
                s    = "consult(`" + DoubleSlashes(rulesetfile) + "`)";
                term = ls.ExecStr(s);
                if (term == 0)
                {
                    throw new Exception("Unable to consult ruleset");
                }
            }
        }
        catch (LSException ex)
        {
            throw new Exception("OpenRules / " + FormatLSException(ex));
        }
    }
Example #2
0
        private void GetPetButton_Click(object sender, System.EventArgs e)
        {
            LogicServer ls;
            int         term;

            term = 0;
            try
            {
                ls = new LogicServer();
                ls.Init("");
                ls.Load("pets.xpl");
                ls.AssertaStr("sound(" + SoundText.Text + ")");
                term = ls.ExecStr("pet(X)");
                if (term != 0)
                {
                    PetText.Text = ls.GetStrArg(term, 1);
                }
                else
                {
                    PetText.Text = "Unknown Pet";
                }
                ls.Close();
            }
            catch (LSException ex)
            {
                String message = ex.GetMessage();
                PetText.Text = message;
            }
        }
Example #3
0
        private void GoButton_Click(object sender, System.EventArgs e)
        {
            LogicServer     ls;
            PrologPredicate prompt_pred;
            int             term;
            string          pet;

            ls          = new LogicServer();
            prompt_pred = new PrologPredicate(prompt);
            try
            {
                ls.Init("");
                ls.AddPred("prompt", 2, prompt_pred);
                ls.Load("pets.xpl");
                term = ls.ExecStr("pet(X)");
                if (term == 0)
                {
                    MessageBox.Show("Sound not found", "ERROR",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    pet          = ls.GetStrArg(term, 1);
                    PetText.Text = pet;
                }
                ls.Close();
            }
            catch (LSException ex)
            {
                MessageBox.Show(ex.GetMessage(), "ERROR",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #4
0
        public int TestSimple()
        {
            string binDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Bin");

            var obj = new LogicServer();

            obj.Init("");
            obj.Load(Path.Combine(binDir, "family.xpl"));
            obj.ExecStr("assert(house(1)).");

            var t = obj.ExecStr("house(1).");

            return(Convert.ToInt32(t));
        }
Example #5
0
        // handle actions when button 'Get Result' is clicked
        private void GetResult_Click(object sender, System.EventArgs e)
        {
            LogicServer ls;
            int         term;

            try
            {
                // Initialize the logic server //
                ls = new LogicServer();
                ls.Init("");
                const string x = @"C:\Program Files\amzi\ide\workspace\cpe425\bin\cpe425.xpl";
                ls.Load(x);

                // get boarding station and alighting station input and execute corresponding command in Prolog //
                term = ls.ExecStr("shortest(" + (comboBox1.SelectedItem).ToString() + "," + (comboBox2.SelectedItem).ToString() + ", MinTime, MinRoute)");

                // analyse the return value, if return value != 0, means the command was successfully executed //
                if (term != 0)
                {
                    // show out the shortest travel time,
                    TimeResult.Text = (ls.GetIntArg(term, 3)).ToString();

                    // show out the shortest travel route, as return value is list, we must recursively get all elements in this list //
                    int    term1 = ls.GetArg(term, 4);
                    string s     = ls.GetStrHead(term1);
                    while (ls.GetTail(term1) != 0)
                    {
                        s    += " -> " + ls.GetStrHead(ls.GetTail(term1));
                        term1 = ls.GetTail(term1);
                    }
                    RouteResult.Text = s;
                }
                else
                {
                    TimeResult.Text  = "Invalid Request!";
                    RouteResult.Text = "Invalid Request!";
                }

                // close the logic server
                ls.Close();
            }
            catch (LSException ex)
            {
                String message = ex.GetMessage();
            }
        }