def sinica_parse(s):
 tokens = re.split(u'([()| ])', s)
 for i in range(len(tokens)):
  if (tokens[i] == u'('):
   (tokens[(i - 1)], tokens[i]) = (tokens[i], tokens[(i - 1)])
  elif (u':' in tokens[i]):
   fields = tokens[i].split(u':')
   if (len(fields) == 2):
    tokens[i] = fields[1]
   else:
    tokens[i] = ((((u'(' + fields[(-2)]) + u' ') + fields[(-1)]) + u')')
  elif (tokens[i] == u'|'):
   tokens[i] = u''
 treebank_string = u' '.join(tokens)
 return Tree.fromstring(treebank_string, remove_empty_top_bracketing=True)

def sinica_parse ( s ) : tokens = re . split ( u'([()| ])' , s ) for i in range ( len ( tokens ) ) : if ( tokens [ i ] == u'(' ) : ( tokens [ ( i - 1 ) ] , tokens [ i ] ) = ( tokens [ i ] , tokens [ ( i - 1 ) ] ) elif ( u':' in tokens [ i ] ) : fields = tokens [ i ] . split ( u':' ) if ( len ( fields ) == 2 ) : tokens [ i ] = fields [ 1 ] else : tokens [ i ] = ( ( ( ( u'(' + fields [ ( - 2 ) ] ) + u' ' ) + fields [ ( - 1 ) ] ) + u')' ) elif ( tokens [ i ] == u'|' ) : tokens [ i ] = u'' treebank_string = u' ' . join ( tokens ) return Tree . fromstring ( treebank_string , remove_empty_top_bracketing = True )
parse a sinica treebank string and return a tree .