[英]true - false response of query from prolog in C#
I am using swi- prolog with c# as front end. 我正在使用带有C#的swi-prolog作为前端。 I want to to display whether the the query is executed or not in a mmessagebox.
我想在mmessagebox中显示是否执行查询。 So i need the answer in 'true' or 'false' like it comes in prolog console.
因此,我需要“真”或“假”的答案,就像Prolog控制台中提供的一样。 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. 首先,请允许我说一下我从未使用过swi-prolog,所以这可能不是您想要的。 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 我找到了以下页面: 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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.