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?

  • 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! – Aditya Oct 6 at 7:24
  • I think you mean an OCR task, for example: github.com/tesseract-ocr – John Oct 7 at 10:26
  • 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? – Arijit Das Oct 7 at 11:32
  • Can you please elaborate on this? – Arijit Das Oct 7 at 11:37
  • 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. – John Oct 7 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()
        text_file.write(page_content)
  • 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 :) – Arijit Das Oct 7 at 12:18

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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