RapidAI / RapidAI/RapidDoc

TableMatch.get_pred_html is not adding spaces between words in a table

Open Beginner friendly
#37 1 comment 0 reactions 0 assignees View on GitHub

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.