Often it will not be possible to generate an alternative expression by a local change as we suggested. We propose that the monitor first tries to change things as local as possible. If all possibilities are tried, the notion `locality' is redefined by going up one level. This process repeats itself until no more alternative solutions are possible. Thus, given a marked derivation tree the monitored generation first tries to find alternatives for the marked parts of the tree. If no further possibilities exist, all markers in the trees are inherited by their mother nodes. Again the monitored generation tries to find alternatives, after which the markers are pushed upwards yet another level, etc.
The following definition of the predicate mark_l_g(Tree, Set, Guide) will (procedurally speaking) first construct the `guide' Guide given a derivation tree Tree and a set of derivation trees Set; upon backtracking it will push the markers in the tree one level upward at the time.
mark_l_g(Tree,Set,Guide):- mark(Tree,Set), l_g(Tree,Guide). l_g(Tree,Tree). l_g(Tree,Guide):- one_up(Tree,Tree2), l_g(Tree2,Guide). one_up(t(L,Ds,n),t(L,Ds,y)):- member(t(_,_,y),Ds),!. one_up(t(L,Ds,n),t(L,Ds2,n)):- one_up_ds(Ds,Ds2). one_up_ds(,). one_up_ds([H|T],[H2|T2]):- one_up(H,H2), one_up_ds(T,T2).
monitored_generation(LF,Sign):- generate(sign(LF,Str,Syn,D)), !, % stick to one.. monitor(sign(LF,Str,Syn,D),Sign). monitor(sign(LF,Str1,Syn1,D1), sign(LF,Str,Syn,D)):- find_all_parse(Str1,TreeSet), ( TreeSet = [_] -> Str1 = Str, Syn1 = Syn, D1 = D ; mark_l_g(D1,TreeSet,Guide), mgen(sign(LF,Str,Syn,D),Guide), unambiguous(Str) ). find_all_parse(Str1,TreeSet) :- setof(D,LF^S^parse(sign(LF,Str1,S,D), TreeSet).