forked from Unstructured-IO/unstructured
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Save table prediction in cells format (Unstructured-IO#2892)
This pull request allows to return predictions in raw cell representation from table transformer. It will be later used to save prediction in a cells format for simpler metrics calculation. This PR has to be merged, after Unstructured-IO/unstructured-inference#335
- Loading branch information
Showing
14 changed files
with
764 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import pytest | ||
|
||
from unstructured.metrics.table.table_formats import SimpleTableCell | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("row_nums", "column_nums", "x", "y", "w", "h"), | ||
[ | ||
([3, 2, 1], [6, 7], 6, 1, 2, 3), | ||
([2], [6, 7], 6, 2, 2, 1), | ||
([1, 2, 3], [20], 20, 1, 1, 3), | ||
([5], [5], 5, 5, 1, 1), | ||
], | ||
) | ||
def test_simple_table_cell_parsing_from_table_transformer_when_expected_input( | ||
row_nums, column_nums, x, y, w, h | ||
): | ||
table_transformer_cell = {"row_nums": row_nums, "column_nums": column_nums, "cell text": "text"} | ||
transformed_cell = SimpleTableCell.from_table_transformer_cell(table_transformer_cell) | ||
expected_cell = SimpleTableCell(x=x, y=y, w=w, h=h, content="text") | ||
assert expected_cell == transformed_cell | ||
|
||
|
||
def test_simple_table_cell_parsing_from_table_transformer_when_missing_row_nums(): | ||
cell = {"row_nums": [], "column_nums": [1], "cell text": "text"} | ||
with pytest.raises(ValueError, match='has missing values under "row_nums" key'): | ||
SimpleTableCell.from_table_transformer_cell(cell) | ||
|
||
|
||
def test_simple_table_cell_parsing_from_table_transformer_when_missing_column_nums(): | ||
cell = {"row_nums": [1], "column_nums": [], "cell text": "text"} | ||
with pytest.raises(ValueError, match='has missing values under "column_nums" key'): | ||
SimpleTableCell.from_table_transformer_cell(cell) |
Oops, something went wrong.