def init_global_ontology(): '''Should be called ONCE by hubs [texthub, simulate, dialogueserver] (and Tasks when creating) -- Then holds the ontology that is used and accessible system wide. Note that the class FlatOntologyManager(object) is a singleton. ''' OntologyUtils.initUtils() global global_ontology global_ontology = FlatOntologyManager.FlatOntologyManager()
def _set_db(self): """Sets self.db to instance of choosen Data base accessing class. .. note:: It is currently hardcoded to use the sqlite method. But this can be config based - data base classes share interface so only need to change class here, nothing else in code will need adjusting. """ db_fname = OntologyUtils.get_database_path(self.domainString) logger.info('Loading database: ' + db_fname + 'db') try: #self.db = DataBase.DataBase(db_fname+'txt') dbprefix = None if Settings.config.has_option("exec_config", "dbprefix"): dbprefix = Settings.config.get("exec_config", "dbprefix") if dbprefix.lower() == 'none': dbprefix = None if dbprefix: db_fname = os.path.join(dbprefix, db_fname.split('/')[-1]) self.db = DataBaseSQLite.DataBase_SQLite(dbfile=db_fname + 'db', dstring=self.domainString) except IOError: print IOError logger.error( "No such file or directory: " + db_fname + ". Probably <Settings.root> is not set/set wrong by config.") return
def _set_ontology(self): """Just loads json file -- No class for ontology representation at present. """ ontology_fname = OntologyUtils.get_ontology_path(self.domainString) logger.info('Loading ontology: ' + ontology_fname) try: self.ontology = json.load(open(ontology_fname)) except IOError: #print IOError logger.error( "No such file or directory: " + ontology_fname + ". Probably <Settings.root> is not set/set wrong by config.") return
def _config_bootup(self): '''Boot up all domains given under [GENERAL] in config as domains = A,B,C,D Settings.config must have first been set. ''' if not Settings.config.has_option("GENERAL", "domains"): logger.error( "You must specify the domains (a domain) under the GENERAL section of the config" ) domains = Settings.config.get("GENERAL", 'domains') if domains in ['camtourist', 'sftourist', 'electronics', 'all']: self.possible_domains = OntologyUtils.get_domains_group(domains) else: self.possible_domains = domains.split(',') # self.possible_domains is used by simulated user --> won't act outside these domains for dstring in self.possible_domains: self._checkDomainString(dstring) self._bootup(dstring)