ó
 ,µ[c           @  s  d  Z  d d l m Z d d l Z d d l Z d d l Z d d l j Z d d l	 m
 Z
 d „  Z e d k re ƒ  Z e d ƒ e d e
 j e ƒ e
 j e ƒ f ƒ e j ƒ  Z e e
 j e ƒ d	 ƒ i d
 d 6d d 6d d 6d d 6d d 6Z e
 j e e  e j ƒ  n  d S(   sš  
=====
Roget
=====

Build a directed graph of 1022 categories and
5075 cross-references as defined in the 1879 version of Roget's Thesaurus
contained in the datafile roget_dat.txt. This example is described in
Section 1.2 in Knuth's book (see [1]_ and [2]_).

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).

References
----------

.. [1] Donald E. Knuth,
   "The Stanford GraphBase: A Platform for Combinatorial Computing",
   ACM Press, New York, 1993.
.. [2] http://www-cs-faculty.stanford.edu/~knuth/sgb.html
iÿÿÿÿ(   t   print_functionN(   t   nxc    	      C  s-  t  j d d ƒ }  t j ƒ  } x|  j ƒ  D]ú } | j ƒ  } | j d ƒ rR q+ n  | j d ƒ rn | | } n  | j d ƒ r’ | j d ƒ } q+ n  | j	 d ƒ \ } } t
 j d ƒ } | j | ƒ d } | j | ƒ xL | j	 ƒ  D]> } | | k rt d	 | | d
 t j ƒn  | j | | ƒ qã Wq+ W| S(   s[    Return the thesaurus graph from the roget.dat example in
    the Stanford Graph Base.
    s   roget_dat.txt.gzt   rt   *t    s   \
t   :s   ^\d+i    s   skipping self loopt   file(   t   gzipt   openR   t   DiGrapht	   readlinest   decodet
   startswitht   endswitht   stript   splitt   ret   compilet   findallt   add_nodet   printt   syst   stderrt   add_edge(	   t   fht   Gt   linet   oldlinet   headnamet   tailst   numfindt   headt   tail(    (    s3   share/doc/networkx-2.2/examples/graph/plot_roget.pyt   roget_graph-   s(    t   __main__s0   Loaded roget_dat.txt containing 1022 categories.s"   digraph has %d nodes with %d edgess   connected componentst   blackt
   node_colori   t	   node_sizet   greyt
   line_colori    t
   linewidthsgš™™™™™¹?t   width(   t   __doc__t
   __future__R    R   R   R   t   matplotlib.pyplott   pyplott   pltt   networkxR   R!   t   __name__R   R   t   number_of_nodest   number_of_edgest   to_undirectedt   UGt   number_connected_componentst   optionst   draw_circulart   show(    (    (    s3   share/doc/networkx-2.2/examples/graph/plot_roget.pyt   <module>   s,   	#	
 
