+
    ÖÇÜhÖ.  ã                   óô   € R t ^ RIt^ RI5 ^ RI5 ]P                  ! R4      t]P                  ! R4      t]P                  ! R4      t]P                  ! R4      t ! R R4      t	 ! R	 R
4      t
 ! R R]4      tR# )a	  
CorpusReader for reviews corpora (syntax based on Customer Review Corpus).

Customer Review Corpus information
==================================

Annotated by: Minqing Hu and Bing Liu, 2004.
    Department of Computer Science
    University of Illinois at Chicago

Contact: Bing Liu, liub@cs.uic.edu
        https://www.cs.uic.edu/~liub

Distributed with permission.

The "product_reviews_1" and "product_reviews_2" datasets respectively contain
annotated customer reviews of 5 and 9 products from amazon.com.

Related papers:

- Minqing Hu and Bing Liu. "Mining and summarizing customer reviews".
    Proceedings of the ACM SIGKDD International Conference on Knowledge
    Discovery & Data Mining (KDD-04), 2004.

- Minqing Hu and Bing Liu. "Mining Opinion Features in Customer Reviews".
    Proceedings of Nineteeth National Conference on Artificial Intelligence
    (AAAI-2004), 2004.

- Xiaowen Ding, Bing Liu and Philip S. Yu. "A Holistic Lexicon-Based Appraoch to
    Opinion Mining." Proceedings of First ACM International Conference on Web
    Search and Data Mining (WSDM-2008), Feb 11-12, 2008, Stanford University,
    Stanford, California, USA.

Symbols used in the annotated reviews:

    :[t]: the title of the review: Each [t] tag starts a review.
    :xxxx[+|-n]: xxxx is a product feature.
    :[+n]: Positive opinion, n is the opinion strength: 3 strongest, and 1 weakest.
           Note that the strength is quite subjective.
           You may want ignore it, but only considering + and -
    :[-n]: Negative opinion
    :##:   start of each sentence. Each line is a sentence.
    :[u]:  feature not appeared in the sentence.
    :[p]:  feature not appeared in the sentence. Pronoun resolution is needed.
    :[s]:  suggestion or recommendation.
    :[cc]: comparison with a competing product from a different brand.
    :[cs]: comparison with a competing product from the same brand.

Note: Some of the files (e.g. "ipod.txt", "Canon PowerShot SD500.txt") do not
    provide separation between different reviews. This is due to the fact that
    the dataset was specifically designed for aspect/feature-based sentiment
    analysis, for which sentence-level annotation is sufficient. For document-
    level classification and analysis, this peculiarity should be taken into
    consideration.
N)Ú*z^\[t\](.*)$z%((?:(?:\w+\s)+)?\w+)\[((?:\+|\-)\d)\]z\[(?!t)(p|u|s|cc|cs)\]z##(.*)$c                   óF   a € ] tR t^Mt o RtR	R ltR tR tR tR t	Rt
V tR# )
ÚReviewz6
A Review is the main block of a ReviewsCorpusReader.
Nc                ó8   € Wn         Vf
   . V n        R# W n        R# )zt
:param title: the title of the review.
:param review_lines: the list of the ReviewLines that belong to the Review.
N)ÚtitleÚreview_lines)Úselfr   r   s   &&&Ú</usr/lib/python3/dist-packages/nltk/corpus/reader/reviews.pyÚ__init__ÚReview.__init__R   s   € ð
 Œ
ØÒØ "ˆDÖà ,Öó    c                ól   € \        V\        4      '       g   Q hV P                  P                  V4       R# )zo
Add a line (ReviewLine) to the review.

:param review_line: a ReviewLine instance that belongs to the Review.
N)Ú
isinstanceÚ
ReviewLiner   Úappend©r   Úreview_lines   &&r	   Úadd_lineÚReview.add_line]   s+   € ô ˜+¤z×2Ò2Ð2Ð2Ø×Ñ× Ñ  Ö-r   c                óf   € . pV P                    F  pVP                  VP                  4       K   	  V# )zí
Return a list of features in the review. Each feature is a tuple made of
the specific item feature and the opinion strength about that feature.

:return: all features of the review as a list of tuples (feat, score).
:rtype: list(tuple)
)r   ÚextendÚfeatures)r   r   r   s   &  r	   r   ÚReview.featuresf   s0   € ð ˆØ×,Ô,ˆKØ�O‰O˜K×0Ñ0Ö1ñ -àˆr   c                óV   € V P                    Uu. uF  qP                  NK  	  up# u upi )z�
Return all tokenized sentences in the review.

:return: all sentences of the review as lists of tokens.
:rtype: list(list(str))
)r   Úsentr   s   & r	   ÚsentsÚReview.sentss   s(   € ð 59×4EÒ4EÓFÑ4E [× Ô Ñ4EÑFÐFùÒFs   �&c                óN   € R P                  V P                  V P                  4      # )z#Review(title="{}", review_lines={}))Úformatr   r   ©r   s   &r	   Ú__repr__ÚReview.__repr__|   s$   € Ø4×;Ñ;Ø�J‰J˜×)Ñ)ó
ð 	
r   )r   r   ©NN)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r
   r   r   r   r    Ú__static_attributes__Ú__classdictcell__©Ú__classdict__s   @r	   r   r   M   s)   ø‡ € ñô	-ò.òòG÷
ð 
r   r   c                   ó4   a € ] tR t^‚t o RtRR ltR tRtV tR# )r   z‹
A ReviewLine represents a sentence of the review, together with (optional)
annotations of its features and notes about the reviewed item.
Nc                ó\   € Wn         Vf	   . V n        MW n        Vf
   . V n        R # W0n        R # ©N©r   r   Únotes)r   r   r   r0   s   &&&&r	   r
   ÚReviewLine.__init__ˆ   s*   € ØŒ	ØÒØˆD�Mà$ŒMàŠ=ØˆDŽJàŽJr   c                ód   € R P                  V P                  V P                  V P                  4      # )z*ReviewLine(features={}, notes={}, sent={}))r   r   r0   r   r   s   &r	   r    ÚReviewLine.__repr__”   s(   € Ø;×BÑBØ�M‰M˜4Ÿ:™: t§y¡yó
ð 	
r   )r   r0   r   r"   )	r#   r$   r%   r&   r'   r
   r    r(   r)   r*   s   @r	   r   r   ‚   s   ø‡ € ñô

÷
ð 
r   r   c                   ó€   a € ] tR t^št o Rt]t]! 4       R3R ltRR lt	RR lt
RR ltRR ltR	 tR
 tR tR tRtV tR# )ÚReviewsCorpusReaderaR  
Reader for the Customer Review Data dataset by Hu, Liu (2004).
Note: we are not applying any sentence tokenization at the moment, just word
tokenization.

    >>> from nltk.corpus import product_reviews_1
    >>> camera_reviews = product_reviews_1.reviews('Canon_G3.txt')
    >>> review = camera_reviews[0]
    >>> review.sents()[0] # doctest: +NORMALIZE_WHITESPACE
    ['i', 'recently', 'purchased', 'the', 'canon', 'powershot', 'g3', 'and', 'am',
    'extremely', 'satisfied', 'with', 'the', 'purchase', '.']
    >>> review.features() # doctest: +NORMALIZE_WHITESPACE
    [('canon powershot g3', '+3'), ('use', '+2'), ('picture', '+2'),
    ('picture quality', '+1'), ('picture quality', '+1'), ('camera', '+2'),
    ('use', '+2'), ('feature', '+1'), ('picture quality', '+3'), ('use', '+1'),
    ('option', '+1')]

We can also reach the same information directly from the stream:

    >>> product_reviews_1.features('Canon_G3.txt')
    [('canon powershot g3', '+3'), ('use', '+2'), ...]

We can compute stats for specific product features:

    >>> n_reviews = len([(feat,score) for (feat,score) in product_reviews_1.features('Canon_G3.txt') if feat=='picture'])
    >>> tot = sum([int(score) for (feat,score) in product_reviews_1.features('Canon_G3.txt') if feat=='picture'])
    >>> mean = tot / n_reviews
    >>> print(n_reviews, tot, mean)
    15 24 1.6
Úutf8c                óL   € \         P                  WW$4       W0n        RV n        R# )a4  
:param root: The root directory for the corpus.
:param fileids: a list or regexp specifying the fileids in the corpus.
:param word_tokenizer: a tokenizer for breaking sentences or paragraphs
    into words. Default: `WordPunctTokenizer`
:param encoding: the encoding that should be used to read the corpus.
z
README.txtN)ÚCorpusReaderr
   Ú_word_tokenizerÚ_readme)r   ÚrootÚfileidsÚword_tokenizerÚencodings   &&&&&r	   r
   ÚReviewsCorpusReader.__init__¼   s!   € ô 	×Ñ˜d¨'Ô<Ø-ÔØ#ˆŽr   Nc                óö   € Vf   V P                   pM\        V\        4      '       d   V.p\        V P	                  VR4       UUu. uF"  w  r#V P                  W P                  VR7      NK$  	  upp4      # u uppi )a=  
Return a list of features. Each feature is a tuple made of the specific
item feature and the opinion strength about that feature.

:param fileids: a list or regexp specifying the ids of the files whose
    features have to be returned.
:return: all features for the item(s) in the given file(s).
:rtype: list(tuple)
T©r>   )Ú_fileidsr   ÚstrÚconcatÚabspathsÚ
CorpusViewÚ_read_features©r   r<   ÚfileidÚencs   &&  r	   r   ÚReviewsCorpusReader.featuresË   su   € ð Š?Ø—m‘m‰GÜ˜¤×%Ò%Ø�iˆGÜð &*§]¡]°7¸DÔ%Aôá%A‘M�Vð —‘ ×(;Ñ(;Àc�ÖJÙ%Aòó
ð 	
ùós   Á(A5
c                óÂ   € Vf   V P                   p\        V P                  VR4       UUu. uF"  w  r#V P                  W P                  VR7      NK$  	  upp4      # u uppi )a#  
Return all the reviews as a list of Review objects. If `fileids` is
specified, return all the reviews from each of the specified files.

:param fileids: a list or regexp specifying the ids of the files whose
    reviews have to be returned.
:return: the given file(s) as a list of reviews.
TrA   )rB   rD   rE   rF   Ú_read_review_blockrH   s   &&  r	   ÚreviewsÚReviewsCorpusReader.reviewsà   sa   € ð Š?Ø—m‘mˆGÜð &*§]¡]°7¸DÔ%Aôá%A‘M�Vð —‘ ×(?Ñ(?È#�ÖNÙ%Aòó
ð 	
ùós   «(A
c                ó¬   € \        V P                  VRR4       UUUu. uF#  w  r#pV P                  W P                  VR7      NK%  	  uppp4      # u upppi )a!  
Return all sentences in the corpus or in the specified files.

:param fileids: a list or regexp specifying the ids of the files whose
    sentences have to be returned.
:return: the given file(s) as a list of sentences, each encoded as a
    list of word strings.
:rtype: list(list(str))
TrA   )rD   rE   rF   Ú_read_sent_block©r   r<   ÚpathrJ   rI   s   &&   r	   r   ÚReviewsCorpusReader.sentsò   óX   € ô ð ,0¯=©=¸À$ÈÔ+Mõá+MÑ'�T ð —‘ ×&;Ñ&;Àc�ÖJÙ+Móó
ð 	
ùôó   �)Ac                ó¬   € \        V P                  VRR4       UUUu. uF#  w  r#pV P                  W P                  VR7      NK%  	  uppp4      # u upppi )a  
Return all words and punctuation symbols in the corpus or in the specified
files.

:param fileids: a list or regexp specifying the ids of the files whose
    words have to be returned.
:return: the given file(s) as a list of words and punctuation symbols.
:rtype: list(str)
TrA   )rD   rE   rF   Ú_read_word_blockrR   s   &&   r	   ÚwordsÚReviewsCorpusReader.words  rU   rV   c                óº   € . p\        ^4       FI  pVP                  4       pV'       g   Vu # VP                  \        P                  ! \
        V4      4       KK  	  V# ©é   )ÚrangeÚreadliner   ÚreÚfindallÚFEATURES)r   Ústreamr   ÚiÚlines   &&   r	   rG   Ú"ReviewsCorpusReader._read_features  sG   € ØˆÜ�r–ˆAØ—?‘?Ó$ˆDßØ’Ø�O‰OœBŸJšJ¤x°Ó6Ö7ñ	 ð
 ˆr   c                óÎ  €  VP                  4       pV'       g   . # \        P                  ! \        V4      pV'       g   K@  \	        VP                  ^4      P                  4       R7      p  TP                  4       pTP                  4       pT'       g   T.# \        P                  ! \        T4      '       d   TP                  T4       T.# \        P                  ! \        T4      p\        P                  ! \        T4      p\        P                  ! \        T4      pT'       d#   T P                  P                  T^ ,          4      p\        Y†TR7      p	TP!                  T	4       Kü  )T)r   r/   )r_   r`   ÚmatchÚTITLEr   ÚgroupÚstripÚtellÚseekra   rb   ÚNOTESÚSENTr9   Útokenizer   r   )
r   rc   re   Útitle_matchÚreviewÚoldposÚfeatsr0   r   r   s
   &&        r	   rM   Ú&ReviewsCorpusReader._read_review_block  s  € ØØ—?‘?Ó$ˆDßØ�	ÜŸ(š(¤5¨$Ó/ˆKß‰{ÜØ%×+Ñ+¨AÓ.×4Ñ4Ó6ô�ð ð Ø—[‘[“]ˆFØ—?‘?Ó$ˆDçØ�x�ô �xŠxœ˜t×$Ò$Ø—‘˜FÔ#Ø�x�ä—J’Jœx¨Ó.ˆEÜ—J’Jœu dÓ+ˆEÜ—:’:œd DÓ)ˆDßØ×+Ñ+×4Ñ4°T¸!µWÓ=�Ü$¨$ÀeÔLˆKØ�O‰O˜KÖ(r   c                ó    € . pV P                  V4       F1  pTP                  VP                  4        Uu. uF  qDNK  	  up4       K3  	  V# u upi r.   )rM   r   r   )r   rc   r   rr   r   s   &&   r	   rQ   Ú$ReviewsCorpusReader._read_sent_block>  sG   € ØˆØ×-Ñ-¨fÖ5ˆFØ�L‰L¨6¯<©<¬>Ó:©> 4š$©>Ñ:Ö;ñ 6àˆùò ;s   ´
A
c                óú   € . p\        ^4       Fi  pVP                  4       p\        P                  ! \        V4      pV'       g   K8  VP                  V P                  P                  V^ ,          4      4       Kk  	  V# r\   )r^   r_   r`   ra   ro   r   r9   rp   )r   rc   rY   rd   re   r   s   &&    r	   rX   Ú$ReviewsCorpusReader._read_word_blockD  s^   € ØˆÜ�r–ˆAØ—?‘?Ó$ˆDÜ—:’:œd DÓ)ˆDß‰tØ—‘˜T×1Ñ1×:Ñ:¸4À½7ÓCÖDñ	 ð
 ˆr   )r:   r9   r.   )r#   r$   r%   r&   r'   ÚStreamBackedCorpusViewrF   ÚWordPunctTokenizerr
   r   rN   r   rY   rG   rM   rQ   rX   r(   r)   r*   s   @r	   r5   r5   š   sN   ø‡ € ñð> (€Jñ -?Ó,@È6ô$ô
ô*
ô$
ô"
ò"ò)òB÷ð r   r5   )r'   r`   Únltk.corpus.reader.apiÚnltk.tokenizeÚcompileri   rb   rn   ro   r   r   r8   r5   © r   r	   Ú<module>r€      sw   ðñ6óp 
ä $Ü à
�
Š
�>Ó"€Ø�:Š:Ø,ó€ð 	�
Š
Ð,Ó-€Ø	‡z‚z�*Ó€÷2
ñ 2
÷j
ñ 
ô0q˜,ö qr   