-í
ŦBņ=c      s      d  k  l Z  d f  d     YZ . d Z 0 e d  Z I d   Z U d k Z V d k Z W e i	 e i
    Y d Z Z d   Z d S(	   (   s
   generatorss   Nodec     s>    d  Z  	 
 d   Z  d   Z  d   Z  d   Z RS(   sũ   Represents a bunch of possible next-words for one word-as-a-node
    Doesn't include the word itself; rather, it's associated with the word 
    in a key:value relationship elsewhere
    
    These only live as leafs at the bottom of the tree
    c   s7   
  d |  _  h  |  _  t |  _  h  |  _ d  S(   Ni    (   s   selfs   ns   dicts   Nones   lists   metadata_dt(   s   self(    (    s   rsg.pys   __init__
 s   c   s     |  i d 7_  |  i i |  o1  |  i | c d 7< |  i | i |  n$  d |  i | < | g |  i | <d  S(   Ni   (   s   selfs   ns   dicts   has_keys   childs   metadata_dts   appends   metadata(   s   selfs   childs   metadata(    (    s   rsg.pys	   add_child s   c   sh     g  |  _  d }  xF |  i i   D ]2 \ } }  | | 7}  |  i i | | f  q+ Wd  S(   Ni    (   s   selfs   lists   counters   dicts	   iteritemss   words   freqs   append(   s   selfs   counters   words   freq(    (    s   rsg.pys   finalize s   	 c   sų     | |  i }   |  i o ! |  i   n " d } # t |  i  d } $ x $ | | d j ow % | | d } & | |  i | d j  o ' | } n; ( | |  i | d j o ) | } n + |  i | d SqW W, |  i | d Sd  S(   Ni    i   i   (	   s   rands   selfs   ns   lists   finalizes   item_bottoms   lens   item_tops   item_middle(   s   selfs   rands   item_tops   item_middles   item_bottoms   n(    (    s   rsg.pys   get_word s   	 (   s   __doc__s   __init__s	   add_childs   finalizes   get_word(    (    (    s   rsg.pys   Node s
   		s   #c   s  0 1 2 | o 2 h  } n 3 g  i } t |   D3 ] } | t  q5 ~ } 5 d } 6 | }	 7 x| D7 ]ú \ } }
 8 | d 7} 9 |	 d | g }	 : | } < x t |  d  D< ]p } = | i |	 |  oA > | |  d j o ? t   | |	 | <n A h  | |	 | <n B | |	 | } qš WD | i |	 |  d |
  E | t j o F | }	 n qm WG | | f Sd S(   sE   Will build upon the n_tuple_dict tree, and return a new, updated treei    i   i   N(   s   n_tuple_dicts   appends   _[1]s   xranges   ns   is   SENTENCE_DELIMs   starting_ngrams   counts	   cur_ngrams   token_sources   toks   metadatas   curnodes   has_keys   Nodes	   add_child(   s   ns   token_sources   n_tuple_dicts   counts   starting_ngrams   is   curnodes   _[1]s   toks	   cur_ngrams   metadata(    (    s   rsg.pys
   build_dict0 s.     		
 	 	c   s   I K L |  } M xa t t |   DM ]J } N | i | |  o O | | | } n Q t d | | d  q% WR | Sd S(   s   Traverses a sequence of words, length=n, down the tree.  It returns
    the bottom node, which is a Node node, that contains a probability table.s   word s    in sequence can't be foundN(   s   dicts   workings   xranges   lens   sequences   is   has_keys	   Exception(   s   dicts   sequences   workings   i(    (    s   rsg.pys   get_choosing_nodeI s   	 	Ni  c 
  #s[  Z \ ] g  i  } t | d  D] ] } | t  q! ~ } ^ d } _ d } ` x` | t j oņ a t	 |  |  } b | i t i    } d | t j o e d d d d f g f VnY g g  i  } | i | Dg ] } | | i  qÔ ~ }	 h | |	 f Vi | d | g } j | d 7} k | t j o! l d d d d f g f Vm Pn qU Wd S(   s`   yields word, positionlist.  Uses the dict as the big tree, and n as
    the length of the n-grami   s	   guten Tagi    s   .s   A00 0000N(   s   appends   _[1]s   xranges   ns   is   SENTENCE_DELIMs	   startwiths   newwords	   wordcounts   get_choosing_nodes   dicts   endnodes   get_words   randoms   metadata_dts   metadatas   poss   poslists   MAXWORDS(
   s   dicts   ns	   startwiths   is	   wordcounts   _[1]s   endnodes   newwords   metadatas   poslist(    (    s   rsg.pys   random_sentenceZ s&    		  (   s
   __future__s
   generatorss   Nodes   SENTENCE_DELIMs   Nones
   build_dicts   get_choosing_nodes   randoms   times   seeds   clocks   MAXWORDSs   random_sentence(	   s   Nodes   SENTENCE_DELIMs
   generatorss   get_choosing_nodes   MAXWORDSs
   build_dicts   random_sentences   randoms   time(    (    s   rsg.pys   ? s   +		