U
    ª9%eN  ã                   @   s   d Z ddlZddlZddlZddlmZ ddlZdd„ Z	e	ƒ Z
edƒ ee
ƒ e
 ¡ Zee e¡dƒ ddd	dd
dœZejefeŽ e ¡  dS )a¤  
=====
Roget
=====

Build a directed graph of 1022 categories and 5075 cross-references as defined
in the 1879 version of Roget's Thesaurus. This example is described in Section
1.2 of

    Donald E. Knuth, "The Stanford GraphBase: A Platform for Combinatorial
    Computing", ACM Press, New York, 1993.
    http://www-cs-faculty.stanford.edu/~knuth/sgb.html

Note that one of the 5075 cross references is a self loop yet it is included in
the graph built here because the standard networkx `DiGraph` class allows self
loops.  (cf. 400pungency:400 401 403 405).

The data file can be found at:

- https://github.com/networkx/networkx/blob/main/examples/graph/roget_dat.txt.gz
é    Nc            	      C   sÆ   t  dd¡} t ¡ }|  ¡ D ]¤}| ¡ }| d¡r4q| d¡rF|| }| d¡r\| d¡}q| 	d¡\}}t
 d¡}| |¡d }| |¡ | 	¡ D ]*}||kr²td	||tjd
 | ||¡ q”q|S )zZReturn the thesaurus graph from the roget.dat example in
    the Stanford Graph Base.
    zroget_dat.txt.gzÚrÚ*ú z\
ú:z^\d+r   zskipping self loop)Úfile)ÚgzipÚopenÚnxZDiGraphÚ	readlinesÚdecodeÚ
startswithÚendswithÚstripÚsplitÚreÚcompileÚfindallÚadd_nodeÚprintÚsysÚstderrZadd_edge)	ÚfhÚGÚlineZoldlineZheadnameÚtailsZnumfindÚheadÚtail© r   úx/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/../../../share/doc/networkx-3.1/examples/graph/plot_roget.pyÚroget_graph   s(    





r   z0Loaded roget_dat.txt containing 1022 categories.zconnected componentsÚblacké   Úgraygš™™™™™¹?)Z
node_colorZ	node_sizeZ
edge_colorZ
linewidthsÚwidth)Ú__doc__r   r   r   Zmatplotlib.pyplotZpyplotZpltZnetworkxr	   r   r   r   Zto_undirectedZUGZnumber_connected_componentsÚoptionsZdraw_circularÚshowr   r   r   r   Ú<module>   s&   #û