
    dh	                     ~    S r SSKrSSKJrJrJrJr  SSKJrJ	r	J
r
  \R                  " \5      r/ SQr " S S\5      rg)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            	           \ rS rSrSr\" SS9r\" SS9\S\	S\
4S	 j5       5       rS
\S\\	\\
4      4S jr SS\\\
4   S\S\	\\
4   4S jjrSrg)BibtexparserWrapper   a  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                 B     SSK nU$ ! [         a    [        S5      ef = f)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/shao/venv/lib/python3.13/site-packages/langchain_community/utilities/bibtex.pyvalidate_environment(BibtexparserWrapper.validate_environment+   s5    	   	E 	s    pathc                     SSK n[        U5       nUR                  U5      R                  nSSS5        U$ ! , (       d  f       W$ = f)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_entries'BibtexparserWrapper.load_bibtex_entries9   s;    $Z4"''-55G  Zs	   6
Aentry
load_extrac                    UR                  S5      =(       d    UR                  S5      nSU;   a  US   nOSU;   a	  SUS    3nOSnUR                  S5      UR                  S5      UR                  S	5      UUR                  S
5      UR                  S5      US.nU(       a   [         H  nUR                  U5      XV'   M     UR                  5        VVs0 sH  u  pxUc  M
  Xx_M     snn$ s  snnf )z!Get metadata for the given entry.r   r   urlr   zhttps://doi.org/NIDyeartitleauthorabstract)idpublished_yearr8   publicationauthorsr:   r5   )getOPTIONAL_FIELDSitems)	r.   r2   r3   r=   r5   metafieldkvs	            r&   get_metadata BibtexparserWrapper.get_metadataA   s     ii	*Deii.DE>,Ce^$U5\N3CC))D/#ii/YYw'&yy*		*-
 (#ii. )!%????s   C,"C, N)F)__name__
__module____qualname____firstlineno____doc__r   model_configr	   classmethodr   r   r'   strr   r0   r   boolrF   __static_attributes__rH       r&   r   r      s     L (#
$ 
3 
  $
 T#s(^0D  <A@S#X&@48@	c3h@ @rS   r   )rM   loggingtypingr   r   r   r   pydanticr   r   r	   	getLoggerrI   loggerr@   r   rH   rS   r&   <module>rY      s<    #  + + ; ;			8	$&;@) ;@rS   