(src:dict, trg:dict, src_chunks, trg_chunks, fid)
return sid2tid
Match chunks to latex cells w.r.t. the contents.
Match chunks to latex cells w.r.t. the contents.
Match chunks to latex cells w . r . t . the contents .
def match(src:dict, trg:dict, src_chunks, trg_chunks, fid):
  """Match chunks to latex cells w.r.t. the contents."""
  sid2tid = {}
  print("--------%s---------------------------" % fid)
  for stxt, sids in src.items():
    if stxt in trg:
      tids = trg[stxt]
      if len(sids) == 1 and len(tids) == 1: sid2tid[sids[0]] = tids[0]
      elif len(sids) == len(tids):
        schunks = [(sid, src_chunks[sid]) for sid in sids]
        tchunks = [(tid, trg_chunks[tid]) for tid in tids]
        sorted_sc = sorted(schunks, key=lambda x: (-x[1].y1, x[1].x1))
        sorted_tc = sorted(tchunks, key=lambda x: (x[1].x1, x[1].y1))
        for (sid, _), (tid, _) in zip(sorted_sc, sorted_tc):
          sid2tid[sid] = tid
      else: 
        print("[W] length of sids and tids doesn't match")
    else: 
      print("[W] no match for text %s" % stxt)
  print("-----------------------------------------------------------")
  return sid2tid
def match ( src : dict , trg : dict , src_chunks , trg_chunks , fid ) : sid2tid = { } print ( "--------%s---------------------------" % fid ) for stxt , sids in src . items ( ) : if stxt in trg : tids = trg [ stxt ] if len ( sids ) == 1 and len ( tids ) == 1 : sid2tid [ sids [ 0 ] ] = tids [ 0 ] elif len ( sids ) == len ( tids ) : schunks = [ ( sid , src_chunks [ sid ] ) for sid in sids ] tchunks = [ ( tid , trg_chunks [ tid ] ) for tid in tids ] sorted_sc = sorted ( schunks , key = lambda x : ( - x [ 1 ] . y1 , x [ 1 ] . x1 ) ) sorted_tc = sorted ( tchunks , key = lambda x : ( x [ 1 ] . x1 , x [ 1 ] . y1 ) ) for ( sid , _ ) , ( tid , _ ) in zip ( sorted_sc , sorted_tc ) : sid2tid [ sid ] = tid else : print ( "[W] length of sids and tids doesn't match" ) else : print ( "[W] no match for text %s" % stxt ) print ( "-----------------------------------------------------------" ) return sid2tid