简体   繁体   中英

true - false response of query from prolog in C#

I am using swi- prolog with c# as front end. I want to to display whether the the query is executed or not in a mmessagebox. So i need the answer in 'true' or 'false' like it comes in prolog console. here is my code:

static void Main(string[] args)
{

    Environment.SetEnvironmentVariable("SWI_HOME_DIR", @"C:\Program Files\swipl");
    Environment.SetEnvironmentVariable("PATH", @"C:\Program Files\swipl");
    Environment.SetEnvironmentVariable("PATH", @"C:\Program Files\swipl\bin");
    string p1 = @"C:\Program Files\swipl\try9.pl";

    string[] p = { "-q", "-f", p1 };
    PlEngine.Initialize(p);
    try
    {

        PlQuery q = new PlQuery("get(sam,age(26)).");

        // here i need the responce of prolog engine of the above query whether true or false .
        Console.ReadLine();

    }
    catch (PlException ex)
    {
        Console.WriteLine("exception handeled" + ex.Message);
    }

}

Let me state first of all that I have never used swi-prolog, so this may not be what you're looking for. But I am able to read documentation and samples... :)

I found this page: http://www.lesta.de/prolog/swiplcs/Generated/html/M_SbsSW_SwiPlCs_PlQuery__ctor.htm

And it sounds like you might want something like the following. Or at least maybe it helps get you started?

try
{
    using (var q = new PlQuery("get(sam,age(26))."))
    {
        if (q.Solutions == null) // Not sure if this is possible?
        {
            Console.WriteLine("Query did not run successfully.");
        }
        else
        {
            Console.WriteLine("Query returned {0} items.", q.Solutions.Count());
        }               
    }
}
catch (PlException ex)
{
    Console.WriteLine("Exception handled: " + ex.Message);
}

Console.ReadLine();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM