【问题标题】:Can I retrieve information from another file, using Prolog?我可以使用 Prolog 从另一个文件中检索信息吗?
【发布时间】:2013-05-05 19:55:25
【问题描述】:

我正在尝试编写一个简单的翻译脚本,但文件变得相当……冗长且令人困惑,主要是因为我已将所有翻译存储在文件末尾。它们的格式为动词(英语、芬兰语)。

我想知道是否有任何方法可以将它们存储在不同的文件中,所以我不需要处理它们。 我已经研究过使用咨询谓词,但我认为这并不完全符合我的需要。有没有办法在 SWI-prolog 中做到这一点?

作为记录,如果我使用咨询谓词,我会收到以下错误消息:

如果我尝试使用咨询谓词,我会收到以下错误:

Warning: The predicates below are not defined. If these are defined
Warning: at runtime using assert/1, use :- dynamic Name/Arity.
Warning: 
Warning: verb/2, which is referenced by
Warning:        c:/users/grant/documents/prolog/string_dictionary.pl:6:8: 1-st clause of translate_word/2

【问题讨论】:

    标签: prolog encapsulation swi-prolog prolog-directive-dynamic


    【解决方案1】:

    您可以将指令multifileconsult/1 或include/1 一起使用,但我建议改为使用modules。多做一点工作,得到更好的维护和支持。

    在动词文件的顶部添加声明

    :- module(verbs, [verb/2]).
    

    然后在你的翻译脚本中添加

    :- use_module(verbs).
    

    【讨论】:

    • 这正是我想要的。谢谢。
    【解决方案2】:

    我认为consult/1 是您所需要的。

    只需将您的verb 事实(顺便说一句,为什么Verb 在您的问题中大写?事实和规则名称不能以大写字母开头)放入单独的文件中,并在您的主 Prolog 文件中查阅该文件。

    【讨论】:

      猜你喜欢
      • 2013-01-07
      • 1970-01-01
      • 2020-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-14
      • 1970-01-01
      • 2014-08-24
      相关资源
      最近更新 更多