
    7|h	                     ~    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y)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y)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                 @    	 ddl }|S # t        $ r t        d      w xY w)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      c/var/www/html/test/engine/venv/lib/python3.12/site-packages/langchain_community/utilities/bibtex.pyvalidate_environmentz(BibtexparserWrapper.validate_environment+   s5    	   	E 	s    pathc                     ddl }t        |      5 }|j                  |      j                  }ddd       |S # 1 sw Y   S xY w)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>    $Z 	64"''-55G	6	6s	   6A entry
load_extrac                    |j                  d      xs |j                  d      }d|v r|d   }nd|v r	d|d    }nd}|j                  d      |j                  d      |j                  d	      ||j                  d
      |j                  d      |d}|rt        D ]  }|j                  |      ||<    |j                         D ci c]  \  }}|	|| c}}S c c}}w )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   )getOPTIONAL_FIELDSitems)	r,   r/   r0   r:   r2   metafieldkvs	            r%   get_metadataz BibtexparserWrapper.get_metadataA   s     ii	*Deii.DE>,Ce^$U5\N3CC))D/#ii/YYw'&yy*		*-
 ( /#ii.U/!%?A1???s   
CCN)F)__name__
__module____qualname____doc__r   model_configr	   classmethodr   r   r&   strr   r.   r   boolrC        r%   r   r      s     L (#
$ 
3 
  $
 T#s(^0D  <A@S#X&@48@	c3h@rM   r   )rG   loggingtypingr   r   r   r   pydanticr   r   r	   	getLoggerrD   loggerr=   r   rL   rM   r%   <module>rS      s>    #  + + ; ;			8	$&;@) ;@rM   