如何从 Java 使用 Prolog?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4303931/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 05:46:09  来源:igfitidea点击:

How use Prolog from Java?

javaprolog

提问by Manuel Selva

In the context of a Java/Eclipse application I would like to use Prolog for a particular task. What are the available solutions and tools to do that, and associated pro and cons ?

在 Java/Eclipse 应用程序的上下文中,我想将 Prolog 用于特定任务。有哪些可用的解决方案和工具可以做到这一点,以及相关的利弊?

I can launch an external Prolog interpreter generating the result in a file ? I can use a full Prolog Java Library (Prolog interpreter implemented in java) ? I can use a java library dedicated to the communication with an external Prolog interpreter ?

我可以启动一个外部 Prolog 解释器在文件中生成结果吗?我可以使用完整的 Prolog Java 库(在 Java 中实现的 Prolog 解释器)?我可以使用专用于与外部 Prolog 解释器通信的 Java 库吗?

Thanks in advance for your help,

在此先感谢您的帮助,

Manu

摩奴

采纳答案by aioobe

I would give GNU Prolog for Javaa try. From the website:

我想试试GNU Prolog for Java。从网站:

GNU Prolog for Java is an implementation of ISO Prolog as a Java library

GNU Prolog for Java 是作为 Java 库的 ISO Prolog 的实现

回答by ProfVersaggi

I'm using tuPrologOfficial Site, Code Repositoryon Android. They have a great embedded Prolog in the form on 1 Jar File. They are responsive too!

我正在使用tuProlog官方网站,Android 上的代码库。他们以 1 Jar 文件的形式嵌入了一个很棒的 Prolog。他们也有反应!

回答by Mostowski Collapse

When looking at multi-threaded Prolog systems, there are different additional considerations. One desiderata is to have a separation between threads and logic engines. This was expressed here: http://www.cs.nmsu.edu/ALP/2011/03/concurrent-programming-constructs-and-first-class-logic-engines/

在查看多线程 Prolog 系统时,还有其他不同的考虑因素。一个需要是在线程和逻辑引擎之间进行分离。这在这里表达:http: //www.cs.nmsu.edu/ALP/2011/03/concurrent-programming-constructs-and-first-class-logic-engines/

There are some Prolog systems that realize this separation. Jekejeke Prolog is also among these systems. There is a report (*) that shows how this separation can be put to use. In the various scenarios we see that the "thread" is provided by a system external to the logic engine:

有一些 Prolog 系统实现了这种分离。Jekejeke Prolog 也是这些系统之一。有一份报告 (*) 显示了如何使用这种分离。在各种场景中,我们看到“线程”是由逻辑引擎外部的系统提供的:

  • Terminal Deployment: Thread is the Java main thread.
  • Standalone Deployment: Thread is the AWT/Swing thread.
  • Applet Deployment: Thread is some browser thread.
  • Servlet Deployment: Thread comes from web server pool.
  • Client Deployment: Thread is the AWT/Swing thread.
  • 终端部署:Thread是Java主线程。
  • 独立部署:线程是 AWT/Swing 线程。
  • 小程序部署:线程是一些浏览器线程。
  • Servlet 部署:线程来自 Web 服务器池。
  • 客户端部署:线程是 AWT/Swing 线程。

Best Regards

最好的祝福

http://www.jekejeke.ch/idatab/doclet/prod/en/docs/05_run/15_stdy/08_deploy/package.html

http://www.jekejeke.ch/idatab/doclet/prod/en/docs/05_run/15_stdy/08_deploy/package.html

回答by Michael Lloyd Lee mlk

A quick google returns a list of options(alas not updated in 5 years).

一个快速的谷歌返回一个选项列表(唉 5 年内没有更新)。

As for pros/cons - as I see it
Native engine with bindingswould be the worse option when it comes to distribution and integration, but may be faster than the native Java engines (but I would want proof first).
Java engine with APIwould lead to some awkwardness at integration points, but should be easy to distribute.
Prolog to bytecode compilershould handle integration between the two languages nicely, and would mean that you are not shipping prolog scripts with the binary (may be a disadvantage). Big disadvantage with this - none still seem to be a live.
Prolog-alike language to bytecode compiler, same as above, but some still seem to be floating about, also would require knowledge of a new language.
Java rules engine- I'd see this as the neatest solution. Rather than use two languages code the rules in a Java-y way, but it depends on how complicated the rules are to express in that way.

至于优点/缺点 - 正如我所见,在分发和集成方面,
带有绑定的机引擎将是更糟糕的选择,但可能比本机 Java 引擎更快(但我首先需要证据)。
带有 API 的 Java 引擎在集成点会导致一些尴尬,但应该易于分发。
字节码编译器的序言应该很好地处理两种语言之间的集成,这意味着您没有使用二进制文件传送序言脚本(可能是一个缺点)。这样做的大缺点 - 似乎仍然没有人是活人。
字节码编译器的 Prolog-alike 语言,与上面相同,但有些似乎仍在浮动,也需要了解新语言。
Java 规则引擎- 我认为这是最好的解决方案。不是使用两种语言以 Java-y 方式对规则进行编码,而是取决于以这种方式表达规则的复杂程度。

A second thing to consider is - is the project still being updated. From my quick google, few are. Provaand Mandaraxare two exceptions from the latter options.

要考虑的第二件事是 - 项目是否仍在更新。从我的快速谷歌来看,很少。PROVAMandarax是从后者选择两个例外。

回答by Nicolas

You may also have a look at JPL http://www.swi-prolog.org/FAQ/Java.html

你也可以看看 JPL http://www.swi-prolog.org/FAQ/Java.html