
    i                        d dl Z d dlZ d dlZd dlZd dlmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZ d dlmZ d dlmZ d d	lmZ  ej(                  d
      d        Z ej(                  d
      d        Z ej(                  d
      d        Z ej(                  d
      d        Zej(                  d        Zej(                  d        Z ej(                  d
      d        Z ej(                  d
      d        Z ej(                  g d      d        Zej(                  d        Zej(                  d        Zej(                  d        Z d Z!d Z"d Z#d Z$ e jJ                  e jL                  jO                               d        Z(y)     N)ndarrays_of_shape)Language)	BeamBatch)ArcEager
StateClassDoc)ExampleVocabmodule)scopec                      t               S Nr        p/var/www/vps2.regionflexible.com/Desarrollo/venv/lib/python3.12/site-packages/spacy/tests/parser/test_nn_beam.pyvocabr      s	    7Nr   c                 v   t        | j                  i       }|j                  dd       |j                  dd       |j                  dd       |j                  dd       |j                  dd       |j                  dd       |j                  d	d
       |j                  dd       |j                  dd       |S )Nr          nsubjpunctaux	nsubjpass   dobj   ROOT)r   strings
add_action)r   aeagers     r   movesr%      s    emmR(F
a
a
a!
a!
a
a%
a 
a
a Mr   c                 4    t        | g dg dg dg d      gS )N)Ratsbitethings)r   r   r   )r   r!   r   )TFF)wordsheadsdepssent_startsr	   )r   s    r   docsr.   $   s%     	,*,	
 r   c                 \    | D cg c]  }t        ||j                                c}S c c}w r   )r   copyr.   docs     r   examplesr3   1   s#    045GC$555s   !)c                 >    | D cg c]  }t        |       c}S c c}w r   r   r1   s     r   statesr5   6   s    '+,JsO,,,s   c                     g }| D ]R  }t         j                  j                  ddt        |      |f      }|j	                  t        j
                  |             T |S )N皙皙?)numpyrandomuniformlenappendasarray)r.   vector_sizeoutputr2   vecs        r   tokvecsrB   ;   sS    F *ll""4s3x.EFemmC()* Mr   c                     t        |       S r   r<   )r.   s    r   
batch_sizerE   D   s    t9r   c                       y)Nr    r   r   r   r   
beam_widthrG   I       r   )        g      ?      ?)paramsc                     | j                   S r   )param)requests    r   beam_densityrO   N   s    ==r   c                       y)N   r   r   r   r   r?   r?   S   rH   r   c                 L    | j                  |      \  }}}t        | |||d      S )NrI   widthdensity)init_gold_batchr   )r%   r3   rG   r5   golds_s         r   beamrY   X   s,    ,,X6FE1UFESIIr   c                     t        j                  t        j                  t        |      D cg c]/  }t         j                  j                  dd|| j                  f      1 c}      d      S c c}w )Nr7   r8   float32)dtype)r9   r>   concatenateranger:   r;   n_moves)r%   rE   rG   rX   s       r   scoresr`   ^   sd    == z* $$T3U]]0KL	
  s   4A-c                      y r   r   )rY   s    r   test_create_beamrb   k   s    r   c                 &    | j                  |       y r   )advance)rY   r`   s     r   test_beam_advancere   o   s    LLr   c                     t        d | D              }|d | }t        j                  t              5  | j	                  |d d        d d d        y # 1 sw Y   y xY w)Nc              3   2   K   | ]  }t        |        y wr   rD   .0rY   s     r   	<genexpr>z3test_beam_advance_too_few_scores.<locals>.<genexpr>t        -#d)-   )sumpytestraises
IndexErrorrd   )rY   r`   n_states      r    test_beam_advance_too_few_scoresrs   s   sQ    ---GHWF	z	" "VCR[!" " "s   AAc                      t               }|j                  d      }||j                  d<   |j                  d       |j	                   fd       |j                  d      } ||       y )Nbeam_parserrG   r   c                       S r   r   )r3   s   r   <lambda>z!test_beam_parse.<locals>.<lambda>   s    h r   zAustralia is a country)r   add_pipecfg	add_label
initializemake_doc)r3   rG   nlpparserr2   s   `    r   test_beam_parser   z   sY    
*C\\-(F)FJJ|
W
&'
,,/
0C
3Kr   )hypc           	         t        |j                  t        j                  j	                  ddd                  }| j                  |      \  }}}t        | ||||      }t        d |D              }	|j                  t        |	| j                  f            }
|j                  |
       |D ]/  }|j                  }|j                  |k(  sJ |d   |d   |z  k\  r/J  y )	NrI   rJ       )rT   rS   c              3   2   K   | ]  }t        |        y wr   rD   rh   s     r   rj   z$test_beam_density.<locals>.<genexpr>   rk   rl   rm   r   )floatdraw
hypothesis
strategiesfloatsrV   r   rn   r   r_   rd   probsmin_density)r%   r3   rG   r   rO   r5   rW   rX   rY   rr   r`   b
beam_probss                r   test_beam_densityr      s    *"7"7">">sCr">"RSTL,,X6FE1UFE\RD---GXX'%--(@ABFLL >WW
}},,,"~A!====>r   ))r   hypothesis.strategiesr9   ro   thinc.tests.strategiesr   spacy.languager   ,spacy.pipeline._parser_internals._beam_utilsr   *spacy.pipeline._parser_internals.arc_eagerr   +spacy.pipeline._parser_internals.stateclassr   spacy.tokensr
   spacy.trainingr   spacy.vocabr   fixturer   r%   r.   r3   r5   rB   rE   rG   rO   r?   rY   r`   rb   re   rs   r   givenr   datar   r   r   r   <module>r      s       4 # B ? B  "  h   h   h	  	 h6  6 - -   h   h   ' (   J J
 	 		" j++0023
> 4
>r   