rule select_one { % This rule applies exactly once on each connected component of the graph. pattern { X[!select] } % Select an unselected node X % Nodes are totally ordrerd though an internal "__id__" value; % we use this in the two without clauses below to ensure that only one node can be chosen in a given connected component: % the "smallest" one, according to "__id__" order without { X -> Y; Y.__id__ < X.__id__} % such that there is no "smaller" node Y linked as a successor of X without { Y -> X; Y.__id__ < X.__id__} % add such that there is no "smaller" node Y linked as a predecessor of X commands { X.select=yes } } package propagate { rule down { pattern { Y[select]; X[!select]; Y -> X } commands { X.select = yes } } rule up { pattern { Y[!select]; X[select]; Y -> X } commands { Y.select = yes } } } rule remove_unselected { pattern { X[!select]; } commands { del_node X; } } rule clean { pattern { X[select]; } commands { del_feat X.select; } } strat main { Seq ( select_one, Onf (propagate), Onf (remove_unselected), Onf (clean), ) }