
    Vh	                     J    d Z ddlmZ ddl  G d de      Z G d de      Zy)	a
  
CorpusReader for the Opinion Lexicon.

Opinion Lexicon information
===========================

Authors: 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.

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), Aug 22-25, 2004, Seattle, Washington, USA.

- Bing Liu, Minqing Hu and Junsheng Cheng. "Opinion Observer: Analyzing and
    Comparing Opinions on the Web". Proceedings of the 14th International World
    Wide Web conference (WWW-2005), May 10-14, 2005, Chiba, Japan.
    )WordListCorpusReader)*c                       e Zd ZdZd Zy)IgnoreReadmeCorpusViewzQ
    This CorpusView is used to skip the initial readme block of the corpus.
    c                     t        j                  | g|i | | j                          t        | j                         | j                  j                         g| _        y N)StreamBackedCorpusView__init___openread_blankline_block_streamtell_filepos)selfargskwargss      R/home/dcms/DCMS/lib/python3.12/site-packages/nltk/corpus/reader/opinion_lexicon.pyr
   zIgnoreReadmeCorpusView.__init__+   sF    ''>t>v>

T\\***,-    N)__name__
__module____qualname____doc__r
    r   r   r   r   &   s    .r   r   c                   .    e Zd ZdZeZddZd Zd Zd Z	y)OpinionLexiconCorpusReadera  
    Reader for Liu and Hu opinion lexicon.  Blank lines and readme are ignored.

        >>> from nltk.corpus import opinion_lexicon
        >>> opinion_lexicon.words()
        ['2-faced', '2-faces', 'abnormal', 'abolish', ...]

    The OpinionLexiconCorpusReader provides shortcuts to retrieve positive/negative
    words:

        >>> opinion_lexicon.negative()
        ['2-faced', '2-faces', 'abnormal', 'abolish', ...]

    Note that words from `words()` method are sorted by file id, not alphabetically:

        >>> opinion_lexicon.words()[0:10] # doctest: +NORMALIZE_WHITESPACE
        ['2-faced', '2-faces', 'abnormal', 'abolish', 'abominable', 'abominably',
        'abominate', 'abomination', 'abort', 'aborted']
        >>> sorted(opinion_lexicon.words())[0:10] # doctest: +NORMALIZE_WHITESPACE
        ['2-faced', '2-faces', 'a+', 'abnormal', 'abolish', 'abominable', 'abominably',
        'abominate', 'abomination', 'abort']
    Nc                     || j                   }nt        |t              r|g}t        | j	                  |dd      D cg c]$  \  }}}| j                  || j                  |      & c}}}      S c c}}}w )a^  
        Return all words in the opinion lexicon. Note that these words are not
        sorted in alphabetical order.

        :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)
        T)encoding)_fileids
isinstancestrconcatabspaths
CorpusView_read_word_block)r   fileidspathencfileids        r   wordsz OpinionLexiconCorpusReader.wordsO   sz     ?mmG%iG ,0==$+M 'T3 d&;&;cJ
 	
s   )A1c                 $    | j                  d      S )z
        Return all positive words in alphabetical order.

        :return: a list of positive words.
        :rtype: list(str)
        zpositive-words.txtr)   r   s    r   positivez#OpinionLexiconCorpusReader.positived        zz.//r   c                 $    | j                  d      S )z
        Return all negative words in alphabetical order.

        :return: a list of negative words.
        :rtype: list(str)
        znegative-words.txtr+   r,   s    r   negativez#OpinionLexiconCorpusReader.negativem   r.   r   c                     g }t        d      D ]4  }|j                         }|s|j                  |j                                6 |S )N   )rangereadlineappendstrip)r   streamr)   ilines        r   r$   z+OpinionLexiconCorpusReader._read_word_blockv   sE    r 	'A??$DLL&		'
 r   r   )
r   r   r   r   r   r#   r)   r-   r0   r$   r   r   r   r   r   5   s"    . (J
*00r   r   N)r   nltk.corpus.readerr   nltk.corpus.reader.apir	   r   r   r   r   r   <module>r<      s.   4 4 $.3 .H!5 Hr   