【问题标题】:Expert system in SWI PrologSWI Prolog 中的专家系统
【发布时间】:2014-12-19 08:09:48
【问题描述】:

我尝试在 SWI Prolog 中实现简单的专家系统。该系统从键盘读取输入数据并找到语言。这是我的代码:

/* Paradigms */
paradigm('Ada', 'Imperative').
paradigm('C', 'Imperative').

/* Typization */
typization('Ada', 'Statical').
typization('C', 'Explicit').

/* Compiler */
compiler('Ada', 'OpenSource').
compiler('C', 'DebugPosibility').

/* Memory */
memory('Ada', 'Stack').
memory('C', 'Pointer').

language(L, P, T, C, M) :- paradigm(L, P), typization(L, T), compiler(L, C), memory(L, M).

run :- write('\nChoose language paradigm:\n1. imperative\n2. object-oriented\n3. distributed\n4. reflexive\n5. declarative\n6. functional\n7. general programming\n'), read(P),
       write('\n\nChoose typization:\n1. statical\n2. explicit\n3. polymorfism\n4. runtime type information\n5. dynamical\n6. implicit\n7. cast without data lose\n8. implicit cast without data lose\n9. argument output at method call\n'), read(T),
       write('\n\nChoose compiler type:\n1. open-source\n2. debug posibility\n3. bootstrapping\n4. multithreading compilation\n5. conditional compilation\n6. command line interpreter\n'), read(C),
       write('\n\nChoose memory management type:\n1. stack\n2. pointer\n3. manual memory management\n4. garbage collector\n'), read(M),

       language(L, P, T, C, M),
       write(L).

当我运行这个程序时,我总是收到所有语言。但在我的测试用例中,它应该只得到一种语言。当来自 language 的所有四个谓词对同一语言 L 都返回 true 时,该语言是可以接受的。我的错误在哪里,我该如何解决?

非常感谢!

【问题讨论】:

    标签: prolog


    【解决方案1】:

    错误出现在输入的捕获中(特别是,要求用户输入与程序实际期望的内容不相符的字符串;请注意这里)。如果您使用原子并删除单引号,则带有两个测试用例的程序将显示:

    paradigm(ada, imperative).
    paradigm(c, imperative).
    
    typization(ada, statical).
    typization(c, explicit).
    
    compiler(ada, openSource).
    compiler(c, debugPosibility).
    
    memory(ada, stack).
    memory(c, pointer).
    
    language(L, P, T, C, M) :- paradigm(L, P), typization(L, T), compiler(L, C), memory(L, M).
    
    test1(L) :- language(L, imperative, statical, openSource, stack).
    test2(L,P) :- language(L, P, statical, openSource, stack).
    

    运行test1(L) 只产生L=ada,运行test2(L,P) 只产生L=ada, P=imperative,如所愿。

    【讨论】:

      猜你喜欢
      • 2012-12-08
      • 2021-04-30
      • 2016-03-03
      • 1970-01-01
      • 1970-01-01
      • 2018-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多