+
    ÖÇÜh>  ã                   ó„   € R t ^ RIt^ RIHt ^ RIHt ^ RI5 ^ RIHt ^ RI	H
t
 ^ RIHt  ! R R	]4      t ! R
 R]4      tR# )z‚
Corpus reader for corpora whose documents are xml files.

(note -- not named 'xml' to avoid conflicting w/ standard xml package)
N)ÚElementTree)ÚCorpusReader)Ú*)ÚSeekableUnicodeStreamReader)ÚElementWrapper)ÚWordPunctTokenizerc                   óB   a € ] tR t^t o RtRR ltRR ltRR ltRtV t	R# )	ÚXMLCorpusReaderzú
Corpus reader for corpora whose documents are xml files.

Note that the ``XMLCorpusReader`` constructor does not take an
``encoding`` argument, because the unicode encoding is specified by
the XML files themselves.  See the XML specs for more info.
c                ó@   € W0n         \        P                  ! WV4       R # ©N)Ú_wrap_etreer   Ú__init__)ÚselfÚrootÚfileidsÚ
wrap_etrees   &&&&Ú</usr/lib/python3/dist-packages/nltk/corpus/reader/xmldocs.pyr   ÚXMLCorpusReader.__init__!   s   € Ø%ÔÜ×Ò˜d¨'Ö2ó    Nc                ó²  € Vf.   \        V P                  4      ^8X  d   V P                  ^ ,          p\        V\        4      '       g   \	        R4      hV P                  V4      P                  4       ;_uu_ 4       p\        P                  ! V4      P                  4       pR R R 4       V P                  '       d   \        X4      pX#   + '       g   i     L/; i)Nz(Expected a single file identifier string)ÚlenÚ_fileidsÚ
isinstanceÚstrÚ	TypeErrorÚabspathÚopenr   ÚparseÚgetrootr   r   )r   ÚfileidÚfpÚelts   &&  r   ÚxmlÚXMLCorpusReader.xml%   sœ   € àŠ>œc $§-¡-Ó0°AÔ5Ø—]‘] 1Õ%ˆFÜ˜&¤#×&Ò&ÜÐFÓGÐGà�\‰\˜&Ó!×&Ñ&×(Ô(¨BÜ×#Ò# BÓ'×/Ñ/Ó1ˆC÷ )ð ××ÐÜ  Ó%ˆCàˆ
÷ )×(ús   Á:%CÃC	c                óz  € V P                  V4      pV P                  V4      p\        4       p VP                  4       p. pT F^  pTP
                  pTf   K  \        T\        4      '       d   TP                  T4      pTP                  T4      p	TP                  T	4       K`  	  T#    TP	                  4       p L|; i)a  
Returns all of the words and punctuation symbols in the specified file
that were in text nodes -- ie, tags are ignored. Like the xml() method,
fileid can only specify one file.

:return: the given file's text nodes as a list of words and punctuation symbols
:rtype: list(str)
)r"   Úencodingr   ÚgetiteratorÚiterÚtextr   ÚbytesÚdecodeÚtokenizeÚextend)
r   r   r!   r%   Úword_tokenizerÚiteratorÚoutÚnoder(   Útokss
   &&        r   ÚwordsÚXMLCorpusReader.words4   s©   € ð �h‰h�vÓˆØ—=‘= Ó(ˆÜ+Ó-ˆð	"Ø—‘Ó(ˆHð ˆãˆDØ—9‘9ˆDØÔÜ˜d¤E×*Ò*ØŸ;™; xÓ0�DØ%×.Ñ.¨tÓ4�Ø—
‘
˜4Ö ñ ð ˆ
øð	"Ø—x‘x“zŠHús   ®B& Â&B:)r   )Fr   )
Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r"   r2   Ú__static_attributes__Ú__classdictcell__©Ú__classdict__s   @r   r	   r	      s   ø‡ € ñô3ô÷ò r   r	   c                   ó(  a € ] tR t^Qt o RtRtRtRR ltR tR t	]
P                  R]
P                  ]
P                  ,          4      t]
P                  R	4      t]
P                  R
]
P                  ]
P                  ,          4      tR tRR ltRtV tR# )ÚXMLCorpusViewa  
A corpus view that selects out specified elements from an XML
file, and provides a flat list-like interface for accessing them.
(Note: ``XMLCorpusView`` is not used by ``XMLCorpusReader`` itself,
but may be used by subclasses of ``XMLCorpusReader``.)

Every XML corpus view has a "tag specification", indicating what
XML elements should be included in the view; and each (non-nested)
element that matches this specification corresponds to one item in
the view.  Tag specifications are regular expressions over tag
paths, where a tag path is a list of element tag names, separated
by '/', indicating the ancestry of the element.  Some examples:

  - ``'foo'``: A top-level element whose tag is ``foo``.
  - ``'foo/bar'``: An element whose tag is ``bar`` and whose parent
    is a top-level element whose tag is ``foo``.
  - ``'.*/foo'``: An element whose tag is ``foo``, appearing anywhere
    in the xml tree.
  - ``'.*/(foo|bar)'``: An wlement whose tag is ``foo`` or ``bar``,
    appearing anywhere in the xml tree.

The view items are generated from the selected XML elements via
the method ``handle_elt()``.  By default, this method returns the
element as-is (i.e., as an ElementTree object); but it can be
overridden, either via subclassing or via the ``elt_handler``
constructor parameter.
Fi   Nc                óÊ   € V'       d   W0n         \        P                  VR,           4      V n         ^ R/V n         V P                  V4      p\        P                  WVR7       R# )aß  
Create a new corpus view based on a specified XML file.

Note that the ``XMLCorpusView`` constructor does not take an
``encoding`` argument, because the unicode encoding is
specified by the XML files themselves.

:type tagspec: str
:param tagspec: A tag specification, indicating what XML
    elements should be included in the view.  Each non-nested
    element that matches this specification corresponds to one
    item in the view.

:param elt_handler: A function used to transform each element
    to a value for the view.  If no handler is specified, then
    ``self.handle_elt()`` is called, which returns the element
    as an ElementTree object.  The signature of elt_handler is::

        elt_handler(elt, tagspec) -> value
z\Z)r%   N© )Ú
handle_eltÚreÚcompileÚ_tagspecÚ_tag_contextÚ_detect_encodingÚStreamBackedCorpusViewr   )r   r   ÚtagspecÚelt_handlerr%   s   &&&& r   r   ÚXMLCorpusView.__init__u   sY   € ÷* Ø)ŒOäŸ
™
 7¨U¥?Ó3ˆŒØ9à ˜GˆÔð	ð
 ×(Ñ(¨Ó0ˆÜ×'Ñ'¨¸xÐ'ÖHr   c                ó¼  € \        V\        4      '       d3    VP                  4       pVP                  4       pVP	                  4        M-\        VR 4      ;_uu_ 4       pVP                  4       pRRR4       XP                  \        P                  4      '       d   R# VP                  \        P                  4      '       d   R# VP                  \        P                  4      '       d   R# VP                  \        P                  4      '       d   R# VP                  \        P                  4      '       d   R# \        P                  RV4      pV'       d    VP                  ^4      P                  4       # \        P                  RV4      pV'       d    VP                  ^4      P                  4       # R#   XP	                  4        i ; i  + '       g   i     ELe; i)	ÚrbNz	utf-16-bez	utf-16-lez	utf-32-bez	utf-32-lezutf-8s!   \s*<\?xml\b.*\bencoding="([^"]+)"s!   \s*<\?xml\b.*\bencoding='([^']+)')r   ÚPathPointerr   ÚreadlineÚcloseÚ
startswithÚcodecsÚBOM_UTF16_BEÚBOM_UTF16_LEÚBOM_UTF32_BEÚBOM_UTF32_LEÚBOM_UTF8rB   ÚmatchÚgroupr*   )r   r   ÚinfileÚsÚms   &&   r   rF   ÚXMLCorpusView._detect_encoding™   s:  € Ü�fœk×*Ò*ðØŸ™›�Ø—O‘OÓ%�à—‘•ä�f˜d×#Ô# vØ—O‘OÓ%�÷ $à�<‰<œ×+Ñ+×,Ò,ÙØ�<‰<œ×+Ñ+×,Ò,ÙØ�<‰<œ×+Ñ+×,Ò,ÙØ�<‰<œ×+Ñ+×,Ò,ÙØ�<‰<œŸ™×(Ò(ÙÜ�H‰HÐ:¸AÓ>ˆßØ—7‘7˜1“:×$Ñ$Ó&Ð&Ü�H‰HÐ:¸AÓ>ˆßØ—7‘7˜1“:×$Ñ$Ó&Ð&áøð+ —‘•úç#×#Ð#ús   ˜ F5 ÁG
Æ5GÇ
G	c                ó   € V# )a—  
Convert an element into an appropriate value for inclusion in
the view.  Unless overridden by a subclass or by the
``elt_handler`` constructor argument, this method simply
returns ``elt``.

:return: The view value corresponding to ``elt``.

:type elt: ElementTree
:param elt: The element that should be converted.

:type context: str
:param context: A string composed of element tags separated by
    forward slashes, indicating the XML context of the given
    element.  For example, the string ``'foo/bar/baz'``
    indicates that the element is a ``baz`` element whose
    parent is a ``bar`` element and whose grandparent is a
    top-level ``foo`` element.
r@   )r   r!   Úcontexts   &&&r   rA   ÚXMLCorpusView.handle_elt¶   s	   € ð( ˆ
r   a;  
        [^<]*
        (
          ((<!--.*?-->)                         |  # comment
           (<![CDATA[.*?]])                     |  # raw character data
           (<!DOCTYPE\s+[^\[]*(\[[^\]]*])?\s*>) |  # doctype decl
           (<[^!>][^>]*>))                         # tag or PI
          [^<]*)*
        \Zz<\s*(?:/\s*)?([^\s>]+)a6  
        # Include these so we can skip them:
        (?P<COMMENT>        <!--.*?-->                          )|
        (?P<CDATA>          <![CDATA[.*?]]>                     )|
        (?P<PI>             <\?.*?\?>                           )|
        (?P<DOCTYPE>        <!DOCTYPE\s+[^\[^>]*(\[[^\]]*])?\s*>)|
        # These are the ones we actually care about:
        (?P<EMPTY_ELT_TAG>  <\s*[^>/\?!\s][^>]*/\s*>            )|
        (?P<START_TAG>      <\s*[^>/\?!\s][^>]*>                )|
        (?P<END_TAG>        <\s*/[^>/\?!\s][^>]*>               )c                óT  € Rp\        V\        4      '       d   VP                  4       p VP                  V P                  4      pW$,          pV P
                  P                  V4      '       d   V# \        P                  RV4      P                  ^ 4      R8X  d\   VP                  4       \        V4      \        P                  RV4      P                  4       ,
          ,
          p\        RV,          4      hV'       g   \        R4      hVP                  R4      pV^ 8”  g   Kù  V P
                  P                  VRV 4      '       g   EK   \        V\        4      '       d$   VP                  X4       VP                  V4       M#VP                  \        V4      V,
          ) ^4       VRV # )aC  
Read a string from the given stream that does not contain any
un-closed tags.  In particular, this function first reads a
block from the stream of size ``self._BLOCK_SIZE``.  It then
checks if that block contains an un-closed tag.  If it does,
then this function either backtracks to the last '<', or reads
another block.
Ú z[<>]Ú>zUnexpected ">" near char %sz&Unexpected end of file: tag not closedÚ<N)r   r   ÚtellÚreadÚ_BLOCK_SIZEÚ_VALID_XML_RErW   rB   ÚsearchrX   r   ÚendÚ
ValueErrorÚrfindÚseekÚchar_seek_forward)r   ÚstreamÚfragmentÚstartposÚ	xml_blockÚposÚlast_open_brackets   &&     r   Ú_read_xml_fragmentÚ XMLCorpusView._read_xml_fragmentñ   s_  € ð ˆä�fÔ9×:Ò:Ø—{‘{“}ˆHØàŸ™ D×$4Ñ$4Ó5ˆIØÕ!ˆHð ×!Ñ!×'Ñ'¨×1Ò1Ø�ô �y‰y˜ Ó*×0Ñ0°Ó3°sÔ:Ø—k‘k“mÜ˜“M¤B§I¡I¨f°hÓ$?×$CÑ$CÓ$EÕEõ�ô !Ð!>ÀÕ!DÓEÐE÷ Ü Ð!IÓJÐJð
 !)§¡¨sÓ 3ÐØ  1Ö$Ø×%Ñ%×+Ñ+¨HÐ5GÐ6GÐ,H×IÕIÜ! &Ô*E×FÒFØŸ™ HÔ-Ø×0Ñ0Ð1BÕCàŸ™¤c¨(£mÐ6GÕ&GÐ$HÈ!ÔLØ#Ð$6Ð%6Ð7Ð7r   c                óê	  € Vf   V P                   pVf   V P                  p\        V P                  P	                  VP                  4       4      4      pVf   Q h. pRpRpRpV. 8X  g   VEeæ   \        V\        4      '       d   VP                  4       p	V P                  V4      p
V
'       g   Vf   EM \        R4      hV P                  P                  V
4       EFÊ  pV P                  '       d<   \        RP                  RP                  V4      RR VP!                  4       4      4       VP!                  R4      '       d›   V P"                  P%                  VP!                  4       4      P!                  ^4      pVP'                  V4       VfK   \(        P%                  VRP                  V4      4      '       d   VP+                  4       p\-        V4      pKý  Kÿ  EK  VP!                  R4      '       dß   V P"                  P%                  VP!                  4       4      P!                  ^4      pV'       g   \        RV,          4      hWÄR,          8w  d   \        R	VR,           R
V R24      hVeP   V\-        V4      8X  d@   WŠWkP/                  4        ,          pVP'                  VRP                  V4      34       R;rgRpVP1                  4        EK÷  VP!                  R4      '       g   EK  V P"                  P%                  VP!                  4       4      P!                  ^4      pVe   EKP  \(        P%                  VRP                  V4      R,           V,           4      '       g   EKŒ  VP'                  VP!                  4       RP                  V4      R,           V,           34       EKÍ  	  Vf   EKM  V. 8X  d   WŠVR ,          p^ pEKd  V P                  '       d   \        R4       \        V\        4      '       d$   VP3                  X	4       VP5                  V4       M#VP3                  \-        V
4      V,
          ) ^4       VRV^,
           pR;rgRpEKñ  VP                  4       pWÐP                  9   d%   \7        V4      V P                  V,          8X  g   Q hM\7        V4      V P                  V&   V UUu. uF2  w  räV! \8        P:                  ! VP=                  RR4      4      V4      NK4  	  upp# u uppi )zœ
Read from ``stream`` until we find at least one element that
matches ``tagspec``, and return the result of applying
``elt_handler`` to each element found.
Nra   zUnexpected end of filez	{:>25} {}Ú/Ú	START_TAGÚEND_TAGzUnmatched tag </%s>zUnmatched tag <z>...</rb   ÚEMPTY_ELT_TAGÚasciiÚxmlcharrefreplaceiìÿÿÿéÿÿÿÿz/                                    (backtrack))rD   rA   ÚlistrE   Úgetrd   r   r   rt   rj   Ú
_XML_PIECEÚfinditerÚ_DEBUGÚprintÚformatÚjoinrX   Ú_XML_TAG_NAMErW   ÚappendrB   Ústartr   ri   Úpoprl   rm   Útupler   Ú
fromstringÚencode)r   rn   rH   rI   r^   ÚeltsÚ	elt_startÚ	elt_depthÚelt_textrp   Úxml_fragmentÚpieceÚnamerr   r!   s   &&&&           r   Ú
read_blockÚXMLCorpusView.read_block"  s  € ð Š?Ø—m‘mˆGØÒØŸ/™/ˆKô �t×(Ñ(×,Ñ,¨V¯[©[«]Ó;Ó<ˆØÒ"Ð"Ð"àˆàˆ	Øˆ	Øˆà�bŒj˜IÓ1Ü˜&Ô"=×>Ò>Ø!Ÿ;™;›=�Ø×2Ñ2°6Ó:ˆL÷  ØÒ$Ùä$Ð%=Ó>Ð>ð Ÿ™×1Ñ1°,×?�Ø—;—;�;Ü˜+×,Ñ,¨S¯X©X°gÓ->¸s¸tÐ-DÀeÇkÁkÃmÓTÔUà—;‘;˜{×+Ò+Ø×-Ñ-×3Ñ3°E·K±K³MÓB×HÑHÈÓK�Dà—N‘N 4Ô(à Ò(ÜŸ8™8 G¨S¯X©X°gÓ->×?Ò?Ø(-¯©«˜IÜ(+¨G«šIñ @ò )ð
 —[‘[ ×+Ò+Ø×-Ñ-×3Ñ3°E·K±K³MÓB×HÑHÈÓK�Dç"Ü(Ð)>ÀÕ)EÓFÐFØ r�{Ô*Ü(¨?¸7À2½;¸-ÀvÈdÈVÐSTÐ)UÓVÐVà Ò,°¼cÀ'»lÔ1JØ °¿Y¹Y»[Ð$IÕI˜ØŸ™ X¨s¯x©x¸Ó/@Ð$AÔBØ04Ð4˜	Ø#%˜à—K‘K—Mà—[‘[ ×1Õ1Ø×-Ñ-×3Ñ3°E·K±K³MÓB×HÑHÈÓK�DØ Õ(ÜŸ8™8 G¨S¯X©X°gÓ->ÀÕ-DÀtÕ-K×LÕLØ ŸK™K¨¯©«¸¿¹ÀÓ8IÈCÕ8OÐRVÕ8VÐ(W×XñE @ðH Õ$ð ˜2”:Ø¨Y¨ZÐ 8Õ8�HØ !“Ið —{—{�{ÜÐ6Ô7Ü! &Ô*E×FÒFØŸ™ HÔ-Ø×0Ñ0°Õ;àŸ™¤c¨,Ó&7¸)Õ&CÐ$DÀaÔHØ% o¨	°A­Ð6�GØ,0Ð0�IØ!“Hð �k‰k‹mˆØ×#Ñ#Ô#Ü˜“> T×%6Ñ%6°sÕ%;Ô;Ð;Ñ;ä%*¨7£^ˆD×Ñ˜cÑ"ñ #'ô
ñ
 #'‘�ñ	 Ü×&Ò& s§z¡z°'Ð;NÓ'OÓPØöñ #'ò
ð 	
ùó 
s   Ò38S/)rE   rD   rA   r   )NN)r4   r5   r6   r7   r8   r‚   rf   r   rF   rA   rB   rC   ÚDOTALLÚVERBOSErg   r†   r€   rt   r”   r9   r:   r;   s   @r   r>   r>   Q   s›   ø‡ € ñð< €Fð €Kô"IòHò:ð0 —J‘Jð	ð 	�	‰	�B—J‘JÕó€Mð —J‘JÐ8Ó9€Mð —‘ð		Eð 	�	‰	�B—J‘JÕó€Jò,8÷bk
ò k
r   r>   )r8   rQ   Ú	xml.etreer   Únltk.corpus.reader.apir   Únltk.corpus.reader.utilÚ	nltk.datar   Únltk.internalsr   Únltk.tokenizer   r	   rG   r>   r@   r   r   Ú<module>rž      s=   ðñó Ý !å /Ü %Ý 1Ý )Ý ,ô6�lô 6ôr|
Ð*ö |
r   