-
Notifications
You must be signed in to change notification settings - Fork 797
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Merge request] bug fix on table structure metric #3089
Merged
+32
−8
Merged
Changes from 11 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
7f36697
add bug fix on index matching
tbs17 d34e9ae
Merge branch 'main' into tshen/test-bug-fix-on-metric
tbs17 b168da6
add back a overlooked pass
tbs17 23d55ec
Merge branch 'main' into tshen/test-bug-fix-on-metric
tbs17 4b9aa29
Merge branch 'main' into tshen/test-bug-fix-on-metric
tbs17 d542b1f
Merge remote-tracking branch 'origin/main' into tshen/test-bug-fix-on…
tbs17 32da54c
Merge remote-tracking branch 'origin/tshen/test-bug-fix-on-metric' in…
tbs17 73e348f
Merge remote-tracking branch 'origin/main' into tshen/test-bug-fix-on…
tbs17 cf7723a
edit changelog for the fix
tbs17 c72116d
update the version.py
tbs17 e6211bb
commit the version changes
tbs17 e5dbb11
fix final nits bits
tbs17 6818cc5
edit the bug fix explanation
tbs17 4a1bf2f
change the version name for typo
tbs17 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "0.14.5" # pragma: no cover | ||
__version__ = "0.14.5-dev1" # pragma: no cover |
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 |
---|---|---|
|
@@ -161,6 +161,8 @@ def _try_process_document(self, doc: Path) -> Optional[list]: | |
def _process_document(self, doc: Path) -> list: | ||
"""Should return all metadata and metrics for a single document.""" | ||
|
||
pass | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No blank line between function and first statement. |
||
|
||
|
||
@dataclass | ||
class TableStructureMetricsCalculator(BaseMetricsCalculator): | ||
|
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 |
---|---|---|
|
@@ -50,11 +50,10 @@ def get_table_level_alignment( | |
|
||
@staticmethod | ||
def _zip_to_dataframe(table_data: List[Dict[str, Any]]) -> pd.DataFrame: | ||
df = pd.DataFrame(table_data).pivot( | ||
index="row_index", | ||
columns="col_index", | ||
values="content", | ||
) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same |
||
df = pd.DataFrame(table_data, columns=["row_index", "col_index", "content"]) | ||
df = df.set_index("row_index") | ||
df["col_index"] = df["col_index"].astype(str) | ||
return df | ||
|
||
@staticmethod | ||
|
@@ -100,7 +99,7 @@ def get_element_level_alignment( | |
|
||
# Get row and col index accuracy | ||
ground_truth_td_contents_list = [gtd["content"].lower() for gtd in ground_truth_td] | ||
|
||
used_indices = set() | ||
indices_tuple_pairs = [] | ||
for td_ele in td: | ||
content = td_ele["content"].lower() | ||
|
@@ -113,8 +112,32 @@ def get_element_level_alignment( | |
cutoff=cutoff, | ||
n=1, | ||
) | ||
matched_idx = ground_truth_td_contents_list.index(matches[0]) if matches else -1 | ||
|
||
# BUG FIX: the previous matched_idx will only output the first matched index if | ||
# the match has duplicates in the | ||
# ground_truth_td_contents_list, my current fix will output its correspondence idx | ||
# although once matching is exhausted, it will go back search again the same fashion | ||
# matched_idx = ground_truth_td_contents_list.index(matches[0]) if matches else -1 | ||
matching_indices = [] | ||
if matches != []: | ||
b_indices = [ | ||
i | ||
for i, b_string in enumerate(ground_truth_td_contents_list) | ||
if b_string == matches[0] and i not in used_indices | ||
] | ||
if not b_indices: | ||
# If all indices are used, reset used_indices and use the first index | ||
used_indices.clear() | ||
b_indices = [ | ||
i | ||
for i, b_string in enumerate(ground_truth_td_contents_list) | ||
if b_string == matches[0] and i not in used_indices | ||
] | ||
matching_index = b_indices[0] | ||
matching_indices.append(matching_index) | ||
used_indices.add(matching_index) | ||
else: | ||
matching_indices = [-1] | ||
matched_idx = matching_indices[0] | ||
if matched_idx >= 0: | ||
gt_row_index = ground_truth_td[matched_idx]["row_index"] | ||
gt_col_index = ground_truth_td[matched_idx]["col_index"] | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be a blank line between each of these, match how it is in the rest of the document, title, blank line, Enhancements, blank line, etc.