Git Product home page Git Product logo

Comments (11)

mlissner avatar mlissner commented on September 18, 2024

How does this feel to you, @flooie ?

from bankruptcy-parser.

flooie avatar flooie commented on September 18, 2024

This is not doubting this - but could you add some screenshots of examples pages for reference?

from bankruptcy-parser.

flooie avatar flooie commented on September 18, 2024

Also @anthonysalvato3 did you see my last message on the closed PR? Should we just wrap that one up if we have a completed solution?

never mind - see it now

from bankruptcy-parser.

mlissner avatar mlissner commented on September 18, 2024

It feels like if we have test cases on all our PRs, it'd be really easy to know if this kind of logic was working.

from bankruptcy-parser.

anthonysalvato3 avatar anthonysalvato3 commented on September 18, 2024

Here is an example situation (with an unsupported form, but still applicable) where if I want to parse 206A/B, the text shows in the last 300 characters of this page, so it counts.
image

from bankruptcy-parser.

flooie avatar flooie commented on September 18, 2024

Thanks - I found an example in our test files as well. Im looking at a fix - because I think your example code - will leave it vulnerable to another potential bug.

from bankruptcy-parser.

flooie avatar flooie commented on September 18, 2024

@anthonysalvato3

What about this ...

we change drop the page requirement because I came across an example that does not use page 1 of X in reviewing other form names. And just create a nice regex.

This regex pattern finds occurrences of a target form with optional word boundaries or parentheses around it (see some form with wrapped parentheses, while also excluding matches where the words "Official Form" come after the target string. This avoids finding anything but the final form.

    pages = []
    with pdfplumber.open(filepath) as pdf:
        for page in pdf.pages:
            text = page.extract_text()
            if text[-300:].find(form) == -1:
                continue
            if text[-300:].lower().find("page") == -1:
                continue
            pages.append(page.page_number - 1)

    if not pages:
        return False

to

    pages = []
    with pdfplumber.open(filepath) as pdf:
        for page in pdf.pages:
            text = page.extract_text()
            pattern = r"(?<!\w)(?:\(|\b){}(?:\)|\b)(?!\w(.*Official Form))".format(
                re.escape(form)
            )
            if not re.findall(pattern, text[-300:]):
                continue
            pages.append(page.page_number - 1)

    if not pages:
        return False

from bankruptcy-parser.

flooie avatar flooie commented on September 18, 2024

I simplified it a little more in the PR.

Added two tests. Would appreciate your feedback and testing though @anthonysalvato3

from bankruptcy-parser.

flooie avatar flooie commented on September 18, 2024

I didnt think the looping would avoid the issue of one page forms - having a second or third incorrectly labeled page. And I thought the regex pattern that only finds the form if it is the last usage of official form on the page was cleaner.

from bankruptcy-parser.

anthonysalvato3 avatar anthonysalvato3 commented on September 18, 2024

I only have 1 test example of my own but it works on that, and I like the solution because mine wasn't very well thought-out.

from bankruptcy-parser.

flooie avatar flooie commented on September 18, 2024

@anthonysalvato3 do you use the docker image or would a pypi bump be sufficient for your current usage

from bankruptcy-parser.

Related Issues (1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.