(t:Table)
return ret
Convert a Table object to a List of Relation.
Convert a Table object to a List of Relation.
Convert a Table object to a List of Relation .
def Table2Relations(t:Table):
  """Convert a Table object to a List of Relation.
  """
  ret = []
  cl = t.coo2cell_id
  # remove duplicates with pair set
  used = set()

  # look right
  for r in range(t.row_n):
    for cFrom in range(t.col_n - 1):
      cTo = cFrom + 1
      loop = True
      while loop and cTo < t.col_n:
        fid, tid = cl[r][cFrom], cl[r][cTo]
        if fid != -1 and tid != -1 and fid != tid:
          if (fid, tid) not in used:
            ret.append(Relation(
              from_text=t.cells[fid].text,
              to_text=t.cells[tid].text,
              direction=DIR_HORIZ,
              from_id=fid,
              to_id=tid,
              no_blanks=cTo - cFrom - 1
            ))
            used.add((fid, tid))
          loop = False
        else:
          if fid != -1 and tid != -1 and fid == tid:
            cFrom = cTo
        cTo += 1
  
  # look down
  for c in range(t.col_n):
    for rFrom in range(t.row_n - 1):
      rTo = rFrom + 1
      loop = True
      while loop and rTo < t.row_n:
        fid, tid = cl[rFrom][c], cl[rTo][c]
        if fid != -1 and tid != -1 and fid != tid:
          if (fid, tid) not in used: 
            ret.append(Relation(
              from_text=t.cells[fid].text,
              to_text=t.cells[tid].text,
              direction=DIR_VERT,
              from_id=fid,
              to_id=tid,
              no_blanks=rTo - rFrom - 1
            ))
            used.add((fid, tid))
          loop = False
        else:
          if fid != -1 and tid != -1 and fid == tid:
            rFrom = rTo
        rTo += 1

  return ret
def Table2Relations ( t : Table ) : ret = [ ] cl = t . coo2cell_id # remove duplicates with pair set used = set ( ) # look right for r in range ( t . row_n ) : for cFrom in range ( t . col_n - 1 ) : cTo = cFrom + 1 loop = True while loop and cTo < t . col_n : fid , tid = cl [ r ] [ cFrom ] , cl [ r ] [ cTo ] if fid != - 1 and tid != - 1 and fid != tid : if ( fid , tid ) not in used : ret . append ( Relation ( from_text = t . cells [ fid ] . text , to_text = t . cells [ tid ] . text , direction = DIR_HORIZ , from_id = fid , to_id = tid , no_blanks = cTo - cFrom - 1 ) ) used . add ( ( fid , tid ) ) loop = False else : if fid != - 1 and tid != - 1 and fid == tid : cFrom = cTo cTo += 1 # look down for c in range ( t . col_n ) : for rFrom in range ( t . row_n - 1 ) : rTo = rFrom + 1 loop = True while loop and rTo < t . row_n : fid , tid = cl [ rFrom ] [ c ] , cl [ rTo ] [ c ] if fid != - 1 and tid != - 1 and fid != tid : if ( fid , tid ) not in used : ret . append ( Relation ( from_text = t . cells [ fid ] . text , to_text = t . cells [ tid ] . text , direction = DIR_VERT , from_id = fid , to_id = tid , no_blanks = rTo - rFrom - 1 ) ) used . add ( ( fid , tid ) ) loop = False else : if fid != - 1 and tid != - 1 and fid == tid : rFrom = rTo rTo += 1 return ret