[英]true - false response of query from prolog in C#
我正在使用帶有C#的swi-prolog作為前端。 我想在mmessagebox中顯示是否執行查詢。 因此,我需要“真”或“假”的答案,就像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);
}
}
首先,請允許我說一下我從未使用過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();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.