def SimplifyNode(node):
 if (not node.getType()):
  return SimplifyNode(node.children[0])
 elif ((node.getType() == QueryParser.CONJUNCTION) and (node.getChildCount() == 1)):
  return SimplifyNode(node.children[0])
 elif ((node.getType() == QueryParser.DISJUNCTION) and (node.getChildCount() == 1)):
  return SimplifyNode(node.children[0])
 elif (((node.getType() == QueryParser.EQ) or (node.getType() == QueryParser.HAS)) and (node.getChildCount() == 1)):
  return SimplifyNode(node.children[0])
 for (i, child) in enumerate(node.children):
  node.setChild(i, SimplifyNode(child))
 return node

def SimplifyNode ( node ) : if ( not node . getType ( ) ) : return SimplifyNode ( node . children [ 0 ] ) elif ( ( node . getType ( ) == QueryParser . CONJUNCTION ) and ( node . getChildCount ( ) == 1 ) ) : return SimplifyNode ( node . children [ 0 ] ) elif ( ( node . getType ( ) == QueryParser . DISJUNCTION ) and ( node . getChildCount ( ) == 1 ) ) : return SimplifyNode ( node . children [ 0 ] ) elif ( ( ( node . getType ( ) == QueryParser . EQ ) or ( node . getType ( ) == QueryParser . HAS ) ) and ( node . getChildCount ( ) == 1 ) ) : return SimplifyNode ( node . children [ 0 ] ) for ( i , child ) in enumerate ( node . children ) : node . setChild ( i , SimplifyNode ( child ) ) return node
simplifies the node removing singleton conjunctions and others .