2015-12-26 14 views
0

在C#应用程序中,我想使用Aleph来构建理论。在C#中使用Aleph与SWI Prolog?

在SWI-Prolog的以下作品:

 
?- [aleph.pl]. 

?- working_directory(CDW,'C:/Users/admin/Desktop/inputFiles'). 

?- read_all(datainput). 

?- induce. 

但在C#这些命令并不:

 
if (!PlEngine.IsInitialized) 
{ 
    String[] param = { "-q" };  
    PlEngine.Initialize(param); 

    PlQuery.PlCall("consult('C:/Users/admin/Desktop/Aleph_pack/Aleph.pl')"); 

    PlQuery.PlCall("working_directory(CDW,'C:/Users/admin/Desktop/inputFiles')); 

    PlQuery.PlCall("assert(read_all(datainput))"); // ERROR! 

    PlQuery.PlCall("assert(induce)"); 
} 

我得到PlQuery.PlCall("assert(read_all(datainput))")以下错误:

An unhandled exception of type 'SbsSW.SwiPlCs.Exceptions.PlException' occurred in SwiPlCs.dll 
Details: 
SbsSW.SwiPlCs.Exceptions.PlException was unhandled 
HResult=-2146233088 
Message=assert/1: No permission to modify static procedure `read_all/1' 
Defined at c:/users/admin/desktop/aleph_pack/aleph.pl:8857 

我该如何解决这个错误?

+0

没有特别的理由,谢谢您的修改。 –

回答

1

为什么你用C#的错误,但不能直接使用的Prolog时的原因,是这样的:

You are doing two different things!

让我们交错上述两个片段:

 
?-      read_all(datainput) . 
%% PlQuery.PlCall("assert(read_all(datainput))"); 

?-      induce . 
%% PlQuery.PlCall("assert(induce)"); 

所以,你正在使用在C#代码中,但不在交互式SWI-Prolog会话中。

你得到了多行错误的一部分,指向那个方向,也:

assert/1: No permission to modify static procedure `read_all/1'

简历通过琢磨该差值的调查。如果您的代码的旧版本显示不同的行为,请检查它们(以及当前代码的增量)!

+1

谢谢,但我不知道我该如何解决这个问题? –

+0

@ K.Ros。如何尝试'PlQuery.PlCall(“read_all(datainput)”); PlQuery.PlCall(“诱导”);'?或者为什么在从C#调用时需要“断言(...)',而不是在SWI-Prolog外壳中? – repeat

+1

应用程序在与”PlQuery.PlCall(“read_all(datainput)”)一起运行时停止; PlQuery.PlCall (“诱导”)' –