Update the OCR app to work based on document versions not documents, document version are the module which hold the document pages instances. Remove old OCR document queue and replace with a single module for OCR processing error entries. Increase compatibility with Django 1.7 and Python 3.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import logging
|
||||
import os
|
||||
@@ -30,14 +30,14 @@ except sh.CommandNotFound:
|
||||
UNPAPER = None
|
||||
|
||||
|
||||
def do_document_ocr(document):
|
||||
def do_document_ocr(document_version):
|
||||
"""
|
||||
Try first to extract text from document pages using the registered
|
||||
parser, if the parser fails or if there is no parser registered for
|
||||
the document mimetype do a visual OCR by calling the corresponding
|
||||
OCR backend
|
||||
"""
|
||||
for document_page in document.pages.all():
|
||||
for document_page in document_version.pages.all():
|
||||
try:
|
||||
# Try to extract text by means of a parser
|
||||
parse_document_page(document_page)
|
||||
@@ -68,10 +68,10 @@ def do_document_ocr(document):
|
||||
|
||||
os.rename(pre_ocr_filepath, pre_ocr_filepath_w_ext)
|
||||
try:
|
||||
ocr_text = ocr_backend.execute(pre_ocr_filepath_w_ext, document.language)
|
||||
ocr_text = ocr_backend.execute(pre_ocr_filepath_w_ext, document_version.document.language)
|
||||
|
||||
document_page.content = ocr_cleanup(document.language, ocr_text)
|
||||
document_page.page_label = _(u'Text from OCR')
|
||||
document_page.content = ocr_cleanup(document_version.document.language, ocr_text)
|
||||
document_page.page_label = _('Text from OCR')
|
||||
document_page.save()
|
||||
finally:
|
||||
fs_cleanup(pre_ocr_filepath_w_ext)
|
||||
@@ -86,7 +86,7 @@ def ocr_cleanup(language, text):
|
||||
cleanup filter
|
||||
"""
|
||||
try:
|
||||
language_backend = load_backend(u'.'.join([u'ocr', u'lang', language, u'LanguageBackend']))()
|
||||
language_backend = load_backend('.'.join(['ocr', 'lang', language, 'LanguageBackend']))()
|
||||
except ImportError:
|
||||
language_backend = None
|
||||
|
||||
@@ -104,9 +104,9 @@ def ocr_cleanup(language, text):
|
||||
result = word
|
||||
if result:
|
||||
output.append(result)
|
||||
output.append(u'\n')
|
||||
output.append('\n')
|
||||
|
||||
return u' '.join(output)
|
||||
return ' '.join(output)
|
||||
|
||||
|
||||
def clean_pages():
|
||||
|
||||
Reference in New Issue
Block a user