Provide a table parser for xml tables in USPTO patent documents. The OASIS Open XML Exchange Table Model can be downloaded from: http://oasis-open.org/specs/soextblx.dtd
| 1400 | |
| 1401 | |
| 1402 | class XmlTable: |
| 1403 | """Provide a table parser for xml tables in USPTO patent documents. |
| 1404 | |
| 1405 | The OASIS Open XML Exchange Table Model can be downloaded from: |
| 1406 | http://oasis-open.org/specs/soextblx.dtd |
| 1407 | """ |
| 1408 | |
| 1409 | class MinColInfoType(TypedDict): |
| 1410 | offset: list[int] |
| 1411 | colwidth: list[int] |
| 1412 | |
| 1413 | class ColInfoType(MinColInfoType): |
| 1414 | cell_range: list[int] |
| 1415 | cell_offst: list[int] |
| 1416 | |
| 1417 | def __init__(self, input: str) -> None: |
| 1418 | """Initialize the table parser with the xml content. |
| 1419 | |
| 1420 | Args: |
| 1421 | input: The xml content. |
| 1422 | """ |
| 1423 | self.max_nbr_messages = 2 |
| 1424 | self.nbr_messages = 0 |
| 1425 | self.empty_text = "" |
| 1426 | self._soup = BeautifulSoup(input, features="xml") |
| 1427 | |
| 1428 | def _create_tg_range(self, tgs: list[dict[str, Any]]) -> dict[int, ColInfoType]: |
| 1429 | """Create a unified range along the table groups. |
| 1430 | |
| 1431 | Args: |
| 1432 | tgs: Table group column specifications. |
| 1433 | |
| 1434 | Returns: |
| 1435 | Unified group column specifications. |
| 1436 | """ |
| 1437 | colinfo: dict[int, XmlTable.ColInfoType] = {} |
| 1438 | |
| 1439 | if len(tgs) == 0: |
| 1440 | return colinfo |
| 1441 | |
| 1442 | for itg, tg in enumerate(tgs): |
| 1443 | colinfo[itg] = { |
| 1444 | "offset": [], |
| 1445 | "colwidth": [], |
| 1446 | "cell_range": [], |
| 1447 | "cell_offst": [0], |
| 1448 | } |
| 1449 | offst = 0 |
| 1450 | for info in tg["colinfo"]: |
| 1451 | cw = info["colwidth"] |
| 1452 | cw = re.sub("pt", "", cw, flags=re.I) |
| 1453 | cw = re.sub("mm", "", cw, flags=re.I) |
| 1454 | try: |
| 1455 | cw = int(cw) |
| 1456 | except BaseException: |
| 1457 | cw = float(cw) |
| 1458 | colinfo[itg]["colwidth"].append(cw) |
| 1459 | colinfo[itg]["offset"].append(offst) |