
    Ng	                         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j        e          Zg dZ G d de          ZdS )zUtil that calls bibtexparser.    N)AnyDictListMapping)	BaseModel
ConfigDictmodel_validator)annotate	booktitleeditorhowpublishedjournalkeywordsnoteorganization	publisherschoolseriestypedoiissnisbnc            	           e Zd ZdZ ed          Z ed          edede	fd                        Z
d	edeeee	f                  fd
Z	 ddeee	f         dedeee	f         f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.
    forbid)extrabefore)modevaluesreturnc                 L    	 ddl }n# t          $ r t          d          w xY w|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"   s      `/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/utilities/bibtex.pyvalidate_environmentz(BibtexparserWrapper.validate_environment+   sP    	 	 	 	E  	 s    !pathc                     ddl }t          |          5 }|                    |          j        }ddd           n# 1 swxY w Y   |S )z;Load bibtex entries from the bibtex file at the given path.r   N)r"   openloadentries)selfr'   r"   filer+   s        r%   load_bibtex_entriesz'BibtexparserWrapper.load_bibtex_entries9   s    $ZZ 	64"''--5G	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6s   ;??Fentry
load_extrac                    |                     d          p|                     d          }d|v r	|d         }nd|v rd|d          }nd}|                     d          |                     d          |                     d	          ||                     d
          |                     d          |d}|r"t          D ]}|                     |          ||<   d |                                D             S )z!Get metadata for the given entry.r   r   urlr   zhttps://doi.org/NIDyeartitleauthorabstract)idpublished_yearr5   publicationauthorsr7   r2   c                     i | ]
\  }}|||S )N ).0kvs      r%   
<dictcomp>z4BibtexparserWrapper.get_metadata.<locals>.<dictcomp>X   s    ???A1    )getOPTIONAL_FIELDSitems)r,   r/   r0   r:   r2   metafields          r%   get_metadataz BibtexparserWrapper.get_metadataA   s    ii	**Deii.D.DE>>,CCe^^3U5\33CCC))D//#ii//YYw''&yy**		*--
 
  	/( / /#ii..U??????rB   N)F)__name__
__module____qualname____doc__r   model_configr	   classmethodr   r   r&   strr   r.   r   boolrH   r=   rB   r%   r   r      s          :  L _(###
$ 
3 
 
 
 [ $#
 T#s(^0D     <A@ @S#X&@48@	c3h@ @ @ @ @ @rB   r   )rL   loggingtypingr   r   r   r   pydanticr   r   r	   	getLoggerrI   loggerrD   r   r=   rB   r%   <module>rV      s    # #  + + + + + + + + + + + + ; ; ; ; ; ; ; ; ; ;		8	$	$  &;@ ;@ ;@ ;@ ;@) ;@ ;@ ;@ ;@ ;@rB   