Ejemplo n.º 1
0
 def getValue(self, key):
     if (self.cfg == None):
         if not self.loadCfg():
             if self.logger != None:
                 exMessage = ExceptionLogMessage(
                     moduleN=self.moduleName,
                     dtime=datetime.now(),
                     classN=self.className,
                     methodN="getValue/1",
                     descr="",
                     details="configuration file not loaded")
                 self.logger.log(exMessage)
             return None
     try:
         return self.cfg[key]
     except Exception as ex:
         if self.logger != None:
             exMessage = ExceptionLogMessage(moduleN=self.moduleName,
                                             dtime=datetime.now(),
                                             classN=self.className,
                                             methodN="getValue/2",
                                             descr=str(ex),
                                             details=None)
             self.logger.log(exMessage)
         print str(ex)
         return None
Ejemplo n.º 2
0
 def getOrg(self):
     """returns origin word (unicode) """
     try:
         ret = self.response["ru-en"]["regular"][0]["text"]
         return ret
     except Exception as ex:
         if self.logger != None:
             exMessage = ExceptionLogMessage(moduleN=self.moduleName,
                                             dtime=datetime.now(),
                                             classN=self.className,
                                             methodN="getOrgText",
                                             descr=str(ex),
                                             details={"word": self.word})
             self.logger.log(exMessage)
         return None
Ejemplo n.º 3
0
 def loadCfg(self):
     try:
         f = file(self.filedir)
         self.cfg = Config(f)
         return True
     except Exception as ex:
         print ex
         self.cfg = None
         if self.logger != None:
             exMessage = ExceptionLogMessage(moduleN=self.moduleName,
                                             dtime=datetime.now(),
                                             classN=self.className,
                                             methodN="loadCfg",
                                             descr=str(ex),
                                             details=None)
             self.logger.log(exMessage)
         return False
Ejemplo n.º 4
0
 def getResponse(self, word):
     """ establish conniction and return response """
     try:
         qword = urllib2.quote(word)
         url = self.TRANSLATE_URL + qword
         res = getRequest(url)
         return res
     except Exception as ex:
         if self.logger != None:
             exMessage = ExceptionLogMessage(moduleN=self.moduleName,
                                             dtime=datetime.now(),
                                             classN=self.className,
                                             methodN="loadResponse",
                                             descr=str(ex),
                                             details={"word": word})
             self.logger.log(exMessage)
         return None
Ejemplo n.º 5
0
    def getGen(self):
        """ returns gender of a noun
	    'm':male
	    'f':female
	    'n':neutron
	    None:has no gender
	"""
        try:
            return self.response["ru-en"]["regular"][0]["gen"]["code"]
        except Exception as ex:
            if self.logger != None:
                exMessage = ExceptionLogMessage(moduleN=self.moduleName,
                                                dtime=datetime.now(),
                                                classN=self.className,
                                                methodN="getGen",
                                                descr=str(ex),
                                                details={"word": self.word})
                self.logger.log(exMessage)
            return None
Ejemplo n.º 6
0
    def getAsp(self):
        """ returns aspective of a verb
	    'pf' : perfective
	    'imp' : imperfective
	    None: not a verb
	"""
        try:
            ret = self.response["ru-en"]["regular"][0]["asp"]["code"]
            return ret
        except Exception as ex:
            if self.logger != None:
                exMessage = ExceptionLogMessage(moduleN=self.moduleName,
                                                dtime=datetime.now(),
                                                classN=self.className,
                                                methodN="getAsp",
                                                descr=str(ex),
                                                details={"word": self.word})
                self.logger.log(exMessage)
            return None
Ejemplo n.º 7
0
    def getType(self):
        """ returns type of the word 
	    'nn'  : noun
	    'vrb' : verb
	    'adj' : adjective
	    ..
	    None : word not recognized
	"""
        try:
            return self.response["ru-en"]["regular"][0]["pos"]["code"]
        except Exception as ex:
            if self.logger != None:
                exMessage = ExceptionLogMessage(moduleN=self.moduleName,
                                                dtime=datetime.now(),
                                                classN=self.className,
                                                methodN="getType",
                                                descr=str(ex),
                                                details={"word": self.word})
                self.logger.log(exMessage)
            return None
Ejemplo n.º 8
0
 def getResponseJSON(self, word):
     """ conver response to json """
     res = self.getResponse(word)
     if res == None: return None
     try:
         res = json.load(res)
         return res
     except Exception as ex:
         if self.logger != None:
             exMessage = ExceptionLogMessage(moduleN=self.moduleName,
                                             dtime=datetime.now(),
                                             classN=self.className,
                                             methodN="loadResponseJSON",
                                             descr=str(ex),
                                             details={
                                                 "word":
                                                 qword,
                                                 "mess":
                                                 "failed to parse to json"
                                             })
             self.logger.log(exMessage)
         return None