如何在jpl中将文件作为模块进行咨询 [英] how to consult file as a module in jpl

查看:108
本文介绍了如何在jpl中将文件作为模块进行咨询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Prolog文件作为模块进行查询,因为jpl不支持多个prolog虚拟机.

I am trying to consult Prolog file as a module, since jpl does not support multiple prolog vms.

在swipl控制台中,我可以成功完成类似的操作

In swipl console, I can do something like this successfully

?- consult(mod1:'data/load.pro') .

在Java中(实际上,它实际上是scala,但它们都位于jvm之上),我可以直接咨询文件而无需发出问题

In java (well, it is actually scala, but they are all on top of jvm), I can consult file directly w/o issue

scala> import jpl._

scala> val q = new Query("consult", Array[Term](new Atom("data/load.pl")))

scala> q.query()
...
true

但是,当我尝试将文件作为模块进行查询时,总是会遇到异常.

however, when I tried to consult the file as module, I always get the exception.

scala> val q = new Query("consult", Array[Term](new Atom("mod1:data/load.pl")))

scala> q.query()
  jpl.PrologExcepion:  PrologException: error(existence_error(source_sink, 'mod1:data/load.pl'), _0)
    at jpl.Query.get1(Query.java:336)
    at jpl.Query.hasMoreSolutions(Query.java:258)
    at jpl.Query.oneSolution(Query.java:688)
    at jpl.Query.query(Query.java:747)
    at .<init>(<console>:15)
    at .<clinit>(<console>)
    ....

任何人都可以指出我将prolog文件作为jpl中的模块进行咨询的正确方法吗?谢谢!

Anybody can point me to the correct way of consulting prolog file as module in jpl? Thanks!

推荐答案

我认为您可以在谓词上交换模块资格,当然,这将允许您传递自己的完整路径源文件:

I think you can swap the module qualification on predicate, and of course that would allow you to pass in the full path of your source file:

val q = new Query("mod1:consult('full_path_to/load.pl')")

这篇关于如何在jpl中将文件作为模块进行咨询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆