B
    .(b+                 @   s   d dl m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ZddlmZ ejd	d
 Zejdd Zdd Zdd Zdd Zdd ZdS )    )unicode_literalsN)Span)Language)EntityRuler)load   )make_tempdirc               C   sH   ddddddiddigddddigddd	d
dgdddddgS )NZHELLOzhello world)labelpatternZBYEZLOWERZbyeORTHZCOMPLEXZfoo*)r   OPZTECH_ORGAppleZa1)r	   r
   id r   r   r   T/home/dcms/DCMS/lib/python3.7/site-packages/spacy/tests/regression/test_issue3526.pypatterns   s
    r   c              C   s   dd } | S )Nc             S   s    t | dd| jjd dg| _| S )Nr      ORG)r	   )r   vocabstringsZents)docr   r   r   add_ent_component   s    z"add_ent.<locals>.add_ent_componentr   )r   r   r   r   add_ent   s    r   c             C   s   t |d}t|| dd}| }t|t| ks4tt|jdksFt|jsPtt|}||}t|t|ksvtt|jdkst|j|jkst|j|jkstd S )N)r   T)r   overwrite_ents   )	r   r   to_byteslenAssertionErrorlabels	overwrite
from_bytesZ
ent_id_sep)r   en_vocabnlprulerZruler_bytes	new_rulerr   r   r   4test_entity_ruler_existing_overwrite_serialize_bytes"   s    


r&   c             C   s|   t |d}t|| dd}t|j}t|}||}t|t|ksJtx|jD ]}||jksRtqRW |j|jk	sxtd S )N)r   T)r   r   )	r   r   srslyZmsgpack_dumpsr   r!   r   r   r    )r   r"   r#   r$   Zbytes_old_styler%   r
   r   r   r   0test_entity_ruler_existing_bytes_old_format_safe1   s    

r(   c          	   C   s   t |d}t|| dd}t r}|d }t|d|j t||}x|jD ]}||jksRtqRW t	|t	|ks|t|j
|j
k	stW d Q R X d S )N)r   T)r   r   entity_rulerz.jsonl)r   r   r   r'   Zwrite_jsonlwith_suffixr   Z	from_diskr   r   r    )r   r"   r#   r$   tmpdirout_filer%   r
   r   r   r   +test_entity_ruler_from_disk_old_format_safe=   s    
r-   c          	   C   s   t |d}t|dd}|dddg || t t}|| |d}|jdddgksdt|j	dksrtt
|}|d}|jdddgkst|j	dkstW d Q R X d S )N)r   T)r   r   r   )r	   r
   r)   )r   r   Zadd_patternsZadd_piper   Zto_diskZget_piper   r   r    r   )r   r"   r#   r$   r+   Znlp2r%   r   r   r   (test_entity_ruler_in_pipeline_from_issueJ   s    




r.   )
__future__r   ZpytestZspacy.tokensr   Zspacy.languager   Zspacy.pipeliner   Zspacyr   r'   utilr   Zfixturer   r   r&   r(   r-   r.   r   r   r   r   <module>   s   	