To illustrate the above title.

Suppose you have a pdf document, which is basically scanned from hardcopy, now there are set of fixed questions to answer from the document itself. For an example a document contains a contract of land, now the set of fixed questions be "who is the seller?" "what is price of the asset? ", document has referred to this answers probably 2-3 times, as a human it's a simple task.

How to automate this?

  • $\begingroup$ It's not so simple task for a machine, a top view of the pipeline would something like this, steps: 1) localize text 2) recognize text 3) run your further processing via Q&A it It's tough one! $\endgroup$ – Aditya Oct 6 '18 at 7:24
  • $\begingroup$ I think you mean an OCR task, for example: github.com/tesseract-ocr $\endgroup$ – John Oct 7 '18 at 10:26
  • $\begingroup$ Hey. @Aditya I understand, it has got some complexity. That's why I am using this forum. Please can you share your inputs at any of the process mentioned? $\endgroup$ – Arijit Das Oct 7 '18 at 11:32
  • $\begingroup$ Can you please elaborate on this? $\endgroup$ – Arijit Das Oct 7 '18 at 11:37
  • $\begingroup$ Follow the instructions of the installation process of tesseract-ocr. Once you installed it, use it to recognize the text from the scanned document. In the recognized text try to searching the relevant terms ("seller", "price"). Next to these terms you should find your answers. $\endgroup$ – John Oct 7 '18 at 12:24

You can use pypdf2 to extract text from pdf.

import PyPDF2

with open('sample.pdf','rb') as pdf_file, open('sample_output.txt', 'w') as text_file:
    read_pdf = PyPDF2.PdfFileReader(pdf_file)
    number_of_pages = read_pdf.getNumPages()
    for page_number in range(number_of_pages):   # use xrange in Py2
        page = read_pdf.getPage(page_number)
        print('Page No - ' + str(1 + read_pdf.getPageNumber(page)))
        page_content = page.extractText()
  • $\begingroup$ I will try this extraction process, after this can you point me at the process to fetch answer from the context? I believe it can be acheived through question answer NLP based model, please do share your views too. Thanks :) $\endgroup$ – Arijit Das Oct 7 '18 at 12:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.