def get_redirects(redirects_filename):
 redirects = {}
 print('Parsing the NT redirect file')
 for (l, line) in enumerate(BZ2File(redirects_filename)):
  split = line.split()
  if (len(split) != 4):
   print(('ignoring malformed line: ' + line))
   continue
  redirects[short_name(split[0])] = short_name(split[2])
  if ((l % 1000000) == 0):
   print(('[%s] line: %08d' % (datetime.now().isoformat(), l)))
 print('Computing the transitive closure of the redirect relation')
 for (l, source) in enumerate(redirects.keys()):
  transitive_target = None
  target = redirects[source]
  seen = set([source])
  while True:
   transitive_target = target
   target = redirects.get(target)
   if ((target is None) or (target in seen)):
    break
   seen.add(target)
  redirects[source] = transitive_target
  if ((l % 1000000) == 0):
   print(('[%s] line: %08d' % (datetime.now().isoformat(), l)))
 return redirects

def get_redirects ( redirects_filename ) : redirects = { } print ( 'Parsing the NT redirect file' ) for ( l , line ) in enumerate ( BZ2File ( redirects_filename ) ) : split = line . split ( ) if ( len ( split ) != 4 ) : print ( ( 'ignoring malformed line: ' + line ) ) continue redirects [ short_name ( split [ 0 ] ) ] = short_name ( split [ 2 ] ) if ( ( l % 1000000 ) == 0 ) : print ( ( '[%s] line: %08d' % ( datetime . now ( ) . isoformat ( ) , l ) ) ) print ( 'Computing the transitive closure of the redirect relation' ) for ( l , source ) in enumerate ( redirects . keys ( ) ) : transitive_target = None target = redirects [ source ] seen = set ( [ source ] ) while True : transitive_target = target target = redirects . get ( target ) if ( ( target is None ) or ( target in seen ) ) : break seen . add ( target ) redirects [ source ] = transitive_target if ( ( l % 1000000 ) == 0 ) : print ( ( '[%s] line: %08d' % ( datetime . now ( ) . isoformat ( ) , l ) ) ) return redirects
return fathead redirect entries for a fathead title .