Example #1
0
    public string QueryRules(string ruleset, string query)
    {
        string s;
        int    term, answer;
        int    len;

        try
        {
            s    = "arxl_query(" + ruleset + ", false, `" + query + "`, ?answer)";
            term = ls.ExecStr(s);
            if (term == 0)
            {
                throw new Exception(FormatARulesError());
            }

            // The answer is a string in the 4th argument
            // Could be any type, turn it into a string
            answer = ls.GetArg(term, 4);
            len    = ls.StrTermLen(answer);
            return(ls.TermToStr(answer, len + 1));
        }
        catch (LSException ex)
        {
            throw new Exception("Error getting arules error: " + ex.GetMsg());
        }
    }
Example #2
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();
            }
        }