ó <¿CVc@sCdZddlZddlTddlTdeefd„ƒYZdS(s‡ CorpusReader for the Pros and Cons dataset. - Pros and Cons dataset information - Contact: Bing Liu, liub@cs.uic.edu http://www.cs.uic.edu/~liub Distributed with permission. Related papers: - Murthy Ganapathibhotla and Bing Liu. "Mining Opinions in Comparative Sentences". Proceedings of the 22nd International Conference on Computational Linguistics (Coling-2008), Manchester, 18-22 August, 2008. - 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, in Chiba, Japan. iÿÿÿÿN(t*tProsConsCorpusReadercBs_eZdZeZeƒdd„Zddd„Zddd„Z d„Z d„Z d„Z RS( s± Reader for the Pros and Cons sentence dataset. >>> from nltk.corpus import pros_cons >>> pros_cons.sents(categories='Cons') [['East', 'batteries', '!', 'On', '-', 'off', 'switch', 'too', 'easy', 'to', 'maneuver', '.'], ['Eats', '...', 'no', ',', 'GULPS', 'batteries'], ...] >>> pros_cons.words('IntegratedPros.txt') ['Easy', 'to', 'use', ',', 'economical', '!', ...] tutf8cKs3tj||||ƒtj||ƒ||_dS(sµ :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: `WhitespaceTokenizer` :param encoding: the encoding that should be used to read the corpus. :param kwargs: additional parameters passed to CategorizedCorpusReader. N(t CorpusReadert__init__tCategorizedCorpusReadert_word_tokenizer(tselftroottfileidstword_tokenizertencodingtkwargs((sn/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/corpus/reader/pros_cons.pyR0s cCs’|j||ƒ}|dkr*|j}nt|tjƒrH|g}ntg|j|ttƒD]*\}}}|j ||j d|ƒ^qaƒS(sè Return all sentences in the corpus or in the specified files/categories. :param fileids: a list or regexp specifying the ids of the files whose sentences have to be returned. :param categories: a list specifying the categories whose sentences have to be returned. :return: the given file(s) as a list of sentences. Each sentence is tokenized using the specified word_tokenizer. :rtype: list(list(str)) R N( t_resolvetNonet_fileidst isinstancetcompatt string_typestconcattabspathstTruet CorpusViewt_read_sent_block(RR t categoriestpathtenctfileid((sn/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/corpus/reader/pros_cons.pytsents?s    cCs’|j||ƒ}|dkr*|j}nt|tjƒrH|g}ntg|j|ttƒD]*\}}}|j ||j d|ƒ^qaƒS(s¿ Return all words and punctuation symbols in the corpus or in the specified files/categories. :param fileids: a list or regexp specifying the ids of the files whose words have to be returned. :param categories: a list specifying the categories whose words have to be returned. :return: the given file(s) as a list of words and punctuation symbols. :rtype: list(str) R N( R RRRRRRRRRt_read_word_block(RR RRRR((sn/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/corpus/reader/pros_cons.pytwordsSs    cCs|g}xotdƒD]a}|jƒ}|s1qntjd|ƒ}|r|j|jj|jdƒjƒƒƒqqW|S(Nis+^(?!\n)\s*<(Pros|Cons)>(.*)i( trangetreadlinetretmatchtappendRttokenizetgrouptstrip(RtstreamRtitlinetsent((sn/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/corpus/reader/pros_cons.pyRgs /cCs1g}x$|j|ƒD]}|j|ƒqW|S(N(Rtextend(RR'RR*((sn/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/corpus/reader/pros_cons.pyRrscCsH|dk r'|dk r'tdƒ‚n|dk r@|j|ƒS|SdS(Ns'Specify fileids or categories, not both(Rt ValueErrorR (RR R((sn/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/corpus/reader/pros_cons.pyR xs   N( t__name__t __module__t__doc__tStreamBackedCorpusViewRtWordPunctTokenizerRRRRRRR (((sn/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/corpus/reader/pros_cons.pyR"s   (R/R!tnltk.corpus.reader.apit nltk.tokenizeRRR(((sn/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/corpus/reader/pros_cons.pyts