o
    h                     @   st   d dl mZ d dlZd dlZd dlmZ d dlmZ d dlmZ d dl	m
Z dd	d
Zdd Zedkr8e  dS dS )    )is_right_to_leftN)displacy)Doc)conll)dependency_visualization
   Fc              	   C   s  t j| }|rtt j| | dS dddddddd}td	}g t|t|j	}}}	t
|D ]}
|
|	kr< n|j	|
 }g g g g g f\}}}}}|j}|r\t|j}t|j}|D ]Y}||j ||j ||j ||j |r|jd
kr|||j  q^|r|jd
kr|||j  q^|s|jd
kr||jd  q^|s|jd
kr||jd  q^t|j|||||d}|| q4t| |D ]
}tj|d|d qdS )a`  
    Takes in a conll file and visualizes it by converting the conll file to a Stanza Document object
    and visualizing it with the visualize_doc method.

    Input should be a proper conll file.

    The pipeline for the conll file to be processed in must be provided as well.

    Optionally, the sent_count argument can be tweaked to display a different amount of sentences.

    To display all of the sentences in a conll file, the display_all argument can optionally be set to True.
    BEWARE: setting this argument for a large conll file may result in too many renderings, resulting in a crash.
    Tz#09a3d5whited   zSource Sans Pro      )compactbgcolordistancefontoffset_xarrow_spacingenr      )wordslemmasheadsdepsposdep)styleoptionsN)r   CoNLL	conll2docvizvisualize_docspacyblankr   len	sentencesranger   reversedappendtextlemmadepreluposheadidr   vocabprintr   render)
conll_filepipeline
sent_countdisplay_alldocvisualization_optionsnlpsentences_to_visualizertlnum_sentencesisentencer   r   r   r   tagssentence_wordssent_lenworddocument_resultline rC   p/var/www/html/env_mimamsha/lib/python3.10/site-packages/stanza/utils/visualization/conll_deprel_visualization.pyconll_to_visual
   sL   



rE   c                  C   sr   t  } | jdtddd | jdtddd | jdtd	d
d | jdtddd |  }t|j|j	|j
|j d S )Nz--conll_filez,C:\Users\Alex\stanza\demo\en_test.conllu.txtz8File path of the CoNLL file to visualize dependencies of)typedefaulthelpz
--pipeliner   zDLanguage code of the language pipeline to use (ex: 'en' for English)z--sent_countr   z0Number of sentences to visualize from CoNLL filez--display_allFzcWhether or not to visualize all of the sentences from the file. Overrides sent_count if set to True)argparseArgumentParseradd_argumentstrintbool
parse_argsrE   r1   r2   r3   r4   )parserargsrC   rC   rD   mainC   s   

rR   __main__)r   F)stanza.models.common.constantr   r!   rI   r   spacy.tokensr   stanza.utilsr   stanza.utils.visualizationr   r   rE   rR   __name__rC   rC   rC   rD   <module>   s    
9
