Metadata-Version: 2.4
Name: h-rots
Version: 0.1.0
Summary: Deterministic structural inference and semantic serialization of complex HTML tables for RAG
Author: H-ROTS contributors
License-Expression: Apache-2.0
Project-URL: Homepage, https://github.com/hallymgitoslab/H-ROTS
Project-URL: Repository, https://github.com/hallymgitoslab/H-ROTS
Project-URL: Issues, https://github.com/hallymgitoslab/H-ROTS/issues
Project-URL: Research, https://github.com/hallymgitoslab/H-ROTS/tree/paper
Keywords: rag,html,tables,serialization,document-processing
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Text Processing :: Markup :: HTML
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: beautifulsoup4>=4.12
Requires-Dist: lxml>=4.9
Dynamic: license-file

# H-ROTS

**Adaptive Structural Inference and Hierarchical Semantic Path Serialization of Complex Tables for Retrieval-Augmented Generation**

H-ROTS transforms complex HTML tables into semantic records and retrieval-ready text. It resolves hierarchical headers, merged cells, row labels and supported contextual transitions before indexing. No LLM calls, model training, GPU or embedding service are needed.

- **FullPath**: explicit hierarchical semantic paths.
- **Compact**: shared-prefix serialization with reconstruction of supported intermediate records.
- Python API and command-line interface; CPU-only preprocessing.

This `main` branch is the lightweight library. The [paper branch](https://github.com/hallymgitoslab/H-ROTS/tree/paper) contains the research implementation, evaluation datasets, experiments, results and limitations.

## Installation

Python 3.10 or newer. Until the first PyPI release is published, install directly from GitHub:

```bash
python -m pip install "h-rots @ git+https://github.com/hallymgitoslab/H-ROTS.git@main"
```

After publication on PyPI:

```bash
python -m pip install h-rots
```

## Quick start

```python
from h_rots import parse, serialize, decode, convert

html = """
<table>
  <thead>
    <tr><th rowspan="2">Department</th><th colspan="2">2026</th></tr>
    <tr><th>Applications</th><th>Admissions</th></tr>
  </thead>
  <tbody>
    <tr><th>Computer Science</th><td>120</td><td>40</td></tr>
    <tr><th>Mathematics</th><td>90</td><td>30</td></tr>
  </tbody>
</table>
"""

records = parse(html)
print(serialize(records, mode="fullpath"))
compact = serialize(records, mode="compact")
print(compact)
assert decode(compact) == records

# Direct HTML-to-text conversion (also retains supported captions).
text = convert(html, mode="compact")
```

## CLI

```bash
h-rots table.html --mode fullpath
h-rots table.html --mode compact -o table.compact.txt
h-rots table.compact.txt --mode decode -o records.json
h-rots table.html --mode json
python -m h_rots table.html --mode fullpath
```

Use `-` or omit the input path to read UTF-8 from stdin. The CLI's Compact mode serializes intermediate records without a caption so it can be decoded directly.

## API

| Function | Purpose |
| --- | --- |
| `parse(html)` | Parse the first table to ordered semantic records. |
| `serialize(records, mode="fullpath")` | Serialize records as FullPath or Compact. |
| `decode(text)` | Reconstruct supported intermediate records from Compact. |
| `convert(html, mode="fullpath")` | Convert the first table to text, including supported captions. |
| `html_tables_to_markdown_text(html)` | Render multiple top-level tables with the research FullPath convenience function. |

Original research entry points are also exported from `h_rots` for migration. See [API documentation](docs/api.md) and [examples](examples/basic.py).

## Design and scope

HTML → span-aware cell-origin grid → adaptive structural inference and context integration → intermediate records → FullPath / Compact → downstream chunking, indexing and retrieval.

The library does not implement retrieval, answer generation or general table reasoning. Heuristic inference can be ambiguous; Compact reconstructs supported intermediate records, not original HTML or visual layout. Token savings depend on the input. Process untrusted HTML with appropriate input size and resource limits in your application.

## Research and citation

See the [research branch](https://github.com/hallymgitoslab/H-ROTS/tree/paper) for experimental protocols, quantitative results, citations and limitations. This library preserves the research core without algorithm changes. The original core comes from paper commit `39ab0685ccc71f6f08ff0f184ba703dec090eddb` (blob `ef5bbabbd1951d51cc86dc8d30077e597e06ef2b`). A formal bibliographic citation will be added when available.

## Development and release

```bash
python -m pip install -e .
python -m unittest discover -s tests -v
python -m pip install build twine
python -m build
python -m twine check dist/*
```

See [release guide](docs/releasing.md) for PyPI Trusted Publishing. The existing research-only addon script is retained for repository history and is not installed by the library.

## Acknowledgments (지원 및 사사)

본 과제(결과물)는 2026년도 교육부 및 강원특별자치도의 재원으로 강원앵커센터의 지원을 받아 수행된 지역성장 인재양성체계(앵커) 한림대학교 글로컬대학 30의 결과입니다.(2026-ANCHOR-10-009)

## License

Original H-ROTS software and documentation are licensed under [Apache-2.0](LICENSE). Third-party dependencies and datasets retain their respective licenses. Research data is not distributed in this package.
