用Prolog显示结果

if twol then twolegs.
if twoh then twohands
if tenf then tenfingers.
if twof then twofeets.
if smallh then smallhair.
if fourlegs and nohands and nofingers and fourfeets and doghair then dog.
if twolegs and twohands and tenfingers and twofeets and smallhair then person.
if fourlegs and nohands and nofingers and fourfeets and doghair then dog.
if twolegs and twohands and tenfingers and twofeets and smallhair then person.


    % forward chaining
    forward :-
     new_derived_fact(P),!,
     write('solution: '),writeln(P),
     assert(derived_fact(P)),
     forward ;
     writeln('No more facts').
    new_derived_fact(P) :-
     if Cond then P,
     \+ fact(P),
     \+ derived_fact(P),
     truth(Cond).
    truth(P) :-
     fact(P) ;
     derived_fact(P).
    truth(P1 and P2) :-
     truth(P1),
     truth(P2).
    truth(P1 or P2) :-
     truth(P1) ;
     truth(P2).

    %database
    solution(person, address, id, house).
    solution(dog, dogaddress, dogid, doghouse)

我有这段使用前向链的prolog代码,如何从数据库中显示 “地址,id,房子 “这样的 “人 “的结果?

我有这段使用前向链的prolog代码,如何从数据库中显示 “地址,id,房子 “这样的结果 “person”?

解决方案:

编辑数据库

 %database
    solution(person, addressx, idp1, house).
    solution(person, addressy, idp2, house).
    solution(person, addressz, idp3, house).
    solution(dog, dogaddressx, dogid1, doghouse).
    solution(dog, dogaddressy, dogid2, doghouse).

给TA打赏
共{{data.count}}人
人已打赏
未分类

当使用position:absolute时,无法将文本居中。

2022-9-8 22:00:38

未分类

如何使A分部的子女与其兄弟姐妹B分部重叠?

2022-9-8 22:00:40

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索