B
    .(b	                 @   sh   d dl mZ d dlZd dlmZmZ d dlmZ d dlm	Z	 d dl
mZ ddlmZ d	d
 Zdd ZdS )    )unicode_literalsN)EntityRecognizerEntityRuler)English)Span)ensure_path   )make_tempdirc        	   	   C   s   t  } | d}|d | | |   t| }ddddddidd	igdg}|| | j|dd
 | d}|jd jdkst	t
 N}t|}| s|  | | t|}|d}|jd jdkst	W dQ R X dS )z@Test that serialization of an EntityRuler before NER works fine.ner
SOME_LABELMY_ORGZApple)labelpatternZMY_GPElowersanZ	francisco)beforezWhat do you think about Apple ?r   N)r   create_pipe	add_labeladd_pipebegin_trainingr   Zadd_patternsentsZlabel_AssertionErrorr	   r   existsmkdirto_diskspacyload)	Znlpr
   Zrulerpatternsdoc1d
output_dirZnlp2Zdoc2 r!   T/home/dcms/DCMS/lib/python3.7/site-packages/spacy/tests/regression/test_issue4042.pytest_issue4042   s(    





r#   c           	   C   s  t  } | j}| d}|d | | |   | d}t|jdksLtd|jksZtt	|dddd}t
|j|g |_|| t|jd	kstd|jkstd|jkstt N}t|}| s|  || t|}|| t|jd	kstW d
Q R X d
S )z
    Test that serialization of an NER works fine when new labels were added.
    This is the second bug of two bugs underlying the issue 4042.
    r
   r   zWhat do you think about Apple ?         r   )r   r   N)r   vocabr   r   r   r   lenlabelsr   r   listr   r	   r   r   r   r   r   Z	from_disk)Znlp1r'   Zner1r   Z	apple_entr   r    Zner2r!   r!   r"   test_issue4042_bug2-   s.    




r+   )
__future__r   r   Zspacy.pipeliner   r   Zspacy.lang.enr   Zspacy.tokensr   Z
spacy.utilr   utilr	   r#   r+   r!   r!   r!   r"   <module>   s    