Context: Developing a program that uses pymupdf to inspect PDF files -> analyze & categorize lines by their position relative to the margin, indentation, position in paragraph, region of the page, density (characters per line), font name, and font size -> TXT format
Currently, the program runs through what's essentially a giant decision tree to collect or skip a line. Not every combination of the factors above are considered. For example, a sparse (density) line at the header (region) of the page is skipped, regardless of its font name and size. I've been reading about design patterns, but I'm not sure what to implement instead of its current structure (which is making debugging + expanding very difficult). I've been considering chain of responsibility, but it doesn't seem like it's a 100% fit. One major drawback is that analysis isn't as simple as yes/no i.e. it's not linear. Suppose the first class acts on line density. However, density alone is never enough to collect/skip a line. So, now it needs to pass the line to a class that acts on the region of the page. Here, only header is skipped. If it's in the footer, it could be the end of a paragraph or it could be a page number. So, now it needs to rely on position in paragraph........... The following class I've added an example of a document I analyzed and a sample of line characteristics + decisions (from 216 combinations).
Should I still move to chain of responsibility, or something else? An alternative I've seen could be a giant decision table (inspired by the picture attached), but it doesn't seem like a popular choice from what I've read (and would also mean up to 1728 combinations if I'm strict).
Link to line characteristic possibilities and snippet of filtering: https://paste.pythondiscord.com/W6SA
Thank you