o
    h                     @   s   d Z ddlZddlZddlZddlZddlmZmZmZm	Z	m
Z
 edZeddZdZeddZed	ejed
Zeg dZeedddfddZeedddfddZdS )z,
Functions for setting up the environments.
    N)HOME_DIRrequest_fileunzipget_root_from_zipfileset_logging_levelstanzaCORENLP_MODEL_URLzdhttps://huggingface.co/stanfordnlp/corenlp-{model}/resolve/{tag}/stanford-corenlp-models-{model}.jarzNhttp://nlp.stanford.edu/software/stanford-corenlp-{version}-models-{model}.jarzThttps://huggingface.co/stanfordnlp/CoreNLP/resolve/{tag}/stanford-corenlp-latest.zipCORENLP_HOMEstanza_corenlp)	arabicchinesezenglish-extrazenglish-kbpfrenchgerman	hungarianitalianspanishINFOTc              
   C   s  t j|}| r
|stdtd|  d| d|  |   } | tvr2t	|  dt
t d|dkr8|nd| }|j|| |d	}t j|d
| d|  d}	t j|	re|setd|	 d dS z	t||	| W dS  ttfyx     ty }
 ztd|
d}
~
ww )a  
    A automatic way to download the CoreNLP models.

    Args:
        model: the name of the model, can be one of 'arabic', 'chinese', 'english',
            'english-kbp', 'french', 'german', 'hungarian', 'italian', 'spanish'
        version: the version of the model
        dir: the directory to download CoreNLP model into; alternatively can be
            set up with environment variable $CORENLP_HOME
        url: The link to download CoreNLP models.
             It will need {model} and either {version} or {tag} to properly format the URL
        logging_level: logging level to use during installation
        force: Download model anyway, no matter model file exists or not
    z1Both model and model version should be specified.zDownloading z models (version z) into directory z- is currently not supported. Must be one of: .mainv)tagmodelversionzstanford-corenlp-z-models-z.jarzModel file z? already exists. Please download this model to a new directory.NzpDownloading CoreNLP model file failed. Please try manual downloading at: https://stanfordnlp.github.io/CoreNLP/.)ospath
expanduser
ValueErrorloggerinfostriplowerAVAILABLE_MODELSKeyErrorlistformatjoinexistswarnr   KeyboardInterrupt
SystemExit	ExceptionRuntimeError)r   r   dirurllogging_levelproxiesforcer   download_url
model_pathe r4   X/var/www/html/env_mimamsha/lib/python3.10/site-packages/stanza/resources/installation.pydownload_corenlp_models"   sJ   

r6   r   c           	   
   C   s  t j| } t|dd t j| r&tt | dkr&td|  d dS t	d|   t
dt j| d  |d	krA|nd
| }|j||d}zt|t j| d| W n ttfyc     tys } ztd|d}~ww t
d t| d t
d|   tt j| d}t j| |}t |D ]}tt j|||  qt
d t t j| d t| | tkrtd|  d dS dS )a  
    A fully automatic way to install and setting up the CoreNLP library 
    to use the client functionality.

    Args:
        dir: the directory to download CoreNLP model into; alternatively can be
            set up with environment variable $CORENLP_HOME
        url: The link to download CoreNLP models
             Needs a {version} or {tag} parameter to specify the version
        logging_level: logging level to use during installation
    N)r.   verboser   z
Directory z; already exists. Please install CoreNLP to a new directory.z Installing CoreNLP package into zDownload to destination file: zcorenlp.zipr   r   )r   r   zlDownloading CoreNLP zip file failed. Please try manual installation: https://stanfordnlp.github.io/CoreNLP/.z Unzipping downloaded zip file...z,Moving files into the designated folder at: zRemoving downloaded zip file...zFor customized installation location, please set the `CORENLP_HOME` environment variable to the location of the installation. In Unix, this is done with `export CORENLP_HOME=z`.)r   r   r   r   r&   lenlistdirr   r'   r   debugr%   r$   r   r(   r)   r*   r+   r   r   shutilmoveremovermtreeDEFAULT_CORENLP_DIRwarning)	r,   r-   r.   r/   r   r   r3   corenlp_dirnamefr4   r4   r5   install_corenlpX   sP   




rC   )__doc__r   loggingzipfiler;   stanza.resources.commonr   r   r   r   r   	getLoggerr   getenvDEFAULT_CORENLP_MODEL_URLBACKUP_CORENLP_MODEL_URLDEFAULT_CORENLP_URLr   r%   r?   setr!   r6   rC   r4   r4   r4   r5   <module>   s.    
6