Exemple #1
0
def ocr_cleanup(language, text):
    """
    Cleanup the OCR's output passing it thru the selected language's
    cleanup filter
    """
    try:
        language_backend = load_backend('.'.join(
            ['ocr', 'lang', language, 'LanguageBackend']))()
    except ImportError:
        language_backend = None

    output = []
    for line in text.splitlines():
        line = line.strip()
        for word in line.split():
            if language_backend:
                try:
                    result = language_backend.check_word(word)
                except Exception as exception:
                    logger.error(exception)
                    raise Exception('ocr_cleanup() %s' % unicode(exception))
            else:
                result = word
            if result:
                output.append(result)
        output.append('\n')

    return ' '.join(output)
Exemple #2
0
def ocr_cleanup(language, text):
    """
    Cleanup the OCR's output passing it thru the selected language's
    cleanup filter
    """
    try:
        language_backend = load_backend('.'.join(['ocr', 'lang', language, 'LanguageBackend']))()
    except ImportError:
        language_backend = None

    output = []
    for line in text.splitlines():
        line = line.strip()
        for word in line.split():
            if language_backend:
                try:
                    result = language_backend.check_word(word)
                except Exception as exception:
                    logger.error(exception)
                    raise Exception('ocr_cleanup() %s' % unicode(exception))
            else:
                result = word
            if result:
                output.append(result)
        output.append('\n')

    return ' '.join(output)
Exemple #3
0
    def __init__(self, name, app_name=None):
        self.name = name
        self.endpoints = []
        try:
            api_urls = load_backend('{0}.urls.api_urls'.format(app_name or name))
        except Exception:
            if settings.DEBUG:
                raise
            else:
                # Ignore import time errors
                pass
        else:
            self.register_urls(api_urls)

        self.__class__._registry[name] = self
Exemple #4
0
    def __init__(self, name, app_name=None):
        self.name = name
        self.endpoints = []
        try:
            api_urls = load_backend('{0}.urls.api_urls'.format(app_name
                                                               or name))
        except Exception:
            if settings.DEBUG:
                raise
            else:
                # Ignore import time errors
                pass
        else:
            self.register_urls(api_urls)

        self.__class__._registry[name] = self
Exemple #5
0
from __future__ import unicode_literals

import logging

from common.utils import load_backend

from .exceptions import OfficeBackendError
from .office_converter import OfficeConverter
from .settings import GRAPHICS_BACKEND

logger = logging.getLogger(__name__)

logger.debug('initializing office backend')
try:
    office_converter = OfficeConverter()
except OfficeBackendError as exception:
    logger.error('error initializing office backend; %s', exception)
    office_converter = None
else:
    logger.debug('office_backend initialized')


backend = load_backend(GRAPHICS_BACKEND)()
Exemple #6
0
from __future__ import absolute_import

from common.utils import load_backend

from .conf.settings import BACKEND, LANGUAGE

try:
    language_backend = load_backend(u'.'.join(
        [u'ocr', u'lang', LANGUAGE, u'LanguageBackend']))()
except ImportError:
    language_backend = None

ocr_backend = load_backend(BACKEND)()
Exemple #7
0
from common.utils import load_backend

from .settings import STORAGE_BACKEND

storage_backend = load_backend(STORAGE_BACKEND)()
Exemple #8
0
from common.utils import load_backend

from .settings import BACKEND

ocr_backend = load_backend(BACKEND)()
Exemple #9
0
from common.utils import load_backend

from .settings import SHARED_STORAGE

shared_storage_backend = load_backend(SHARED_STORAGE)()
Exemple #10
0
from __future__ import absolute_import

from common.utils import load_backend

from .conf.settings import BACKEND, LANGUAGE

try:
    language_backend = load_backend(u'.'.join([u'ocr', u'lang', LANGUAGE, u'LanguageBackend']))()
except ImportError:
    language_backend = None

ocr_backend = load_backend(BACKEND)()
    def get(cls, full_name):
        result = cls.registry[full_name]
        if not hasattr(result, 'serializer'):
            result.serializer = load_backend(result.serializer_string)

        return result
Exemple #12
0
    def get(cls, full_name):
        result = cls.registry[full_name]
        if not hasattr(result, 'serializer'):
            result.serializer = load_backend(result.serializer_string)

        return result