ķ <ŋCVc@s`dZddlmZddlmZddlTdefd„ƒYZdefd„ƒYZd S( sī CorpusReader for the Opinion Lexicon. - Opinion Lexicon information - Authors: Minqing Hu and Bing Liu, 2004. Department of Computer Sicence University of Illinois at Chicago Contact: Bing Liu, liub@cs.uic.edu http://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. i˙˙˙˙(t string_types(tWordListCorpusReader(t*tIgnoreReadmeCorpusViewcBseZdZd„ZRS(sQ This CorpusView is used to skip the initial readme block of the corpus. cOsCtj|||Ž|jƒt|jƒ|jjƒg|_dS(N(tStreamBackedCorpusViewt__init__t_opentread_blankline_blockt_streamttellt_filepos(tselftargstkwargs((st/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/corpus/reader/opinion_lexicon.pyR's  (t__name__t __module__t__doc__R(((st/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/corpus/reader/opinion_lexicon.pyR#stOpinionLexiconCorpusReadercBs;eZdZeZdd„Zd„Zd„Zd„Z RS(sn 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] ['2-faced', '2-faces', 'abnormal', 'abolish', 'abominable', 'abominably', 'abominate', 'abomination', 'abort', 'aborted'] >>> sorted(opinion_lexicon.words())[0:10] ['2-faced', '2-faces', 'a+', 'abnormal', 'abolish', 'abominable', 'abominably', 'abominate', 'abomination', 'abort'] cCs€|dkr|j}nt|tjƒr6|g}ntg|j|ttƒD]*\}}}|j||j d|ƒ^qOƒS(s^ 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) tencodingN( tNonet_fileidst isinstancetcompatRtconcattabspathstTruet CorpusViewt_read_word_block(R tfileidstpathtenctfileid((st/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/corpus/reader/opinion_lexicon.pytwordsKs  cCs |jdƒS(sˆ Return all positive words in alphabetical order. :return: a list of positive words. :rtype: list(str) spositive-words.txt(R (R ((st/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/corpus/reader/opinion_lexicon.pytpositiveZscCs |jdƒS(sˆ Return all negative words in alphabetical order. :return: a list of negative words. :rtype: list(str) snegative-words.txt(R (R ((st/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/corpus/reader/opinion_lexicon.pytnegativecscCsLg}x?tdƒD]1}|jƒ}|s1qn|j|jƒƒqW|S(Ni(trangetreadlinetappendtstrip(R tstreamR titline((st/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/corpus/reader/opinion_lexicon.pyRls N( RRRRRRR R!R"R(((st/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/corpus/reader/opinion_lexicon.pyR1s   N( Rt nltk.compatRtnltk.corpus.readerRtnltk.corpus.reader.apiRRR(((st/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/corpus/reader/opinion_lexicon.pyts