gpt4 book ai didi

c# - 将 Prolog 与 C# 集成

转载 作者:太空狗 更新时间:2023-10-30 01:18:14 24 4
gpt4 key购买 nike

我是 Prolog 和 C# 的新手。当我尝试将 Prolog 与 C# 集成时,我发现了一些错误,

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SbsSW.SwiPlCs;


namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
// Environment.SetEnvironmentVariable("SWI_HOME_DIR", @"the_PATH_to_boot32.prc"); // or boot64.prc
if (!PlEngine.IsInitialized)
{
String[] param = { "-q" }; // suppressing informational and banner messages
PlEngine.Initialize(param);
PlQuery.PlCall("assert(father(martin, inka))");
PlQuery.PlCall("assert(father(uwe, gloria))");
PlQuery.PlCall("assert(father(uwe, melanie))");
PlQuery.PlCall("assert(father(uwe, ayala))");
using (var q = new PlQuery("father(P, C), atomic_list_concat([P,' is_father_of ',C], L)"))
{
foreach (PlQueryVariables v in q.SolutionVariables)
Console.WriteLine(v["L"].ToString());

Console.WriteLine("all children from uwe:");
q.Variables["P"].Unify("uwe");
foreach (PlQueryVariables v in q.SolutionVariables)
Console.WriteLine(v["C"].ToString());
}
PlEngine.PlCleanup();
Console.WriteLine("finished!");
}
}
}
}

它没有运行,在运行之前我添加了引用 SwiPlCs.dll。但它显示错误“FileNotFoundException 未处理,找不到指定的模块。(HRESULT 异常:0x8007007E)”。

那么谁能帮我解决这个错误?

我得到了这个编码 here

最佳答案

您提供的链接对此错误有完整的解释:

If libswipl.dll or one of its dependencies could not found you will recive an error like System.IO.FileNotFoundException: Das angegebene Modul wurde nicht gefunden. (Ausnahme von HRESULT: 0x8007007E)

An other common error is:

SWI-Prolog: [FATAL ERROR:
Could not find system resources]`
Failed to release stacks

To fix this add the SWI_HOME_DIR environment variable as described in SWI-Prolog FAQ FindResources with a statment like this befor calling PlEngine.Initialize.

Environment.SetEnvironmentVariable("SWI_HOME_DIR", @"the_PATH_to_boot32.prc");

此代码默认已注释,取消注释并提供指向 the_PATH_to_boot32.prc 的正确路径。如常见问题解答中所述:

Solution

On Windows, it suffices to leave libswipl.dll in the installation tree (i.e., do not copy it elsewhere) and add the bin directory of the installation tree to %PATH%.

A cross-platform and robust solution is to use putenv() to put an appropriate path into the environment before calling PL_initialise().

...;
putenv("SWI_HOME_DIR=C:\\Program Files\\swipl");
if ( PL_initialise(argc, argv) )
PL_halt(1);
...

In the final version of your application you link the saved-state to the executable (using swipl-ld or cat (Unix)) and comment the putenv() call.

关于c# - 将 Prolog 与 C# 集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28253960/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com