def save_sentiment_dict(remove_neutral=True): """ This saves the sentiment dictionary without extended adverbs (check). No get additional adverbs, modify the load function in the Sentiment class of Pattern. """ # this must be the path of the Pattern sentiment lexicon for English pin = 'C:/Users/ABittar/AppData/Local/Continuum/anaconda3/envs/py27/lib/site-packages/pattern-2.6-py2.7.egg/pattern/text/en/en-sentiment.xml' s = Sentiment() s.load(pin) s = dict(s) df_lex = pd.DataFrame.from_dict(s).T # keep only polarity value (first element in list, or 0 if null) for col in df_lex.columns: df_lex[col] = df_lex[[col]][col].apply( lambda x: x[0] if (type(x) == list or type(x) == tuple) else 0) # remove rows/words with 0 values if remove_neutral: df_lex = df_lex.loc[~(df_lex[None] == 0)] df_lex.drop('', inplace=True, axis=1) # > 0 = pos (1), <0 = neg (-1), 0 = neutral for col in df_lex.columns: df_lex[col] = df_lex[[col]][col].apply(lambda x: 1 if x > 0 else x) for col in df_lex.columns: df_lex[col] = df_lex[[col]][col].apply(lambda x: -1 if x < 0 else x) df_lex.rename(columns={None: 'aggregated'}, inplace=True) df_lex.to_pickle(RESOURCE_DIR + 'pattern_en_sentiment_full.pickle') return df_lex
def load(self, path=None): _Sentiment.load(self, path) # Map "verschrikkelijk" to adverbial "verschrikkelijke" (+1%) if not path: for w, pos in dict.items(self): if "JJ" in pos: p, s, i = pos["JJ"] self.annotate(attributive(w), "JJ", p, s, i)
def load(self): _Sentiment.load(self) for w, pos in self.items(): if "JJ" in pos: # Map "verschrikkelijk" to adverbial "verschrikkelijke" (+1% accuracy) self.setdefault(attributive(w), { "JJ": pos["JJ"], None: pos["JJ"] })
def load(self, path=None): _Sentiment.load(self, path) # Map "terrible" to adverb "terribly" (+1% accuracy) if not path: for w, pos in list(dict.items(self)): if "JJ" in pos: if w.endswith("y"): w = w[:-1] + "i" if w.endswith("le"): w = w[:-2] p, s, i = pos["JJ"] self.annotate(w + "ly", "RB", p, s, i)
def load(self, path=None): _Sentiment.load(self, path) # Map "terrible" to adverb "terribly" (+1% accuracy) if not path: for w, pos in list(dict.items(self)): if "JJ" in pos: if w.endswith("y"): w = w[:-1] + "i" if w.endswith("le"): w = w[:-2] p, s, i = pos["JJ"] self.annotate(w + "ly", "RB", p, s, i)
def load(self, path=None): _Sentiment.load(self, path) # Map "précaire" to "precaire" (without diacritics, +1% accuracy). if not path: for w, pos in list(dict.items(self)): w0 = w if not w.endswith((u"à", u"è", u"é", u"ê", u"ï")): w = w.replace(u"à", "a") w = w.replace(u"é", "e") w = w.replace(u"è", "e") w = w.replace(u"ê", "e") w = w.replace(u"ï", "i") if w != w0: for pos, (p, s, i) in pos.items(): self.annotate(w, pos, p, s, i)
def load(self, path=None): _Sentiment.load(self, path) # Map "précaire" to "precaire" (without diacritics, +1% accuracy). if not path: for w, pos in dict.items(self): w0 = w if not w.endswith((u"à", u"è", u"é", u"ê", u"ï")): w = w.replace(u"à", "a") w = w.replace(u"é", "e") w = w.replace(u"è", "e") w = w.replace(u"ê", "e") w = w.replace(u"ï", "i") if w != w0: for pos, (p, s, i) in pos.items(): self.annotate(w, pos, p, s, i)
def load(self): _Sentiment.load(self) for w, pos in self.items(): if "JJ" in pos: # Map "verschrikkelijk" to adverbial "verschrikkelijke" (+1% accuracy) self.setdefault(attributive(w), {"JJ": pos["JJ"], None: pos["JJ"]})
def load(self, path=None): _Sentiment.load(self, path)
def load(self, path=None): _Sentiment.load(self, path)