看板 Programming 關於我們 聯絡資訊
※ 引述《ntouckcm (知足常樂)》之銘言: : 由於第一次接觸PROLOG,所以語法不熟,不知道怎麼除錯.. : 可以請大大幫我看一下嗎?謝謝~ : % Candidate Elimination Algorithm : run_candidate_elim :- candidate_elim([[_,_,_]], [], : [[small, medium, large], [red, blue, green], [ball, brick, cube]]). : % Candidate_elim implements a top level read-process loop : % It prints out the current G set : % the S set : % : % and calls process to process the input. : candidate_elim([G],[S],_) :- : covers(G,S),covers(S,G), : write("target concept is "), write(G),nl. : candidate_elim(G, S, Types) :- : write("G= "), write(G),nl, : write("S= "), write(S),nl, : write("Enter Instance "), : read(Instance), : process(Instance, G, S, Updated_G, Updated_S, Types), : candidate_elim(Updated_G, Updated_S, Types). : % Process takes the instance, : % a set of concepts, G and : % and a set of concepts, S : % it implements a step of the candidate elimination algorithm. : process(negative(Instance), G, S, Updated_G, Updated_S, Types) :- : delete(X, S, covers(X, Instance), Updated_S), : specialize_set(G,Spec_G, Instance, Types), : delete(X, Spec_G, (member(Y, Spec_G), more_general(Y, X)), Pruned_G), : delete(X, Pruned_G, (member(Y, Updated_S), not(covers(X, Y))), Updated_G). : process(positive(Instance), G, [], Updated_G, [Instance],_):- : % Initialize S : delete(X, G, not(covers(X, Instance)), Updated_G). : process(positive(Instance), G, S, Updated_G, Updated_S,_) :- : delete(X, G, not(covers(X, Instance)), Updated_G), : generalize_set(S,Gen_S, Instance), : delete(X, Gen_S, (member(Y, Gen_S), more_general(X, Y)), Pruned_S), : delete(X, Pruned_S, not((member(Y, Updated_G), covers(Y, X))), Updated_S). : process(Input, G, P, G, P,_):- : Input \= positive(_), : Input \= negative(_), : write("Enter either positive(Instance) or negative(Instance) "), nl : % The following predicate definitions are duplicated in either : % the general to specific searches or the specific to genearal searches. : % : specialize_set([], [], _, _). : ERROR: c:/candidate1.pl:54:0: Syntax error: Operator expected : specialize_set([Hypothesis|Rest],Updated_H,Instance, Types):- : covers(Hypothesis, Instance), : (bagof(Hypothesis, specialize(Hypothesis, Instance, Types), Updated_head); Updated_head = []), : specialize_set(Rest, Updated_rest, Instance, Types), : append(Updated_head, Updated_rest, Updated_H). : specialize_set([Hypothesis|Rest],[Hypothesis|Updated_rest],Instance, Types):- : not (covers(Hypothesis, Instance)), : specialize_set(Rest,Updated_rest, Instance, Types). : specialize([Prop|_], [Inst_prop|_], [Instance_values|_]):- : var(Prop), : member(Prop, Instance_values), : Prop \= Inst_prop. : specialize([_|Tail], [_|Inst_tail], [_|Types]):- : specialize(Tail, Inst_tail, Types). : % : generalize_set([], [], _). : generalize_set([Hypothesis|Rest],Updated_H,Instance):- : not(covers(Hypothesis, Instance)), : (bagof(X, generalize(Hypothesis, Instance, X), Updated_H); Updated_head = []), : generalize_set(Rest,Updated_rest, Instance), : append(Updated_head, Updated_rest, Updated_H). : generalize_set([Hypothesis|Rest],[Hypothesis|Updated_rest],Instance):- : covers(Hypothesis, Instance), : generalize_set(Rest,Updated_rest, Instance). : % : generalize([],[],[]). : generalize([Feature|Rest], [Inst_prop|Rest_inst], [Feature|Rest_gen]) :- : not(Feature \= Inst_prop), 請問一下,compiler成功了,但是為什麼在程式中輸入 | ?- run_candidate_elim. 會出現 [71,61,32][[_17,_19,_21]] [83,61,32][] [69,110,116,101,114,32,73,110,115,116,97,110,99,101,32] 而不是出現正確的畫面 ?- run_candidate_elim. "G= "[[_0,_1,_2]] "S= "[] "Enter Instance "positive([small, red, ball]). -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.121.219.142