B
    .(b                  @   s&  d dl mZ d dlZd dlZd dlmZmZmZmZm	Z	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dd Zdd Zejddgdd Zejddgdd Zdd Zdd Zdd Zdd Zdd Zd d! Z d"d# Z!d$d% Z"d&d' Z#d(d) Z$d*d+ Z%d,d- Z&d.d/ Z'dS )0    )unicode_literalsN)IS_ALPHAIS_DIGITIS_LOWERIS_PUNCTIS_TITLEIS_STOP)VERB)Vocab)Doc   )get_docc             C   sh   d}ddddddddddddddg}ddd	d
dddd	d
ddd	ddg}| |}t |jdd |D ||dS )Nz:This is a sentence. This is another sentence. And a third.   r   nsubjROOTdetattrpunctZnpadvmodc             S   s   g | ]
}|j qS  )text).0tr   r   M/home/dcms/DCMS/lib/python3.7/site-packages/spacy/tests/doc/test_token_api.py
<listcomp>   s    zdoc.<locals>.<listcomp>)wordsheadsdeps)r   vocab)en_tokenizerr   r   r   tokensr   r   r   doc   s     r#   c             C   s  d}dddddddg}dddd	d
ddg}dddddddg}| |}t |jdd |D |||d}|d jdksrt|d jdkst|d jdkst|d jdkst|d jdkst|d jdkst|d j	dkst|d j
dkst|d jdkstd S )NzGive it back! He pleaded.r	   ZPRONZPARTZPUNCTr   r   r   r   r   r   ZdobjZprtr   r   c             S   s   g | ]
}|j qS r   )r   )r   r   r   r   r   r   "   s    z.test_doc_token_api_strings.<locals>.<listcomp>)r   posr   r   ZGivezGive ZgiveZXxxxGZive)r   r    Zorth_AssertionErrorr   Ztext_with_wsZlower_Zshape_Zprefix_Zsuffix_pos_Zdep_)r!   r   r$   r   r   r"   r#   r   r   r   test_doc_token_api_strings   s     r(   c             C   s   d}| |}|d  tst|d  tr0t|d  tsBt|d  tsTt|d  tsft|d  tsxt|d  trtd S )NzGive it back! He pleaded.r   r      r      )Z
check_flagr   r&   r   r   r   r   r   )r!   r   r"   r   r   r   test_doc_token_api_flags/   s    r+   r   zGive it back! He pleaded.c             C   s6   |  d }d| j| _| |}|d jdks2td S )Nr   r   )splitr    Zprobr&   )r!   r   wordr"   r   r   r   ,test_doc_token_api_prob_inherited_from_vocab<   s    r.   zone twoc             C   sH   | |}t |d |dd ks&tt |d |dd ksDtd S )Nr    r   )strr,   r&   )r!   r   r"   r   r   r   test_doc_token_api_str_builtinD   s    r1   c             C   s   t | ddddddgd}|d js&t|d js4t|d jrBt|d	 jsPt|d
 js^t|d
 jrlt|d jszt|d j	std S )NZHi,Zmyemailisztest@me.com)r   r   r   r)      r*   )
r   Zis_titler&   Zis_alphaZis_digitZis_punctZis_asciiZlike_urlZis_lowerZ
like_email)en_vocabr#   r   r   r    test_doc_token_api_is_propertiesK   s    r7   c              C   s   t  } | jdd | jdtjddgddd | jd	tjdd
gddd t| dd	dgd}|jsft|d jstt|d jst|d jrtd}d
}d||  }|d |d |kstd S )Nr   )widthZapplesg        g       @f)Zdtype)ZvectorZorangesg      ?Zoov)r   r   r   )	r
   Zreset_vectorsZ
set_vectornumpyZasarrayr   Z
has_vectorr&   Z
similarity)r    r#   Zapples_normZoranges_normZcosiner   r   r   test_doc_token_api_vectorsW   s    
r;   c          	   C   s   d}dddddddddg	}| |}t |jdd	 |D |d
}dd	 |d jD ddgks\tdd	 |d jD dgksztdd	 |d jD g kst|d |d st|d |d rtd S )Nz)Yesterday I saw a dog that barked loudly.r   r   r   r   r   ic             S   s   g | ]
}|j qS r   )r   )r   r   r   r   r   r   l   s    z0test_doc_token_api_ancestors.<locals>.<listcomp>)r   r   c             S   s   g | ]
}|j qS r   )r   )r   r   r   r   r   r   m   s       ZdogZsawc             S   s   g | ]
}|j qS r   )r   )r   r   r   r   r   r   n   s    c             S   s   g | ]
}|j qS r   )r   )r   r   r   r   r   r   o   s       )r   r    Z	ancestorsr&   Zis_ancestor)r!   r   r   r"   r#   r   r   r   test_doc_token_api_ancestorsg   s     r>   c          	   C   sD  d}dddddddddg	}| |}t |jdd	 |D |d
}|d jdksNt|d jdks`t|d jjdkstt|d jjdkst|d jdkst|d jdkst|d jjdkst|d jjdkst|d jdkst|d jdkst|d jjdkst|d jjdks$t|d jjdks:t|d jjdksPt|d |d _|d jdksrt|d jdkst|d jjdkst|d jjdkst|d jdkst|d jdkst|d jjdkst|d jjdkst|d jdkst|d jdks.t|d jjdksDt|d jjdksZt|d jjdkspt|d jjdkst|d |d _|d jjdkst|d jjdkst|d jjdkst|d jjdkst|d jjdkstt |jdd	 |D |d
}t	
t |d |d _W d Q R X d S )Nz)Yesterday I saw a dog that barked loudly.r   r   r   r   r   ic             S   s   g | ]
}|j qS r   )r   )r   r   r   r   r   r   z   s    z2test_doc_token_api_head_setter.<locals>.<listcomp>)r   r   r<   r*   r=   r5   r)      c             S   s   g | ]
}|j qS r   )r   )r   r   r   r   r   r      s    )r   r    Zn_leftsr&   Zn_rights	left_edgeiZ
right_edgeheadpytestZraises
ValueError)r!   r   r   r"   r#   Zdoc2r   r   r   test_doc_token_api_head_setteru   sT    rE   c             C   sV   | d}|d j d kstd|d _ |d j dks6td|_tt|jdksRtd S )Nz$This is a sentence. This is another.r*   Tr   )is_sent_startr&   	is_parsedlenlistsents)r!   r#   r   r   r   test_is_sent_start   s    
rK   c             C   sV   | d}|d j d kstd|d _|d j dks6td|_tt|jdksRtd S )Nz$This is a sentence. This is another.r5   Tr*   r   )is_sent_endr&   rF   rG   rH   rI   rJ   )r!   r#   r   r   r   test_is_sent_end   s    
rM   c              C   sN   t t ddgd} d| d _| d jdks.tt| d _| d jdksJtd S )Nhelloworld)r   ZNOUNr   r   r	   )r   r
   r'   r&   r	   r$   )r#   r   r   r   test_set_pos   s
    

rP   c             C   sr   t t| jdkst| d jjdks*t| d jjdks>t| d jjjjdksVt| d jjjjdksntdS )zTest token.sent propertyr)   r   zThis is a sentence .r=   zThis is another sentence .ZThisN)rH   rI   rJ   r&   sentr   rootr@   )r#   r   r   r   test_tokens_sent   s
    rS   c              C   sD   t t ddgd} | d jdks$t| d jd ks6t| jr@td S )NrN   rO   )r   r   Tr   )r   r
   rF   r&   is_sentenced)r#   r   r   r   test_token0_has_sent_start_true   s    rU   c              C   sD   t t ddgd} | d jd ks$t| d jdks6t| jr@td S )NrN   rO   )r   r   r   T)r   r
   rL   r&   rT   )r#   r   r   r    test_tokenlast_has_sent_end_true   s    rV   c          
   C   s   d  }ddddddddddg
}ddd	dd
d	dd
ddg
}t| |||d}dd |d jD ddgkshtdd |d jD ddgkstdd |d jD ddgkstd S )Nz'The boy and the girl and the man went .r   r=   r   r   r   r   r   ccconjr   r   )r   r   r   c             S   s   g | ]
}|j qS r   )r   )r   wr   r   r   r      s    z2test_token_api_conjuncts_chain.<locals>.<listcomp>ZgirlZmanc             S   s   g | ]
}|j qS r   )r   )r   rY   r   r   r   r      s    r5   Zboyc             S   s   g | ]
}|j qS r   )r   )r   rY   r   r   r   r      s    )r,   r   	conjunctsr&   )r6   r   r   r   r#   r   r   r   test_token_api_conjuncts_chain   s      r[   c             C   st   d  }dddddg}dddd	d
g}t| |||d}dd |d jD dgksRtdd |d jD dgksptd S )NzThey came and went .r   r   r   r   r   r   rW   rX   dep)r   r   r   c             S   s   g | ]
}|j qS r   )r   )r   rY   r   r   r   r      s    z3test_token_api_conjuncts_simple.<locals>.<listcomp>Zwentc             S   s   g | ]
}|j qS r   )r   )r   rY   r   r   r   r      s    r)   Zcame)r,   r   rZ   r&   )r6   r   r   r   r#   r   r   r   test_token_api_conjuncts_simple   s    r]   c             C   sh   d  }dddg}dddg}t| |||d}d	d
 |d jD g ksHtdd
 |d jD g ksdtd S )NzThey came .r   r   r   r   r   r   )r   r   r   c             S   s   g | ]
}|j qS r   )r   )r   rY   r   r   r   r      s    z0test_token_api_non_conjuncts.<locals>.<listcomp>c             S   s   g | ]
}|j qS r   )r   )r   rY   r   r   r   r      s    )r,   r   rZ   r&   )r6   r   r   r   r#   r   r   r   test_token_api_non_conjuncts   s    

r^   )(
__future__r   rC   r:   Zspacy.attrsr   r   r   r   r   r   Zspacy.symbolsr	   Zspacy.vocabr
   Zspacy.tokensr   utilr   Zfixturer#   r(   r+   markZparametrizer.   r1   r7   r;   r>   rE   rK   rM   rP   rS   rU   rV   r[   r]   r^   r   r   r   r   <module>   s2    ;			
	