+
    ÖÇÜh   ã                   óh   € ^ RI t ^ RIt^ RIt^ RIt^ RIt^ RIHt ^ RIHt ^ RI	H
t
  ! R R]
4      tR# )é    N)ÚZipFilePathPointer)Úfind_dir)Ú
TokenizerIc                   ój   a € ] tR t^t o RtRR ltR tRR ltR t]	R 4       t
]	R 4       tR tR	tV tR
# )ÚReppTokenizeray  
A class for word tokenization using the REPP parser described in
Rebecca Dridan and Stephan Oepen (2012) Tokenization: Returning to a
Long Solved Problem - A Survey, Contrastive  Experiment, Recommendations,
and Toolkit. In ACL. http://anthology.aclweb.org/P/P12/P12-2.pdf#page=406

>>> sents = ['Tokenization is widely regarded as a solved problem due to the high accuracy that rulebased tokenizers achieve.' ,
... 'But rule-based tokenizers are hard to maintain and their rules language specific.' ,
... 'We evaluated our method on three languages and obtained error rates of 0.27% (English), 0.35% (Dutch) and 0.76% (Italian) for our best models.'
... ]
>>> tokenizer = ReppTokenizer('/home/alvas/repp/') # doctest: +SKIP
>>> for sent in sents:                             # doctest: +SKIP
...     tokenizer.tokenize(sent)                   # doctest: +SKIP
...
(u'Tokenization', u'is', u'widely', u'regarded', u'as', u'a', u'solved', u'problem', u'due', u'to', u'the', u'high', u'accuracy', u'that', u'rulebased', u'tokenizers', u'achieve', u'.')
(u'But', u'rule-based', u'tokenizers', u'are', u'hard', u'to', u'maintain', u'and', u'their', u'rules', u'language', u'specific', u'.')
(u'We', u'evaluated', u'our', u'method', u'on', u'three', u'languages', u'and', u'obtained', u'error', u'rates', u'of', u'0.27', u'%', u'(', u'English', u')', u',', u'0.35', u'%', u'(', u'Dutch', u')', u'and', u'0.76', u'%', u'(', u'Italian', u')', u'for', u'our', u'best', u'models', u'.')

>>> for sent in tokenizer.tokenize_sents(sents): # doctest: +SKIP
...     print(sent)                              # doctest: +SKIP
...
(u'Tokenization', u'is', u'widely', u'regarded', u'as', u'a', u'solved', u'problem', u'due', u'to', u'the', u'high', u'accuracy', u'that', u'rulebased', u'tokenizers', u'achieve', u'.')
(u'But', u'rule-based', u'tokenizers', u'are', u'hard', u'to', u'maintain', u'and', u'their', u'rules', u'language', u'specific', u'.')
(u'We', u'evaluated', u'our', u'method', u'on', u'three', u'languages', u'and', u'obtained', u'error', u'rates', u'of', u'0.27', u'%', u'(', u'English', u')', u',', u'0.35', u'%', u'(', u'Dutch', u')', u'and', u'0.76', u'%', u'(', u'Italian', u')', u'for', u'our', u'best', u'models', u'.')
>>> for sent in tokenizer.tokenize_sents(sents, keep_token_positions=True): # doctest: +SKIP
...     print(sent)                                                         # doctest: +SKIP
...
[(u'Tokenization', 0, 12), (u'is', 13, 15), (u'widely', 16, 22), (u'regarded', 23, 31), (u'as', 32, 34), (u'a', 35, 36), (u'solved', 37, 43), (u'problem', 44, 51), (u'due', 52, 55), (u'to', 56, 58), (u'the', 59, 62), (u'high', 63, 67), (u'accuracy', 68, 76), (u'that', 77, 81), (u'rulebased', 82, 91), (u'tokenizers', 92, 102), (u'achieve', 103, 110), (u'.', 110, 111)]
[(u'But', 0, 3), (u'rule-based', 4, 14), (u'tokenizers', 15, 25), (u'are', 26, 29), (u'hard', 30, 34), (u'to', 35, 37), (u'maintain', 38, 46), (u'and', 47, 50), (u'their', 51, 56), (u'rules', 57, 62), (u'language', 63, 71), (u'specific', 72, 80), (u'.', 80, 81)]
[(u'We', 0, 2), (u'evaluated', 3, 12), (u'our', 13, 16), (u'method', 17, 23), (u'on', 24, 26), (u'three', 27, 32), (u'languages', 33, 42), (u'and', 43, 46), (u'obtained', 47, 55), (u'error', 56, 61), (u'rates', 62, 67), (u'of', 68, 70), (u'0.27', 71, 75), (u'%', 75, 76), (u'(', 77, 78), (u'English', 78, 85), (u')', 85, 86), (u',', 86, 87), (u'0.35', 88, 92), (u'%', 92, 93), (u'(', 94, 95), (u'Dutch', 95, 100), (u')', 100, 101), (u'and', 102, 105), (u'0.76', 106, 110), (u'%', 110, 111), (u'(', 112, 113), (u'Italian', 113, 120), (u')', 120, 121), (u'for', 122, 125), (u'our', 126, 129), (u'best', 130, 134), (u'models', 135, 141), (u'.', 141, 142)]
c                ór   € V P                  V4      V n        \        P                  ! 4       V n        W n        R # )N)Úfind_repptokenizerÚrepp_dirÚtempfileÚ
gettempdirÚworking_dirÚencoding)Úselfr
   r   s   &&&Ú4/usr/lib/python3/dist-packages/nltk/tokenize/repp.pyÚ__init__ÚReppTokenizer.__init__6   s*   € Ø×/Ñ/°Ó9ˆŒä#×.Ò.Ó0ˆÔà Žó    c                ó8   € \        V P                  V.4      4      # )z˜
Use Repp to tokenize a single sentence.

:param sentence: A single sentence string.
:type sentence: str
:return: A tuple of tokens.
:rtype: tuple(str)
)ÚnextÚtokenize_sents)r   Úsentences   &&r   ÚtokenizeÚReppTokenizer.tokenize=   s   € ô �D×'Ñ'¨¨
Ó3Ó4Ð4r   c              #  ó  "  € \         P                  ! RV P                  RRR7      ;_uu_ 4       pV F$  pVP                  \	        V4      R,           4       K&  	  VP                  4        V P                  VP                  4      pV P                  V4      P                  V P                  4      P                  4       pV P                  V4       F  pV'       g   \        V!  w  rxp	Vx € K  	  RRR4       R#   + '       g   i     R# ; i5i)z°
Tokenize multiple sentences using Repp.

:param sentences: A list of sentence strings.
:type sentences: list(str)
:return: A list of tuples of tokens
:rtype: iter(tuple(str))
zrepp_input.ÚwF)ÚprefixÚdirÚmodeÚdeleteÚ
N)r   ÚNamedTemporaryFiler   ÚwriteÚstrÚcloseÚgenerate_repp_commandÚnameÚ_executeÚdecoder   ÚstripÚparse_repp_outputsÚzip)
r   Ú	sentencesÚkeep_token_positionsÚ
input_fileÚsentÚcmdÚrepp_outputÚtokenized_sentÚstartsÚendss
   &&&       r   r   ÚReppTokenizer.tokenize_sentsH   sÕ   é € ô ×(Ò(Ø  d×&6Ñ&6¸SÈ÷
õ 
àã!�Ø× Ñ ¤ T£¨TÕ!1Ö2ñ "à×ÑÔà×,Ñ,¨Z¯_©_Ó=ˆCàŸ-™-¨Ó,×3Ñ3°D·M±MÓB×HÑHÓJˆKØ"&×"9Ñ"9¸+Ö"F�ß+ä36¸Ñ3GÑ0�N¨DØ$Ô$ñ	 #G÷
÷ 
÷ 
ò 
üs   ‚-D¯B>C7Ã-
DÃ7D	Ä	Dc                óŽ   € V P                   R,           .pVRV P                   R,           .,          pVRR.,          pW!.,          pV# )z‹
This module generates the REPP command to be used at the terminal.

:param inputfilename: path to the input file
:type inputfilename: str
ú	/src/reppz-cú/erg/repp.setz--formatÚtriple)r
   )r   Úinputfilenamer0   s   && r   r%   Ú#ReppTokenizer.generate_repp_commandb   sK   € ð �}‰}˜{Õ*Ð+ˆØ��d—m‘m oÕ5Ð6Õ6ˆØ�
˜HÐ%Õ%ˆØˆÕˆØˆ
r   c                ó”   € \         P                  ! V \         P                  \         P                  R 7      pVP                  4       w  r#V# ))ÚstdoutÚstderr)Ú
subprocessÚPopenÚPIPEÚcommunicate)r0   Úpr=   r>   s   &   r   r'   ÚReppTokenizer._executeo   s0   € ä×Ò˜S¬¯©ÄÇÁÔQˆØŸ™›‰ˆØˆr   c              #  ón  "  € \         P                  ! R\         P                  4      pV P                  R4       Fo  pVP	                  V4       UUUu. uF  w  r4pV\        V4      \        V4      3NK  	  pppp\        ;QJ d    . R V 4       F  NK  	  5M! R V 4       4      pVx € Kq  	  R# u upppi 5i)a  
This module parses the tri-tuple format that REPP outputs using the
"--format triple" option and returns an generator with tuple of string
tokens.

:param repp_output:
:type repp_output: type
:return: an iterable of the tokenized sentences as tuples of strings
:rtype: iter(tuple)
z^\((\d+), (\d+), (.+)\)$z

c              3   ó2   "  € T F  q^,          x € K  	  R# 5i)é   N© )Ú.0Úts   & r   Ú	<genexpr>Ú3ReppTokenizer.parse_repp_outputs.<locals>.<genexpr>‡   s   é € Ð=Ñ(< 1˜AŸ$š$Ó(<ùs   ‚N)ÚreÚcompileÚ	MULTILINEÚsplitÚfindallÚintÚtuple)r1   Ú
line_regexÚsectionÚstartÚendÚtokenÚwords_with_positionsÚwordss   &       r   r*   Ú ReppTokenizer.parse_repp_outputsu   sŸ   é € ô —Z’ZÐ ;¼R¿\¹\ÓJˆ
Ø"×(Ñ(¨Ö0ˆGð *4×);Ñ);¸GÔ)Dõ$á)DÑ%�E ð œ˜E›
¤C¨£HÓ-Ù)Dð !ò $÷ ”EÑ=Ñ(<Ó=—E‘EÑ=Ñ(<Ó=Ó=ˆEØ&Ô&ó 1ùô$ùs   ‚AB5Á#B.
Á4AB5c                ó(  € \         P                  P                  V4      '       d   TpM\        VRR7      p\         P                  P                  VR,           4      '       g   Q h\         P                  P                  VR,           4      '       g   Q hV# )zH
A module to find REPP tokenizer binary and its *repp.set* config file.
)Úenv_varsr7   r8   )ÚREPP_TOKENIZER)ÚosÚpathÚexistsr   )r   Úrepp_dirnameÚ	_repp_dirs   && r   r	   Ú ReppTokenizer.find_repptokenizerŠ   sk   € ô �7‰7�>‰>˜,×'Ò'Ø$‰Iä  Ð8KÔLˆIä�w‰w�~‰~˜i¨+Õ5×6Ò6Ð6Ð6Ü�w‰w�~‰~˜i¨/Õ9×:Ò:Ð:Ð:ØÐr   )r   r
   r   N)Úutf8)F)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r   r   r%   Ústaticmethodr'   r*   r	   Ú__static_attributes__Ú__classdictcell__)Ú__classdict__s   @r   r   r      sQ   ø‡ € ñô@!ò	5ô%ò4ð ñó ðð
 ñ'ó ð'÷(ð r   r   )r_   rM   r?   Úsysr   Ú	nltk.datar   Únltk.internalsr   Únltk.tokenize.apir   r   rH   r   r   Ú<module>rs      s-   ðó 
Û 	Û Û 
Û å (Ý #Ý (ô@�Jö @r   