MCPcopy Create free account
hub / github.com/google-research/language / process_table

Function process_table

language/fruit/wiki_utils.py:188–219  ·  view source on GitHub ↗

Processes table markup.

(table)

Source from the content-addressed store, hash-verified

186
187
188def process_table(table):
189 """Processes table markup."""
190 # Remove outer delimiters and styling
191 table = RE_TAB_DELIM.sub("", table)
192 table = RE_TAB_STYLE.sub("", table)
193
194 # Detect optional caption
195 caption = RE_TAB_CAPTION.search(table)
196 if caption:
197 caption_string = "[CAPTION] " + caption.group("caption")
198 table = RE_TAB_CAPTION.sub("", table)
199 else:
200 caption_string = ""
201
202 # Clean styling from start of table & split into rows
203 rows = RE_TAB_ROW.split(table)
204
205 # Detect optional header row (could be either of first two rows).
206 header_string = ""
207 row_start = 0
208 for i, row in enumerate(rows[:2]):
209 num_header_cells = len(re.findall("!", row))
210 if num_header_cells > 0:
211 header_string = "[HEADER] " + RE_TAB_COL.sub(" [COL] ", row)
212 row_start = i + 1
213
214 # Generate rows
215 for row in rows[row_start:]:
216 row_string = "[ROW] " + RE_TAB_COL.sub(" [COL] ", row)
217 output_string = " ".join((caption_string, header_string, row_string))
218 output_string = RE_WHITESPACE.sub(" ", output_string)
219 yield output_string
220
221
222def split_article(text):

Callers 1

split_articleFunction · 0.70

Calls 1

splitMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…