naruhodo.utils.polarity module
This module contains polarity related functionalities.
""" This module contains polarity related functionalities. """ import pickle import sys class polarity(object): """ Class for word and phrase polarity. """ def __init__(self, lang='ja', pdict=''): """ Constructor. If no pdict given, will initialize with an empty pdict. """ self.lang = lang if pdict: pass else: self.pdict = dict() def load(self, fname): """ Load saved polarity dict from file. """ try: with open(fname, 'r') as f: self.pdict = pickle.load(f) except: sys.exit('Failed loading pdict file: {0}. Please check the file path.'.format(fname)) def save(self, fname): """ Save polarity dict to file. """ with open(fname, 'r') as f: pickle.dump(self.pdict, f)
Classes
class polarity
Class for word and phrase polarity.
class polarity(object): """ Class for word and phrase polarity. """ def __init__(self, lang='ja', pdict=''): """ Constructor. If no pdict given, will initialize with an empty pdict. """ self.lang = lang if pdict: pass else: self.pdict = dict() def load(self, fname): """ Load saved polarity dict from file. """ try: with open(fname, 'r') as f: self.pdict = pickle.load(f) except: sys.exit('Failed loading pdict file: {0}. Please check the file path.'.format(fname)) def save(self, fname): """ Save polarity dict to file. """ with open(fname, 'r') as f: pickle.dump(self.pdict, f)
Ancestors (in MRO)
- polarity
- builtins.object
Static methods
def __init__(
self, lang='ja', pdict='')
Constructor. If no pdict given, will initialize with an empty pdict.
def __init__(self, lang='ja', pdict=''): """ Constructor. If no pdict given, will initialize with an empty pdict. """ self.lang = lang if pdict: pass else: self.pdict = dict()
def load(
self, fname)
Load saved polarity dict from file.
def load(self, fname): """ Load saved polarity dict from file. """ try: with open(fname, 'r') as f: self.pdict = pickle.load(f) except: sys.exit('Failed loading pdict file: {0}. Please check the file path.'.format(fname))
def save(
self, fname)
Save polarity dict to file.
def save(self, fname): """ Save polarity dict to file. """ with open(fname, 'r') as f: pickle.dump(self.pdict, f)
Instance variables
var lang