Ejemplo n.º 1
0
 def testFileRead(self):
   ## test existing file
   cont = SysUtils.readFileContent("content.txt")
   self.assertEqual(cont, "hello")
   ## test non-existing file
   cont = SysUtils.readFileContent("nosuchfile.txt")
   self.assertIsNone(cont)
Ejemplo n.º 2
0
 def load(self, inFile):
   ## load configuration from argument or ./config.cfg.json or config/config.cfg.json
   cfgFile = inFile or ("config.cfg.json" if os.path.isfile("config.cfg.json") else os.path.join("config", "config.cfg.json"))
   if (not os.path.isfile(cfgFile)):
     raise ConfigException("unable to find config file")
   self.cfgFile = cfgFile
   content = SysUtils.readFileContent(cfgFile)
   self.json = json.loads(content)
Ejemplo n.º 3
0
 def loadTermFile(self, ruleFile):
   if not os.path.exists(ruleFile):
     cfgDirecotry = os.path.dirname(os.path.abspath(Config.getConfigFile()))
     ## pick at config directory
     ruleFile = os.path.join(cfgDirecotry, ruleFile)
   if not os.path.exists(ruleFile):
     raise NLPException("Unable to load rule file " + os.path.basename(ruleFile))
   return json.loads(SysUtils.readFileContent(ruleFile))
Ejemplo n.º 4
0
 def testJsonParser(self):
   fileData = json.loads(SysUtils.readFileContent("testJson.json"))
   parser = Parser.Factory.getParser("json")
   parser.parseFile("testJson.json")
   self.assertSequenceEqual(parser.docs(), fileData["docs"])
   self.assertEqual(parser.getFileMetaData("metaData"), "some data")
Ejemplo n.º 5
0
 def parseFile(self, fileName):
   self.json = json.loads(SysUtils.readFileContent(fileName))