next up previous
Next: Bibliography Up: Improving the Efficiency of Previous: Acknowledgements

Preparing the Query for the Meta-interpreter

Note that the following preprocessor assumes that the pack of the form a, (b, (c or d or e) or f or g, (h or i or j)) was already transformed to the form a , or([(b, or([c,d,e])), f, (g, or([h,i,j]))]).

      preprocess((A,B),(A,NewB),PrevNode,NodeNr0,LeafNr0,BranchNr,NodeNr1,LeafNr1):- !,
              preprocess(B,NewB,PrevNode,NodeNr0,LeafNr0,BranchNr,NodeNr1,LeafNr1).
      
      preprocess(or(Querys),or(NQuerys,PrevNode,NodeNr0,BranchNr,Length),
                 PrevNode,NodeNr0,LeafNr0,BranchNr,NodeNr1,LeafNr1):- !,
              NodeNr2 is NodeNr0 + 1,
              preprocessbranches(Querys,NQuerys,NodeNr0,NodeNr2,LeafNr0,
                                                 1,NodeNr1,LeafNr1,Length).
      preprocess(A,(A,leaf(PrevNode,BranchNr,LeafNr0)),
                      PrevNode,NodeNr0,LeafNr0,BranchNr,NodeNr0,LeafNr1):-
              LeafNr1 is LeafNr0 + 1.
      
      preprocessbranches([],[],_,NodeNr,LeafNr,BranchNr, 
                                     NodeNr,LeafNr,BranchNr).
      preprocessbranches([Query|Querys],[NewQuery|NewQuerys],PrevNode, 
                         NodeNr0,LeafNr0,BranchNr,NodeNr1,LeafNr1,Length):-
              preprocess(Query,NewQuery,  
                         PrevNode,NodeNr0,LeafNr0,BranchNr,NodeNr2,LeafNr2),
              BranchNr1 is BranchNr + 1,
              preprocessbranches(Querys,NewQuerys,PrevNode,  
                                 NodeNr2,LeafNr2,BranchNr1,NodeNr1,LeafNr1,Length).



Hendrik Blockeel 2002-02-26