【问题标题】:Problem with building an expert system in prolog在 prolog 中构建专家系统的问题
【发布时间】:2021-04-30 16:04:56
【问题描述】:

在 prolog 中编译此代码时,我不断收到语法错误。我是编程新手,所以不太明白。有人可以帮我调试我出错的地方吗?专家系统旨在将动物与脊椎动物和无脊椎动物进行分类。这是我目前拥有的代码:

:-dynamic known/3
top_goal(X):-animal(X).

%Animals and their classifications
animal(lion):-
    type(vertebrate),
    color(brown).

animal(bee):-
    type(invertebrate),
    color(yellow).

animal(crickets):-
    type(invertebrate),
    color(green).

%background information about vertebrates and invertebrates.

animal(vertebrate):-
    vertebral_column(present),
    nerve_cord(dorsal_and_hollow),
    skeleton(internal),
    heart(located_on_right_side),
    haemoglobin(present_in_red_blood_cells).

animal(invertebrate):-
    vertebral_column(absent),
    skeleton(external),
    heart(located_on_dorsal_side),
    haemoglobin(dissolved_in_plasma).

%Ask rules
animal(X):-ask(type,X).
animal(X):-ask(color,X).
animal(X):-ask(sound,X).

ask(A,V):-
    write(A:V),%ask user
    write('?:'),
    read(Y),%get the answer
    asserta(known(Y,A,V),%remember it
    Y==yes.%succeed or fail

solve:-
    retractall(known(_,_,)),
    top_goal(X),
    write('The animal is '),write(X),nl.

solve:-
    write('This animal is unknown '),nl.

【问题讨论】:

    标签: prolog expert-system


    【解决方案1】:

    你有一些错别字。

    ask(A,V):-
        write(A:V),%ask user
        write('?:'),
        read(Y),%get the answer
        asserta(known(Y,A,V)), %remember it ***missing ')'
        Y==yes.%succeed or fail
    

    这里

    solve:-
        retractall(known(_,_,_)), % *** missing _
        top_goal(X),
        write('The animal is '),write(X),nl.
    

    然后缺少一些代码:颜色/1、血红蛋白/1、心脏/1、 neuro_cord/1,skeleton/1,top_goal/1,type/1,vertebral_column/1。

    【讨论】:

    • 我回答你的问题了吗?如果是这样,请升级此答案以帮助像您这样的其他新用户。如果不是,请澄清您的问题,或提出其他问题!
    猜你喜欢
    • 1970-01-01
    • 2012-12-08
    • 2016-03-03
    • 2011-11-28
    • 2018-03-05
    • 1970-01-01
    • 2020-05-28
    • 2010-09-15
    • 1970-01-01
    相关资源
    最近更新 更多