0

大学の試験の修正のために、次の構造を持つ Prolog データベースを使用した過去の紙の質問に出くわしました。

% The structure of a media production team takes the form
% team(Producer, Core_team, Production_assistant).
% Core_team is an arbitrarily long list of staff structures,
% but excludes the staff structures for Producer and
% and Production_assistant.
% staff structures represent employees and take the form
% staff(Surname,Initial,file(Speciality,Grade,CV)).
% CV is an arbitrarily long list of titles of media productions.

team(staff(lyttleton,h,file(music,3,[my_music,best_tunes,showtime])),
[staff(garden,g,file(musical_comedy,2,[on_the_town,my_music])),
staff(crier,b,file(musical_comedy,2,[on_the_town,best_tunes]))],
staff(brooke-taylor,t,file(music,2,[my_music,best_tunes]))).

team(staff(wise,e,file(science,3,[horizon,frontiers,insight])),
[staff(morcambe,e,file(science,3,[horizon,leading_edge]))],
staff(o_connor,d,file(documentary,2,[horizon,insight]))).

team(staff(merton,p,file(variety,2,[showtime,dance,circus])),
[staff(smith,p,file(variety,1,[showtime,dance,circus,my_music])),
staff(hamilton,a,file(variety,1,[dance,best_tunes]))],
staff(steaffel,s,file(comedy,2,[comedians,my_music]))).

team(staff(chaplin,c,file(economics,3,[business_review,stock_show])),
[staff(keaton,b,file(documentary,3,[business_review,insight])),
staff(hardy,o,file(news,3,[news_report,stock_show,target,now])),
staff(laurel,s,file(economics,3,[news_report,stock_show,now]))],
staff(senate,m,file(news,3,[business_review]))).

私が書かなければならないルールの1つは次のとおりです。

チームに 2 人の従業員が含まれ、CV に「Now」というタイトルの作品が含まれるプロデューサーのイニシャルと姓を返します。

これが私の解決策です:

recurseTeam([],0).

recurseTeam[staff(_,_file(_,_,CV))|List],Sum):-
    member(now,CV),
    recurseTeam(List,Rest),
    Sum is Rest + 1.

query(Initial,Surname):-
    team(staff(Surname,Initial,file(Speciality,Grade,CV)),Core_team,Production_assistant),
    recurseTeam([staff(Surname,Initial,file(Speciality,Grade,CV)),Production_assistant|Core_team,Sum),
Sum >= 2.

ここでのロジックは、各スタッフ メンバーを順番に取得する再帰的な述語があり、CV リストに「現在」のプロダクションが含まれている場合にのみ一致が検出され、ご覧のとおり、イニシャルと姓が返されるというものです。少なくとも 2 人の従業員の履歴書に「現在」のプロダクションが含まれている場合はプロデューサー。

だから、少なくとも私が見る限り、それは c,chaplin プロデューサーを返すはずですよね? このチームには、「今」の制作を含む履歴書を持つスタッフがいるからです。

しかし、クエリを実行すると、たとえば

qii(Initial,Surname).

「false」を返します。

「member(now,CV)」述語を削除すると、4 つのプロデューサーすべてが正常に返されます。したがって、問題はこのルールにあるようです。Member はリストの内容を照会するための組み込みの述語であり、'CV' は譜表構造のファイル構造内に含まれるリスト構造です。

これが期待どおりに機能しない理由はありますか?

ここで他に何を試すことができるかについて何か提案はありますか?

4

1 に答える 1