parameters: (files)
return_statement: return ids, results
docstring: Given a set of paths to sgf files (`files`), extract the PW, PB, & RE
      tags from the file, build a lookup table for {player: id}, and a list of
      (winner, loser) id pairs.
  
      Returns `ids, results`, the id lookup dictionary and the list of pairs as
      tuples.
docstring_summary: Given a set of paths to sgf files (`files`), extract the PW, PB, & RE
      tags from the file, build a lookup table for {player: id}, and a list of
      (winner, loser) id pairs.
docstring_tokens: Given a set of paths to sgf files ( files ) extract the PW PB & RE tags from the file build a lookup table for { player : id } and a list of ( winner loser ) id pairs .
function: def extract_pairwise(files):
      """Given a set of paths to sgf files (`files`), extract the PW, PB, & RE
      tags from the file, build a lookup table for {player: id}, and a list of
      (winner, loser) id pairs.
  
      Returns `ids, results`, the id lookup dictionary and the list of pairs as
      tuples.
      """
  
      # this defaultdict gives each new key referenced a unique increasing int
      # starting from zero.  Since the choix library wants a continuous set of
      # ids, this is works to transform the data into (N, M) pairs.
      ids = defaultdict(lambda: len(ids))
      results = []
      for _file in tqdm(files):
          with open(_file) as f:
              text = f.read()
          pw = re.search(PW_REGEX, text)
          pb = re.search(PB_REGEX, text)
          result = re.search(RESULT_REGEX, text)
          if not (pw and pb and result):
              print("Player or result fields not found: ", _file)
              continue
  
          pw = pw.group(1)
          pb = pb.group(1)
          result = result.group(1).lower()
  
          if pw == pb:
              print("Players were the same: ", _file)
              continue
          if result.startswith('b'):
              results.append((ids[pb], ids[pw]))
          if result.startswith('w'):
              results.append((ids[pw], ids[pb]))
  
      return ids, results
function_tokens: def extract_pairwise ( files ) : # this defaultdict gives each new key referenced a unique increasing int # starting from zero.  Since the choix library wants a continuous set of # ids, this is works to transform the data into (N, M) pairs. ids = defaultdict ( lambda : len ( ids ) ) results = [ ] for _file in tqdm ( files ) : with open ( _file ) as f : text = f . read ( ) pw = re . search ( PW_REGEX , text ) pb = re . search ( PB_REGEX , text ) result = re . search ( RESULT_REGEX , text ) if not ( pw and pb and result ) : print ( "Player or result fields not found: " , _file ) continue pw = pw . group ( 1 ) pb = pb . group ( 1 ) result = result . group ( 1 ) . lower ( ) if pw == pb : print ( "Players were the same: " , _file ) continue if result . startswith ( 'b' ) : results . append ( ( ids [ pb ] , ids [ pw ] ) ) if result . startswith ( 'w' ) : results . append ( ( ids [ pw ] , ids [ pb ] ) ) return ids , results