Beispiel #1
0
def load_app_features_context(config: AppConfig,
                              download_manager: DownloadManager):
    return AppFeaturesContext(country_lookup=load_lookup_from_config(
        config.get('lookup', {}).get('country'),
        download_manager=download_manager),
                              first_name_lookup=load_lookup_from_config(
                                  config.get('lookup', {}).get('first_name'),
                                  download_manager=download_manager),
                              last_name_lookup=load_lookup_from_config(
                                  config.get('lookup', {}).get('last_name'),
                                  download_manager=download_manager))
Beispiel #2
0
def get_ocr_model_for_app_config(
        app_config: AppConfig,
        enabled: bool = True) -> Optional[OpticalCharacterRecognitionModel]:
    ocr_model_config = app_config.get('ocr_models', {}).get('default')
    if enabled and ocr_model_config:
        return get_lazy_ocr_model_for_config(ocr_model_config)
    return None
Beispiel #3
0
def get_cv_model_for_app_config(
        app_config: AppConfig,
        enabled: bool = True) -> Optional[ComputerVisionModel]:
    cv_model_config = app_config.get('cv_models', {}).get('default')
    if enabled and cv_model_config:
        return get_lazy_cv_model_for_config(cv_model_config)
    return None
Beispiel #4
0
 def __init__(self, config: AppConfig):
     self.config = config
     self.download_manager = DownloadManager(
         download_dir=get_download_dir(config))
     self.pdfalto_wrapper = PdfAltoWrapper(
         self.download_manager.download_if_url(config['pdfalto']['path']))
     self.pdfalto_wrapper.ensure_executable()
     self.app_context = AppContext(
         app_config=config,
         download_manager=self.download_manager,
         lazy_wapiti_binary_wrapper=LazyWapitiBinaryWrapper(
             install_url=config.get('wapiti', {}).get('install_source'),
             download_manager=self.download_manager))
     self.fulltext_processor_config = FullTextProcessorConfig.from_app_config(
         app_config=config)
     self.fulltext_models = load_models(
         config,
         app_context=self.app_context,
         fulltext_processor_config=self.fulltext_processor_config)
     if config.get('preload_on_startup'):
         self.fulltext_models.preload()
     self.app_features_context = load_app_features_context(
         config, download_manager=self.download_manager)
     tei_to_jats_config = config.get('xslt', {}).get('tei_to_jats', {})
     self.tei_to_jats_xslt_transformer = XsltTransformerWrapper.from_template_file(
         TEI_TO_JATS_XSLT_FILE,
         xslt_template_parameters=tei_to_jats_config.get('parameters', {}))
     self.doc_to_pdf_enabled = config.get('doc_to_pdf',
                                          {}).get('enabled', True)
     self.doc_to_pdf_convert_parameters = config.get('doc_to_pdf',
                                                     {}).get('convert', {})
     self.doc_converter_wrapper = DocConverterWrapper(
         **config.get('doc_to_pdf', {}).get('listener', {}))
Beispiel #5
0
 def from_app_config(app_config: AppConfig) -> 'FullTextProcessorConfig':
     return FullTextProcessorConfig()._replace(
         **app_config.get('processors', {}).get('fulltext', {}))