
    4 jY                         d dl Z d dlZd dlZd dlZd dlZd dlmc mZ d dl	m
Z
 ej                  Z ej                  de      Zd Zd ZddZd Zy)	    N)	BaseModelcommonc                     d| vryd| vryd| d   v sJ d       d| d   v r-| d   d   dkD  sJ d       | d   d   | d   d   d	z   k  sJ d
       y)a  
    Validate the provided configuration file.
    A ValueError exception will be thrown in case the config file is invalid

    Parameters
    ----------
    config : dictionary
        Configuration for the tablemodel

    Returns
    -------
    bool : True on success
    modelTpreparationmax_tag_lenz<Config error: 'preparation.max_tag_len' parameter is missingseq_lenr   z0Config error: 'model.seq_len' should be positive   zKConfig error: 'model.seq_len' should be up to 'preparation.max_tag_len' + 2 )configs    X/home/agent/.local/lib/python3.12/site-packages/docling_ibm_models/tableformer/common.pyvalidate_configr      s     fF"..FEF.F7O#7OI&*	>=	>*gy)=!-014
 	YX	Y 
     c                     t        | d      5 }t        j                  |      }d d d        t               |S # 1 sw Y   xY w)Nr)openjsonloadr   )config_filenamefdr   s      r   read_configr   /   s?    	os	# r2 FM s	   8Ac                     | ||S | }|dd D ]+  }||vr |rt        dj                  |            |c S ||   }- |d   }||vr|rt        dj                  |            |S ||   S )a  
    Safe get parameter from a nested dictionary.

    Provide a nested dictionary (dictionary of dictionaries) and a list of indices:
    - If the whole index path exists the value pointed by it is returned
    - Otherwise the default value is returned.

    Input:
        input_dict: Data structure of nested dictionaries.
        index_path: List with the indices path to follow inside the input_dict.
        default: Default value to return if the indices path is broken.
        required: If true a ValueError exception will be raised in case the parameter does not exist
    Output:
        The value pointed by the index path or "default".
    NzMissing parameter: {})
ValueErrorformat)
input_dict
index_pathdefaultrequireddi
last_indexs          r   safe_get_parameterr#   9   s      Z/A_ A: !8!?!?!BCCNaD BJ4;;JGHHZ=r   c                 X    t         j                  |    }d|v r|j                  d|      }|S )a&  
    Build the full filename of the prepared data part

    Parameters
    ----------
    prepared_data_part : string
        Part of the prepared data
    dataset_name : string
        Name of the dataset

    Returns
    -------
    string
        The full filename for the prepared file
    z	<POSTFIX>)sPREPARED_DATA_PARTSreplace)prepared_data_partdataset_nametemplates      r   get_prepared_data_filenamer+   ]   s4      $$%78Hh##K>Or   )NF)argparser   loggingostorch'docling_ibm_models.tableformer.settingstableformersettingsr%   7docling_ibm_models.tableformer.models.common.base_modelr   DEBUG	LOG_LEVELget_custom_loggerloggerr   r   r#   r+   r   r   r   <module>r8      sP       	  3 3 MMM				Xy	1@!Hr   