Skip to content

✨Support tables spanning over multiple pages#7

Merged
hf-kklein merged 12 commits intomainfrom
extract_more_tables
Dec 19, 2022
Merged

✨Support tables spanning over multiple pages#7
hf-kklein merged 12 commits intomainfrom
extract_more_tables

Conversation

@hf-kklein
Copy link
Copy Markdown
Contributor

fun fun fun

@hf-kklein hf-kklein self-assigned this Dec 18, 2022
@hf-kklein hf-kklein changed the title ✨Support tables over multiple pages ✨Support tables spanning over multiple pages Dec 18, 2022
next_table_is_requested_table: bool = False
for table_or_paragraph in _get_tables_and_paragaphs(document):
tables: List[Table] = []
tables_and_paragraphs = _get_tables_and_paragaphs(document)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

habe den aus der loop rausgezogen, damit wir weiter unten weiter drüber loopen können (an der stelle wo wir die erste treffende tabelle gefunden haben.

Comment on lines 107 to 118

def convert_docx_table_to_ebd_table(self) -> EbdTable:
def _handle_single_table(
self, table: Table, row_offset: int, rows: List[EbdTableRow], sub_rows: List[EbdTableSubRow]
) -> None:
"""
Converts the raw docx table of an EBD to an EbdTable.
The latter contains the same data but in an easily accessible format that can be used to e.g. plot real graphs.
Handles a single table (out of possible multiple tables for 1 EBD).
The results are written into rows and sub_rows. Those will be modified.
"""
rows: List[EbdTableRow] = []
sub_rows: List[EbdTableSubRow] = []
for table_row, sub_row_position in zip(
self._docx_table.rows[self._row_index_last_header + 1 :],
table.rows[row_offset:],
cycle([_EbdSubRowPosition.UPPER, _EbdSubRowPosition.LOWER]),
):
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

die funktion, die vorher die eine einzige tabelle gehandlet hat, ist jetzt eine private methode, die ihre ergebnisse an zwei übergebene listen fürs rows und subrows anhängt.

Comment on lines -127 to +131
result_code = row_cells[self._column_index_result_code].text.strip()
note = row_cells[self._column_index_note].text.strip()
sub_row = EbdTableSubRow(
check_result=EbdCheckResult(subsequent_step_number=subsequent_step_number, result=boolean_outcome),
result_code=result_code or None,
note=note or None,
result_code=row_cells[self._column_index_result_code].text.strip() or None,
note=row_cells[self._column_index_note].text.strip() or None,
Copy link
Copy Markdown
Contributor Author

@hf-kklein hf-kklein Dec 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pylint hat gemeckert: too-many-locals (also zu viele lokale variablen): hier ist so ein klassiker für: das gefällt zwar dem linter aber die lesbarkeit leidet vllt ein bisschen.

Comment thread src/ebddocx2table/docxtableconverter.py Outdated
offset: int = 0
if table_index == 0:
offset = self._row_index_last_header + 1
self._handle_single_table(table, offset, rows, sub_rows)
Copy link
Copy Markdown
Contributor Author

@hf-kklein hf-kklein Dec 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

die vormals einzige konvertierungsfunktion wird jetzt hier aufgerufen.

Copy link
Copy Markdown
Contributor

@lord-haffi lord-haffi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Insgesamt würde ich sagen lgtm. Bei get_ebd_docx_tables ist mir nur eine Sache aufgefallen:
Meiner Meinung nach, bekommst du ein Problem, wenn nach einer Tabelle direkt ein Paragraph mit Ebd-key (und natürlich darauffolgender eigener Tabelle) kommt. Hab mal kurz die PDF überflogen. An den meisten Stellen scheint ein "unnötiger" Paragraph zu folgen, bei dem es dann nicht auffällt, wenn der geskippt wird. Falls das immer so ist, gerne kommentieren. Falls nicht, müsstest du wahrscheinlich nochmal nachbessern - in dem Fall wäre ein entsprechender Testcase bestimmt auch sinnvoll.

Comment thread src/ebddocx2table/__init__.py Outdated
tables.append(table)
# Now we have to check if the EBD table spans multiple pages and _maybe_ we have to collect more tables.
# The funny thing is: Sometimes the authors create multiple tables split over multiple lines which belong
# together, sometimes they create 1 proper table that spans multiple pages. This we won't notice here.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was wird hier nicht "genoticed"? Der Unterschied zwischen den beiden Fällen, die du präsentiert hast? Oder wird einer der Fälle nicht abgefangen?

Edit: In Anbetracht des Codes hierunter nehme ich an, du meinst, dass zwar beide Fälle berücksichtigt werden, aber der Unterschied nicht im Ergebnis mit gespeichert wird?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

f8d9306 <-- so hfftl klarer

Comment thread src/ebddocx2table/__init__.py Outdated
# sometimes the authors add blank lines before they continue with the next table
continue
else:
break # because if no other table follows, we're done collecting the tables for this EBD key
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tables_and_paragraphs ist ja ein Generator. D.h. ja dass die Liste "on the fly" generiert wird, indem für jede Iteration der Generator die entsprechende Funktion (in diesem Fall _get_tables_and_paragaphs) bis zum nächsten yield ausführt.
Wenn du jetzt den Fall hast, dass ein Paragraph auf die Tabelle folgt, wo etwas drinsteht (z.B. ein neuer Ebd-key), dann führt der zwar den break hier aus, in der outer-loop wird der dann aber geskippt oder überseh ich hier irgendwas?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

die outer loop ist uns egal, sobald wir einmal in der inner loop waren.
91297fe

Comment thread src/ebddocx2table/__init__.py Outdated
Comment on lines 52 to 53
Opens the file specified in docx_file_path and returns the table that relates to the given ebd_key.
Raises an ValueError if the table was not found.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Den Docstring musst du noch anpassen.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread unittests/__init__.py Outdated
@hf-kklein hf-kklein requested a review from lord-haffi December 19, 2022 12:34
Copy link
Copy Markdown
Contributor

@lord-haffi lord-haffi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stimmt, hab ganz vergessen, dass die Methode get_ebd_docx_tables ja nur eine einzelne Ebd-Tabelle auslesen soll. Da war ich wohl 'n bissl verwirrt ^^
Passt so für mich 👍

@hf-kklein hf-kklein merged commit 3c6f710 into main Dec 19, 2022
@hf-kklein hf-kklein deleted the extract_more_tables branch December 19, 2022 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants