true - 来自C#中prolog的查询的错误响应

时间:2015-04-14 17:45:09

标签: c# ffi swi-prolog

我使用带有c#的swiprolog作为前端。我想在mmessagebox中显示是否执行查询。所以我需要回答“真实”的问题。或者' false'喜欢它来自prolog控制台。这是我的代码:

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);
    }

}

1 个答案:

答案 0 :(得分:0)

首先让我说明我从未使用过swi-prolog,所以这可能不是你想要的。但我能够阅读文档和样本...... :)

我找到了这个页面:http://www.lesta.de/prolog/swiplcs/Generated/html/M_SbsSW_SwiPlCs_PlQuery__ctor.htm

听起来你可能会想要以下内容。或者至少它可能有助于你开始?

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();