(Message 8) From: HELEN HPS (on ERCC DEC-10) Date: Wednesday, 16-Jan-85 14:08:28-GMT To: ecmi08@2972,Pain@EDXA Via: uk.ac.edinburgh.edxa ; (to uk.ac.edinburgh.emas) 16 Jan 85 14:16:43 gmt Msg ID: <132001-455-533@EDXA> -------- /* classify1 Classify as example, non-example or grey Alan Bundy 7.7.82 */ classify(CObjs,VObjs,CDefn,VRec,ExDiff,yes) :- make_diff(CObjs,VObjs,CDefn,VRec,ExDiff,yes), !. classify(CObjs,VObjs,CDefn,VRec,BestDiff,grey) :- bagof(Diff, make_diff(CObjs,VObjs,CDefn,VRec,Diff,grey), Diffs), Diffs \== [], !, best(Diffs,BestDiff). classify(CObjs,VObjs,CDefn,VRec,NonExDiff,no) :- make_diff(CObjs,VObjs,CDefn,VRec,NonExDiff,no), !. /* Find the difference between example and concept */ make_diff(CObjs,VObjs,CDefn,CRec,Diff,Verdict) :- perm(CObjs,VObjs), pair_off(CDefn,CRec,Diff,Verdict). /*Pair off concept definition and example record to make differences */ pair_off([],[],[],_) :- !. pair_off([],ERec,Diff,Verdict) :- !, maplist(new_defn(Verdict),ERec,Diff). pair_off([define(Args,Name,UpPosn,LowPosn) | CDefn], ERec, [differ(Args,Name,UpPosn,ExPosn,LowPosn,Verdict1) | Diff], Verdict) :- select(record(Args,Name,ExPosn),ERec,Rest), !, compare(UpPosn,ExPosn,LowPosn,Verdict1), acceptable(Verdict,Verdict1), pair_off(CDefn,Rest,Diff,Verdict). pair_off([Define|CDefn], ERec, [Differ|Diff], Verdict) :- !, extra_rec(Verdict,Define,Differ), pair_off(CDefn,ERec,Diff,Verdict). /* invent new bits of definition as necessary */ new_defn(Verdict,record(Args,Name,ExPosn), differ(Args,Name,[],ExPosn,DfPosn,Verdict1)) :- default_posn(Name,DfPosn), compare([],ExPosn,DfPosn,Verdict1), acceptable(Verdict,Verdict1). /* invent extra bits of example record as necessary */ extra_rec(Verdict,define(Args,Name,UpPosn,LowPosn), differ(Args,Name,UpPosn,DfPosn,LowPosn,Verdict1)) :- default_posn(Name,DfPosn), compare(UpPosn,DfPosn,LowPosn,Verdict1), acceptable(Verdict,Verdict1). /* Find position of default predicate on tree */ default_posn(TreeName,Posn) :- default(TreeName,Pred), !, tree(TreeName,_,Tree), node_at(Pred,Tree,Posn). default_posn(TreeName,[]). /* Compare positions in tree to give verdict */ compare(U,E,L,anything(notno(yes))) :- append(L,_,E), !. compare(U,E,L,anything(notno(grey))) :- append(U,_,E), !. compare(U,E,L,anything(no)) :- !. /* What local verdicts indicate what global ones */ acceptable(yes,anything(notno(yes))). acceptable(grey,anything(notno(X))). acceptable(no,anything(X)). /* Find best difference and return it */ best(Diffs,Diff) :- !, maplist(score,Diffs,Scores), writef('Scores are %t \n',[Scores]), lowest(Diffs,Scores,Diff,Score). /* Return difference with lowest score */ lowest([Diff],[Score],Diff,Score) :- !. lowest([Diff1|Diffs], [Score1|Scores], Diff2, Score2) :- lowest(Diffs,Scores,Diff2,Score2), Score2