o
    ˷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i 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 ]R}| }|drq|dr#|| }|dr.|d}q|	d\}}t
d}||d }|| |	 D ]}||krYtd	||tjd
 ||| qJq|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nxDiGraph	readlinesdecode
startswithendswithstripsplitrecompilefindalladd_nodeprintsysstderradd_edge)	fhGlineoldlineheadnametailsnumfindheadtail r"   r/var/www/ideatree/venv/lib/python3.10/site-packages/../../../share/doc/networkx-2.8.6/examples/graph/plot_roget.pyroget_graph   s*   





r$   z0Loaded roget_dat.txt containing 1022 categories.zconnected componentsblack   grayg?)
node_color	node_size
edge_color
linewidthswidth)__doc__r   r   r   matplotlib.pyplotpyplotpltnetworkxr	   r$   r   r   to_undirectedUGnumber_connected_componentsoptionsdraw_circularshowr"   r"   r"   r#   <module>   s(    #