def token_lists(q, phrases=True):
 if q.is_leaf():
  if (phrases or (not isinstance(q, Phrase))):
   return list(q.tokens())
 else:
  ls = []
  for qq in q.children():
   t = token_lists(qq, phrases=phrases)
   if (len(t) == 1):
    t = t[0]
   if t:
    ls.append(t)
  return ls

def token_lists ( q , phrases = True ) : if q . is_leaf ( ) : if ( phrases or ( not isinstance ( q , Phrase ) ) ) : return list ( q . tokens ( ) ) else : ls = [ ] for qq in q . children ( ) : t = token_lists ( qq , phrases = phrases ) if ( len ( t ) == 1 ) : t = t [ 0 ] if t : ls . append ( t ) return ls
returns the terms in the query tree .