a
    bg	                     @   s^   d Z ddlZddlmZmZmZmZ ddlmZm	Z	m
Z
 eeZg dZG dd deZdS )zUtil that calls bibtexparser.    N)AnyDictListMapping)	BaseModel
ConfigDictmodel_validator)Zannotate	booktitleZeditorZhowpublishedjournalkeywordsZnoteZorganizationZ	publisherschoolZseriestypedoiZissnZisbnc                   @   sx   e Zd ZdZeddZeddeee	dddZ
eeeee	f  d	d
dZdeee	f eeee	f dddZdS )BibtexparserWrappera   Wrapper around bibtexparser.

    To use, you should have the ``bibtexparser`` python package installed.
    https://bibtexparser.readthedocs.io/en/master/

    This wrapper will use bibtexparser to load a collection of references from
    a bibtex file and fetch document summaries.
    Zforbid)extrabefore)mode)valuesreturnc                 C   s,   zddl }W n ty&   tdY n0 |S )z7Validate that the python package exists in environment.r   Nz`Could not import bibtexparser python package. Please install it with `pip install bibtexparser`.)bibtexparserImportError)clsr   r    r   r/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/langchain_community/utilities/bibtex.pyvalidate_environment+   s    
z(BibtexparserWrapper.validate_environment)pathr   c                 C   s@   ddl }t|}||j}W d   n1 s20    Y  |S )z;Load bibtex entries from the bibtex file at the given path.r   N)r   openloadentries)selfr   r   filer   r   r   r   load_bibtex_entries9   s    
*z'BibtexparserWrapper.load_bibtex_entriesF)entry
load_extrar   c                 C   s   | dp| d}d|v r&|d }nd|v r>d|d  }nd}| d| d| d	|| d
| d|d}|rtD ]}| |||< q|dd | D S )z!Get metadata for the given entry.r
   r	   urlr   zhttps://doi.org/NZIDyeartitleauthorabstract)idZpublished_yearr&   publicationZauthorsr(   r$   c                 S   s   i | ]\}}|d ur||qS )Nr   ).0kvr   r   r   
<dictcomp>X       z4BibtexparserWrapper.get_metadata.<locals>.<dictcomp>)getOPTIONAL_FIELDSitems)r   r"   r#   r*   r$   metafieldr   r   r   get_metadataA   s$    
	z BibtexparserWrapper.get_metadataN)F)__name__
__module____qualname____doc__r   Zmodel_configr   classmethodr   r   r   strr   r!   r   boolr5   r   r   r   r   r      s   		 
r   )r9   loggingtypingr   r   r   r   Zpydanticr   r   r   	getLoggerr6   loggerr1   r   r   r   r   r   <module>   s   
