ó
ł`]c           @` s;  d  d l  m Z d  d l  m Z 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 yD d  d l m Z d  d	 l m Z d  d
 l m Z d  d l m Z Wn e k
 rĻ n Xd  d l m Z m Z m Z d e f d     YZ d e f d     YZ d e f d     YZ d   Z d S(   i    (   t   absolute_import(   t   division(   t   print_functionN(   t   remove(   t   deepcopy(   t
   itemgetter(   t   array(   t   sparse(   t   load_svmlight_file(   t   svm(   t   ParserIt   DependencyGrapht   DependencyEvaluatort   Configurationc           B` s5   e  Z d  Z d   Z d   Z e d  Z d   Z RS(   s  
    Class for holding configuration which is the partial analysis of the input sentence.
    The transition based parser aims at finding set of operators that transfer the initial
    configuration to the terminal configuration.

    The configuration includes:
        - Stack: for storing partially proceeded words
        - Buffer: for storing remaining input words
        - Set of arcs: for storing partially built dependency tree

    This class also provides a method to represent a configuration as list of features.
    c         C` sX   d g |  _  t t d t | j    |  _ g  |  _ | j |  _ t |  j  |  _ d S(   s¶   
        :param dep_graph: the representation of an input in the form of dependency graph.
        :type dep_graph: DependencyGraph where the dependencies are not specified.
        i    i   N(	   t   stackt   listt   ranget   lent   nodest   buffert   arcst   _tokenst   _max_address(   t   selft	   dep_graph(    (    s:   lib/python2.7/site-packages/nltk/parse/transitionparser.pyt   __init__,   s
    !	c         C` s3   d t  |  j  d t  |  j  d t  |  j  S(   Ns   Stack : s     Buffer : s
      Arcs : (   t   strR   R   R   (   R   (    (    s:   lib/python2.7/site-packages/nltk/parse/transitionparser.pyt   __str__8   s    c         C` sC   | d k r t S| d k r  t S| t k r? | d k r? t Sn  t S(   ss   
        Check whether a feature is informative
        The flag control whether "_" is informative or not
        t    t   _N(   t   Nonet   Falset   True(   R   t   featt   flag(    (    s:   lib/python2.7/site-packages/nltk/parse/transitionparser.pyt   _check_informativeB   s    c         C` sØ  g  } t  |  j  d k rn|  j t  |  j  d } |  j | } |  j | d t  rp | j d | d  n  d | k r§ |  j | d  r§ | j d | d  n  |  j | d  rŅ | j d | d  n  d	 | k r)|  j | d	  r)| d	 j d
  } x" | D] } | j d |  qWn  t  |  j  d k r|  j t  |  j  d } |  j | } |  j | d  r| j d | d  qn  d } d } d }	 d }
 xw |  j D]l \ } } } | | k rµ| | k r÷| | k r÷| } | }
 n  | | k  r!| | k  r!| } | }	 q!qµqµW|  j |	  rH| j d |	  n  |  j |
  rn| j d |
  qnn  t  |  j  d k r¤|  j d } |  j | } |  j | d t  rĖ| j d | d  n  d | k r|  j | d  r| j d | d  n  |  j | d  r-| j d | d  n  d	 | k r|  j | d	  r| d	 j d
  } x" | D] } | j d |  qfWn  t  |  j  d k r|  j d } |  j | } |  j | d t  rį| j d | d  n  |  j | d  r| j d | d  qn  t  |  j  d k rl|  j d } |  j | } |  j | d  rl| j d | d  qln  t  |  j  d k rÉ|  j d } |  j | } |  j | d  rÉ| j d | d  qÉn  d } d } d }	 d }
 xw |  j D]l \ } } } | | k rė| | k r-| | k r-| } | }
 n  | | k  rW| | k  rW| } | }	 qWqėqėW|  j |	  r~| j d |	  n  |  j |
  r¤| j d |
  q¤n  | S(   s/  
        Extract the set of features for the current configuration. Implement standard features as describe in
        Table 3.2 (page 31) in Dependency Parsing book by Sandra Kubler, Ryan McDonal, Joakim Nivre.
        Please note that these features are very basic.
        :return: list(str)
        i    i   t   wordt   STK_0_FORM_t   lemmat   STK_0_LEMMA_t   tagt
   STK_0_POS_t   featst   |t   STK_0_FEATS_i   t
   STK_1_POS_i@B i’’’’R   t   STK_0_LDEP_t   STK_0_RDEP_t   BUF_0_FORM_t   BUF_0_LEMMA_t
   BUF_0_POS_t   BUF_0_FEATS_t   BUF_1_FORM_t
   BUF_1_POS_t
   BUF_2_POS_i   t
   BUF_3_POS_t   BUF_0_LDEP_t   BUF_0_RDEP_(	   R   R   R   R#   R    t   appendt   splitR   R   (   R   t   resultt
   stack_idx0t   tokenR*   R!   t
   stack_idx1t	   left_mostt
   right_mostt   dep_left_mostt   dep_right_mostt   wit   rt   wjt   buffer_idx0t   buffer_idx1t   buffer_idx2t   buffer_idx3(    (    s:   lib/python2.7/site-packages/nltk/parse/transitionparser.pyt   extract_featuresP   s¤    		(   t   __name__t
   __module__t   __doc__R   R   R   R#   RK   (    (    (    s:   lib/python2.7/site-packages/nltk/parse/transitionparser.pyR      s
   		
t
   Transitionc           B` sS   e  Z d  Z d Z d Z d Z d Z d   Z d   Z d   Z	 d   Z
 d	   Z RS(
   s½   
    This class defines a set of transition which is applied to a configuration to get another configuration
    Note that for different parsing algorithm, the transition is different.
    t   LEFTARCt   RIGHTARCt   SHIFTt   REDUCEc         C` sD   | |  _  | t j t j g k r@ t d t j t j f   n  d S(   s¢   
        :param alg_option: the algorithm option of this parser. Currently support `arc-standard` and `arc-eager` algorithm
        :type alg_option: str
        s%    Currently we only support %s and %s N(   t   _algot   TransitionParsert   ARC_STANDARDt	   ARC_EAGERt
   ValueError(   R   t
   alg_option(    (    s:   lib/python2.7/site-packages/nltk/parse/transitionparser.pyR   Ć   s    	c   	      C` sš   t  | j  d k s* t  | j  d k r. d S| j d d k rE d S| j t  | j  d } t } |  j t j k r¬ x2 | j D]$ \ } } } | | k r t } q q Wn  | rč | j j	   | j d } | j j
 | | | f  n d Sd S(   s  
        Note that the algorithm for left-arc is quite similar except for precondition for both arc-standard and arc-eager
            :param configuration: is the current configuration
            :return : A new configuration or -1 if the pre-condition is not satisfied
        i    i’’’’i   N(   R   R   R   R    RT   RU   RW   R   R   t   popR:   (	   R   t   conft   relationt   idx_wiR"   t
   idx_parentRE   t	   idx_childt   idx_wj(    (    s:   lib/python2.7/site-packages/nltk/parse/transitionparser.pyt   left_arcŅ   s    *c         C` sŽ   t  | j  d k s* t  | j  d k r. d S|  j t j k r | j j   } | j d } | | j d <| j j | | | f  nU | j t  | j  d } | j j d  } | j j |  | j j | | | f  d S(   sų   
        Note that the algorithm for right-arc is DIFFERENT for arc-standard and arc-eager
            :param configuration: is the current configuration
            :return : A new configuration or -1 if the pre-condition is not satisfied
        i    i’’’’i   N(	   R   R   R   RT   RU   RV   RZ   R   R:   (   R   R[   R\   R]   R`   (    (    s:   lib/python2.7/site-packages/nltk/parse/transitionparser.pyt	   right_arcķ   s    *c         C` s   |  j  t j k r d St | j  d k r/ d S| j t | j  d } t } x/ | j D]$ \ } } } | | k rY t } qY qY W| r | j j   n d Sd S(   sé   
        Note that the algorithm for reduce is only available for arc-eager
            :param configuration: is the current configuration
            :return : A new configuration or -1 if the pre-condition is not satisfied
        i’’’’i    i   N(	   RT   RU   RW   R   R   R   R   R    RZ   (   R   R[   R]   R"   R^   RE   R_   (    (    s:   lib/python2.7/site-packages/nltk/parse/transitionparser.pyt   reduce   s    c         C` s?   t  | j  d k r d S| j j d  } | j j |  d S(   só   
        Note that the algorithm for shift is the SAME for arc-standard and arc-eager
            :param configuration: is the current configuration
            :return : A new configuration or -1 if the pre-condition is not satisfied
        i    i’’’’N(   R   R   RZ   R   R:   (   R   R[   R]   (    (    s:   lib/python2.7/site-packages/nltk/parse/transitionparser.pyt   shift  s    (   RL   RM   RN   t   LEFT_ARCt	   RIGHT_ARCRR   RS   R   Ra   Rb   Rc   Rd   (    (    (    s:   lib/python2.7/site-packages/nltk/parse/transitionparser.pyRO   ·   s   				RU   c           B` sn   e  Z d  Z d Z d Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z e d
  Z d   Z RS(   sl   
    Class for transition based parser. Implement 2 algorithms which are "arc-standard" and "arc-eager"
    s   arc-standards	   arc-eagerc         C` s_   | |  j  |  j g k r7 t d |  j  |  j f   n  | |  _ i  |  _ i  |  _ i  |  _ d S(   s    
        :param algorithm: the algorithm option of this parser. Currently support `arc-standard` and `arc-eager` algorithm
        :type algorithm: str
        s%    Currently we only support %s and %s N(   RV   RW   RX   t
   _algorithmt   _dictionaryt   _transitiont   _match_transition(   R   t	   algorithm(    (    s:   lib/python2.7/site-packages/nltk/parse/transitionparser.pyR   +  s    			c         C` sR   | j  | } | j  | } | d d  k r. d  S| d | d k rJ | d Sd  Sd  S(   NR$   t   headt   addresst   rel(   R   R   (   R   R^   R_   t   depgrapht   p_nodet   c_node(    (    s:   lib/python2.7/site-packages/nltk/parse/transitionparser.pyt   _get_dep_relation;  s    c         C` sd   g  } x> | D]6 } |  j  j | t |  j    | j |  j  |  q Wd j d   t |  D  S(   sč   
        :param features: list of feature string which is needed to convert to binary features
        :type features: list(str)
        :return : string of binary features in libsvm format  which is 'featureID:value' pairs
        t    c         s` s   |  ] } t  |  d  Vq d S(   s   :1.0N(   R   (   t   .0t	   featureID(    (    s:   lib/python2.7/site-packages/nltk/parse/transitionparser.pys	   <genexpr>T  s    (   Rh   t
   setdefaultR   R:   t   joint   sorted(   R   t   featurest   unsorted_resultt   feature(    (    s:   lib/python2.7/site-packages/nltk/parse/transitionparser.pyt   _convert_to_binary_featuresG  s    c   
      C` s-  g  } xc | j  D]X } | j  | } d | k r | d } | d } | d  k	 rh | j | | f  qh q q Wxŗ | D]² \ } } | | k r  | } | } | } n  x t | d |  D]m } xd t t | j    D]M }	 |	 | k  sī |	 | k rŠ | |	 f | k rt S|	 | f | k rt SqŠ qŠ Wq“ Wqs Wt S(   NRl   Rm   i   (   R   R   R:   R   R   R   R    (
   R   Ro   t   arc_listt   keyt   nodet   childIdxt	   parentIdxt   tempt   kt   m(    (    s:   lib/python2.7/site-packages/nltk/parse/transitionparser.pyt   _is_projectiveW  s*    

	c         C` sm   |  j  j | t |  j   d  | |  j |  j  | <t |  j  |  d | d } | j | j d   d S(   s^   
        write the binary features to input file and update the transition dictionary
        i   Rs   s   
s   utf-8N(   Ri   Rv   R   Rj   R   t   writet   encode(   R   R~   t   binary_featurest
   input_filet	   input_str(    (    s:   lib/python2.7/site-packages/nltk/parse/transitionparser.pyt   _write_to_fileq  s     c         C` s  t  |  j  } d } g  } x<| D]4} |  j |  s= q" n  | d 7} t |  } x t | j  d k rU| j d } | j   }	 |  j |	  }
 t | j  d k r| j t | j  d } |  j	 | | |  } | d k	 r*t  j d | } |  j | |
 |  | j | |  | j |  qV n  |  j	 | | |  } | d k	 rt } | j } xl t | d  D]Z } | | k rk|  j	 | | |  } | d k	 rÅ| | | f | j k rĀt } qĀqÅqkqkW| rt  j d | } |  j | |
 |  | j | |  | j |  qV qqn  t  j } |  j | |
 |  | j |  | j |  qV Wq" Wt d t t |    t d t |   | S(   sŌ   
        Create the training example in the libsvm format and write it to the input_file.
        Reference : Page 32, Chapter 3. Dependency Parsing by Sandra Kubler, Ryan McDonal and Joakim Nivre (2009)
        i    i   t   :s    Number of training examples : s)    Number of valid (projective) examples : N(   RO   RV   R   R   R   R   RK   R|   R   Rr   R   Re   R   Ra   R:   R    R   R   R   R   Rf   Rb   RR   Rd   t   printR   (   R   t	   depgraphsR   t	   operationt
   count_projt   training_seqRo   R[   t   b0Ry   R   t   s0Rn   R~   t   preconditiont   maxIDt   wt   relw(    (    s:   lib/python2.7/site-packages/nltk/parse/transitionparser.pyt!   _create_training_examples_arc_std{  sX    
		c         C` s¬  t  |  j  } d } g  } x\| D]T} |  j |  s= q" n  | d 7} t |  } x t | j  d k ru| j d } | j   }	 |  j |	  }
 t | j  d k r<| j t | j  d } |  j	 | | |  } | d k	 r*t  j d | } |  j | |
 |  | j | |  | j |  qV n  |  j	 | | |  } | d k	 rt  j d | } |  j | |
 |  | j | |  | j |  qV n  t } x\ t |  D]N } |  j	 | | |  d k	 rĻt } n  |  j	 | | |  d k	 r„t } q„q„W| r<t  j } |  j | |
 |  | j |  | j |  qV q<n  t  j } |  j | |
 |  | j |  | j |  qV Wq" Wt d t t |    t d t |   | S(   sĢ   
        Create the training example in the libsvm format and write it to the input_file.
        Reference : 'A Dynamic Oracle for Arc-Eager Dependency Parsing' by Joav Goldberg and Joakim Nivre
        i    i   R   s    Number of training examples : s)    Number of valid (projective) examples : N(   RO   RW   R   R   R   R   RK   R|   R   Rr   R   Re   R   Ra   R:   Rf   Rb   R   R   R    RS   Rc   RR   Rd   R   R   (   R   R   R   R   t	   countProjR   Ro   R[   R   Ry   R   R   Rn   R~   R"   R   (    (    s:   lib/python2.7/site-packages/nltk/parse/transitionparser.pyt#   _create_training_examples_arc_eager¹  s^    
				c         C` sš   zŪ t  j d d d t  j   d t  } |  j |  j k rL |  j | |  n |  j | |  | j   t	 | j
  \ } } t j d d d d d	 d
 d d d d d | d t  } | j | |  t j | t | d   Wd t | j
  Xd S(   sŲ   
        :param depgraphs : list of DependencyGraph as the training data
        :type depgraphs : DependencyGraph
        :param modelfile : file name to save the trained model
        :type modelfile : str
        t   prefixs   transition_parse.traint   dirt   deletet   kernelt   polyt   degreei   t   coef0i    t   gammagÉ?t   Cg      ą?t   verboset   probabilityt   wbN(   t   tempfilet   NamedTemporaryFilet
   gettempdirR   Rg   RV   R   R   t   closeR   t   nameR	   t   SVCR    t   fitt   picklet   dumpt   openR   (   R   R   t	   modelfileR¤   R   t   x_traint   y_traint   model(    (    s:   lib/python2.7/site-packages/nltk/parse/transitionparser.pyt   trainł  s&    	
		c   !      C` sU  g  } t  j t | d   } t |  j  } x!| D]} t |  } xxt | j  d k rĄ| j   } g  }	 g  }
 g  } xN | D]F } | |  j	 k r |	 j
 |  j	 |  |
 j
 d  | j
 d  q q Wt t |	   } t |
  } t |  } t j | | | f f d d t |  j	  f } i  } | j |  d } x( t t |   D] } | | | | <qSWt | j   d t d  d t } x+| D]#\ } } | j | } | |  j k r­|  j | } | j d  d } | t j k r| j | | j d  d  d	 k rŖPqŖq¹| t j k rT| j | | j d  d  d	 k rŖPqŖq¹| t j k r| j |  d	 k rŖPqŖq¹| t j k r¹| j |  d	 k rŖPqŖq¹qt d
   qWqI Wt  |  } x2 | j! D]' } | j! | } d | d <d | d <q×Wx; | j" D]0 \ } } } | j! | }  | |  d <| |  d <qW| j
 |  q4 W| S(   sZ  
        :param depgraphs: the list of test sentence, each sentence is represented as a dependency graph where the 'head' information is dummy
        :type depgraphs: list(DependencyGraph)
        :param modelfile: the model file
        :type modelfile: str
        :return: list (DependencyGraph) with the 'head' and 'rel' information
        t   rbi    g      š?t   shapei   R~   t   reverseR   i’’’’s;   The predicted transition is not recognized, expected errorsR   Rn   Rl   (#   R®   t   loadR°   RO   Rg   R   R   R   RK   Rh   R:   R   Rx   R   t
   csr_matrixt   predict_probaR   t   itemsR   R    t   classes_Rj   R;   Re   Ra   Rf   Rb   RS   Rc   RR   Rd   RX   R   R   R   (!   R   R   t	   modelFileR<   R“   R   Ro   R[   Ry   t   colt   rowt   dataR{   t   np_colt   np_rowt   np_datat   x_testt	   prob_dictt	   pred_probt   it   sorted_Probt
   y_pred_idxt
   confidencet   y_predt   strTransitiont   baseTransitiont   new_depgraphR~   R   Rl   Rn   t   childRq   (    (    s:   lib/python2.7/site-packages/nltk/parse/transitionparser.pyt   parse"  sr    *$		


(   RL   RM   RN   RV   RW   R   Rr   R|   R   R   R   R   R    Rµ   RŃ   (    (    (    s:   lib/python2.7/site-packages/nltk/parse/transitionparser.pyRU   "  s   					
	>	@)c           C` s   d S(   s   
    >>> from nltk.parse import DependencyGraph, DependencyEvaluator
    >>> from nltk.parse.transitionparser import TransitionParser, Configuration, Transition
    >>> gold_sent = DependencyGraph("""
    ... Economic  JJ     2      ATT
    ... news  NN     3       SBJ
    ... has       VBD       0       ROOT
    ... little      JJ      5       ATT
    ... effect   NN     3       OBJ
    ... on     IN      5       ATT
    ... financial       JJ       8       ATT
    ... markets    NNS      6       PC
    ... .    .      3       PU
    ... """)

    >>> conf = Configuration(gold_sent)

    ###################### Check the Initial Feature ########################

    >>> print(', '.join(conf.extract_features()))
    STK_0_POS_TOP, BUF_0_FORM_Economic, BUF_0_LEMMA_Economic, BUF_0_POS_JJ, BUF_1_FORM_news, BUF_1_POS_NN, BUF_2_POS_VBD, BUF_3_POS_JJ

    ###################### Check The Transition #######################
    Check the Initialized Configuration
    >>> print(conf)
    Stack : [0]  Buffer : [1, 2, 3, 4, 5, 6, 7, 8, 9]   Arcs : []

    A. Do some transition checks for ARC-STANDARD

    >>> operation = Transition('arc-standard')
    >>> operation.shift(conf)
    >>> operation.left_arc(conf, "ATT")
    >>> operation.shift(conf)
    >>> operation.left_arc(conf,"SBJ")
    >>> operation.shift(conf)
    >>> operation.shift(conf)
    >>> operation.left_arc(conf, "ATT")
    >>> operation.shift(conf)
    >>> operation.shift(conf)
    >>> operation.shift(conf)
    >>> operation.left_arc(conf, "ATT")

    Middle Configuration and Features Check
    >>> print(conf)
    Stack : [0, 3, 5, 6]  Buffer : [8, 9]   Arcs : [(2, 'ATT', 1), (3, 'SBJ', 2), (5, 'ATT', 4), (8, 'ATT', 7)]

    >>> print(', '.join(conf.extract_features()))
    STK_0_FORM_on, STK_0_LEMMA_on, STK_0_POS_IN, STK_1_POS_NN, BUF_0_FORM_markets, BUF_0_LEMMA_markets, BUF_0_POS_NNS, BUF_1_FORM_., BUF_1_POS_., BUF_0_LDEP_ATT

    >>> operation.right_arc(conf, "PC")
    >>> operation.right_arc(conf, "ATT")
    >>> operation.right_arc(conf, "OBJ")
    >>> operation.shift(conf)
    >>> operation.right_arc(conf, "PU")
    >>> operation.right_arc(conf, "ROOT")
    >>> operation.shift(conf)

    Terminated Configuration Check
    >>> print(conf)
    Stack : [0]  Buffer : []   Arcs : [(2, 'ATT', 1), (3, 'SBJ', 2), (5, 'ATT', 4), (8, 'ATT', 7), (6, 'PC', 8), (5, 'ATT', 6), (3, 'OBJ', 5), (3, 'PU', 9), (0, 'ROOT', 3)]


    B. Do some transition checks for ARC-EAGER

    >>> conf = Configuration(gold_sent)
    >>> operation = Transition('arc-eager')
    >>> operation.shift(conf)
    >>> operation.left_arc(conf,'ATT')
    >>> operation.shift(conf)
    >>> operation.left_arc(conf,'SBJ')
    >>> operation.right_arc(conf,'ROOT')
    >>> operation.shift(conf)
    >>> operation.left_arc(conf,'ATT')
    >>> operation.right_arc(conf,'OBJ')
    >>> operation.right_arc(conf,'ATT')
    >>> operation.shift(conf)
    >>> operation.left_arc(conf,'ATT')
    >>> operation.right_arc(conf,'PC')
    >>> operation.reduce(conf)
    >>> operation.reduce(conf)
    >>> operation.reduce(conf)
    >>> operation.right_arc(conf,'PU')
    >>> print(conf)
    Stack : [0, 3, 9]  Buffer : []   Arcs : [(2, 'ATT', 1), (3, 'SBJ', 2), (0, 'ROOT', 3), (5, 'ATT', 4), (3, 'OBJ', 5), (5, 'ATT', 6), (8, 'ATT', 7), (6, 'PC', 8), (3, 'PU', 9)]

    ###################### Check The Training Function #######################

    A. Check the ARC-STANDARD training
    >>> import tempfile
    >>> import os
    >>> input_file = tempfile.NamedTemporaryFile(prefix='transition_parse.train', dir=tempfile.gettempdir(), delete=False)

    >>> parser_std = TransitionParser('arc-standard')
    >>> print(', '.join(parser_std._create_training_examples_arc_std([gold_sent], input_file)))
     Number of training examples : 1
     Number of valid (projective) examples : 1
    SHIFT, LEFTARC:ATT, SHIFT, LEFTARC:SBJ, SHIFT, SHIFT, LEFTARC:ATT, SHIFT, SHIFT, SHIFT, LEFTARC:ATT, RIGHTARC:PC, RIGHTARC:ATT, RIGHTARC:OBJ, SHIFT, RIGHTARC:PU, RIGHTARC:ROOT, SHIFT

    >>> parser_std.train([gold_sent],'temp.arcstd.model', verbose=False)
     Number of training examples : 1
     Number of valid (projective) examples : 1
    >>> remove(input_file.name)

    B. Check the ARC-EAGER training

    >>> input_file = tempfile.NamedTemporaryFile(prefix='transition_parse.train', dir=tempfile.gettempdir(),delete=False)
    >>> parser_eager = TransitionParser('arc-eager')
    >>> print(', '.join(parser_eager._create_training_examples_arc_eager([gold_sent], input_file)))
     Number of training examples : 1
     Number of valid (projective) examples : 1
    SHIFT, LEFTARC:ATT, SHIFT, LEFTARC:SBJ, RIGHTARC:ROOT, SHIFT, LEFTARC:ATT, RIGHTARC:OBJ, RIGHTARC:ATT, SHIFT, LEFTARC:ATT, RIGHTARC:PC, REDUCE, REDUCE, REDUCE, RIGHTARC:PU

    >>> parser_eager.train([gold_sent],'temp.arceager.model', verbose=False)
     Number of training examples : 1
     Number of valid (projective) examples : 1

    >>> remove(input_file.name)

    ###################### Check The Parsing Function ########################

    A. Check the ARC-STANDARD parser

    >>> result = parser_std.parse([gold_sent], 'temp.arcstd.model')
    >>> de = DependencyEvaluator(result, [gold_sent])
    >>> de.eval() >= (0, 0)
    True

    B. Check the ARC-EAGER parser
    >>> result = parser_eager.parse([gold_sent], 'temp.arceager.model')
    >>> de = DependencyEvaluator(result, [gold_sent])
    >>> de.eval() >= (0, 0)
    True

    Remove test temporary files
    >>> remove('temp.arceager.model')
    >>> remove('temp.arcstd.model')

    Note that result is very poor because of only one training example.
    N(    (    (    (    s:   lib/python2.7/site-packages/nltk/parse/transitionparser.pyt   demo  R   (   t
   __future__R    R   R   R§   R®   t   osR   t   copyR   t   operatorR   t   numpyR   t   scipyR   t   sklearn.datasetsR   t   sklearnR	   t   ImportErrort
   nltk.parseR
   R   R   t   objectR   RO   RU   RŅ   (    (    (    s:   lib/python2.7/site-packages/nltk/parse/transitionparser.pyt   <module>	   s(   k’ l