#NEWLINE# @ cached ( _CACHE , key = partial ( hashkey , 'depechemood' ) ) #NEWLINE# def load_depechemood( data_dir = None , weighting = 'normfreq' ) : #NEWLINE# #INDENT# '\n    Load DepecheMood lexicon text file from disk, munge into nested dictionary\n    for convenient lookup by lemma#POS. NB: English only!\n\n    Each version of DepecheMood is built starting from word-by-document matrices\n    either using raw frequencies (DepecheMood_freq.txt), normalized frequencies\n    (DepecheMood_normfreq.txt) or tf-idf (DepecheMood_tfidf.txt). The files are\n    tab-separated; each row contains one Lemma#PoS followed by the scores for the\n    following emotions: AFRAID, AMUSED, ANGRY, ANNOYED, DONT_CARE, HAPPY, INSPIRED, SAD.\n\n    Args:\n        data_dir (str, optional): directory on disk where DepecheMood lexicon\n            text files are stored\n        weighting (str {\'freq\', \'normfreq\', \'tfidf\'}, optional): type of word\n            weighting used in building DepecheMood matrix\n\n    Returns:\n        dict[dict]: top-level keys are Lemma#POS strings, values are nested dicts\n            with emotion names as keys and weights as floats\n\n    References:\n        Staiano, J., & Guerini, M. (2014). "DepecheMood: a Lexicon for Emotion\n        Analysis from Crowd-Annotated News". Proceedings of ACL-2014. (arXiv:1405.1605)\n        Data available at https://github.com/marcoguerini/DepecheMood/releases .\n    ' #NEWLINE# if ( data_dir is None ) : #NEWLINE# #INDENT# data_dir = os . path . join ( DEFAULT_DATA_DIR , 'DepecheMood_V1.0' ) #NEWLINE# #UNINDENT# fname = os . path . join ( data_dir , ( ( 'DepecheMood_' + weighting ) + '.txt' ) ) #NEWLINE# _ = os . path . isfile ( fname ) #NEWLINE# logger . info ( 'Loading DepecheMood lexicon from %s' , fname ) #NEWLINE# with open ( fname , 'r' ) as csvfile : #NEWLINE# #INDENT# csvreader = csv . reader ( csvfile , delimiter = '\t' ) #NEWLINE# rows = list ( csvreader ) #NEWLINE# #UNINDENT# cols = csvreader [ 0 ] #NEWLINE# return { row [ 0 ] : { cols [ i ] : float ( row [ i ] ) for i in range ( 1 , 9 ) } for row in rows [ 1 : ] }