0

下部に、ヘルプを簡単にするためにプログラム全体(ciao)へのリンクを示しました。私は次のような質問のリストがあるProlog関数で作成しようとします

 questions([[[What, are,you,doing,?],[Where,am,I,Incorrect,?]]]).
 answers([[Im,doing,exercise],[I,do,nothing]],[[You,are,incorrect,at,'..'],[i,dont,know]]]).
 wordkeys([[[Incorrect,50],[doing,20]]]).

私はそれが本当に厄介に見えることを知っていますが、私は本当に助けが必要であり、感謝するでしょう。主な機能は、どの回答が最良であるかをチェックすることです(キーワードポイントの合計が最大です)。私の問題は、ここで最後の関数に移動するまで、すべてが正常に見えることです(何が起こっているかを確認するためにいくつかのwrite()を作成しました):

count_pnt_keys()

Prologは、すべての単語が等しいかどうかをチェックしますが、キーワードから外れると、それと呼ばれる関数に戻る必要がありますが、それは単に「いいえ」です。たぶん、Tailだけで同じ関数を再度呼び出す前に、リストが空かどうかを確認する必要がありますか?これを行う方法?

ルール:

count_pnt([],[],[]).
count_pnt([Ah|At],Keys,RList) :-      %choose one answer from answer list and go further
    count_pnt_word(Ah,Keys,Pnts),     %return sum of points for one answer
    count_ADD_POINT(RList,Pnts),      %not important here
    count_pnt(At,Keys,RList).         %call again with next question
/*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
count_pnt_word([],[],0)
count_pnt_word([Ah|At],Keys,Pnts) :-  %choose one WORD from answer and go further
    count_pnt_keys(Ah,Keys,Pnts),
    count_pnt_word(At,Keys,Pnts).     %call recursion with next word from answer
/*vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv*/
count_pnt_keys([],[],0)
count_pnt_keys(AWord,[Kh|Kt],Pnts) :- %check word with all keys for first question
    get_tail_h(Kh,KWORD,KPOINTS),     %just return head and tail from first key
    AWord==KWORD,                     %check if they are equal
    /*counting points*/ !,            %counting not important when end counting points go out to next
    count_pnt_keys(AWord,Kt,Pnts). %call again if not equal and try with next key

そして私はそれを呼びます:

test :-
write(AnswerFirst),
count_pnt(FirstPackOfAnswer,FirstPackofKeys,ReturnedListwithpoints),
write(ReturnedListwithpoints).

コードへのリンク(ciao) http://wklej.org/id/754478/

4

2 に答える 2

0

count_pnt3つの自由な引数を使用して呼び出します。これは、count_pnt最初にすべての引数を空のリストで統合することを意味します。バックトラックすると、再帰count_pnt句が呼び出されcount_pnt_keys、3つの自由な引数が再び呼び出されます。これにより、失敗ではなく、etcとのAh統合が行われます。[]

count_pntのコードで提案されているように、本当に電話します testか?

于 2012-05-17T12:41:33.327 に答える
0
count_pnts(_,_,[],_).
count_pnt_word(_,[],_).
count_pnt_keys([],_,_).

問題だったこのように見えるはずです

于 2012-05-17T14:15:17.893 に答える