TableMatch.get_pred_html is not adding spaces between words in a table
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 230
- Forks
- 41
- PR merge metrics
- No merged PRs in 30d
Description
The get_pred_html in rapid_doc.model.table.rapid_table_self.table_matcher.main.TableMatch does not add spaces between words in a table cell. Below is a fix, hopefully someone will merge it with the code.
def get_pred_html(
self,
pred_structures: List[str],
matched_index: Dict[int, List[int]],
ocr_contents: List[Tuple[str, float]],
):
end_html = []
td_index = 0
for tag in pred_structures:
if "</td>" not in tag:
end_html.append(tag)
continue
if "<td></td>" == tag:
end_html.extend("<td>")
if td_index in matched_index.keys():
b_with = False
if (
"<b>" in ocr_contents[matched_index[td_index][0]]
and len(matched_index[td_index]) > 1
):
b_with = True
end_html.extend("<b>")
contents = [] # Bug fixing line
for i, td_index_index in enumerate(matched_index[td_index]):
content = ocr_contents[td_index_index][0]
if len(matched_index[td_index]) > 1:
if len(content) == 0:
continue
if content[0] == " ":
content = content[1:]
if "<b>" in content:
content = content[3:]
if "</b>" in content:
content = content[:-4]
if len(content) == 0:
continue
if i != len(matched_index[td_index]) - 1 and " " != content[-1]:
# content += " " #用字符级别的框,每个字符都会多空格
content += ""
contents.append(content) # Bug fixing line
# end_html.extend(content) #Bug fixing removed line
end_html.extend(' '.join(contents)) # Bug fixing line
if b_with:
end_html.extend("</b>")
if "<td></td>" == tag:
end_html.append("</td>")
else:
end_html.append(tag)
td_index += 1
# Filter <thead></thead><tbody></tbody> elements
filter_elements = ["<thead>", "</thead>", "<tbody>", "</tbody>"]
end_html = [v for v in end_html if v not in filter_elements]
return "".join(end_html), end_html
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in rapid_doc.model.table.rapid_table_self.table_matcher.main at TableMatch.get_pred_html and trace how matched OCR contents become each table cell's HTML. Verify that multiple OCR fragments in one cell are separated by spaces while empty cells and bold markup remain valid, then compare the returned HTML and end_html values with the reported behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend, data
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100