def __init__(self, domainString, rootIn=None): '''Should also be a singleton class - otherwise you can actually circumvent the point of FlatOntologyManager() being a singleton, which is that if ontology is to be dynamic at all - then everything should refer to the one single source. :param domainString: tag such as 'SFHotels' or 'CamHotels' :type domainString: str :param rootIn: path of repository - default None - :type rootIn: str ''' # For conditional goal generation: self.PROB_MASS_OVER_CONDITIONALS = 0.9 # must be less than 1.0 if rootIn is not None: Settings.load_root( rootIn ) # for use with semi file parser - where no config is given to set repository root by self.domainString = domainString self._set_ontology() # sets self.ontology self._set_db() # sets self.db self._set_domains_informable_and_requestable_slots()
def checkOntology(domain): Settings.load_root(root) Settings.load_config(None) Settings.config.add_section("GENERAL") Settings.config.set("GENERAL", 'domains', domain) Ontology.init_global_ontology() gOnt = Ontology.global_ontology for dstring in gOnt.possible_domains: informable = gOnt.get_informable_slots(dstring) for slot in informable: valuesJson = gOnt.get_informable_slot_values(dstring, slot) results = gOnt.ontologyManagers[dstring].db.customQuery( 'SELECT DISTINCT {} FROM {} ORDER BY {} ASC'.format( slot, dstring, slot)) valuesDB = [entry[slot] for entry in results] # valuesDB = map(lambda a : a.lower(),valuesDB) valuesJson.append("not available") difference = list(set(valuesDB) - set(valuesJson)) if len(difference): print dstring + " " + slot + " " + str(difference)
if count >= 5: break logger.info(str) print (str) # for a in self.prevbelief["beliefs"]: # print a, self.prevbelief["beliefs"][a] # for slot,value in self.prevbelief["beliefs"].iteritems(): # print value # print slot # raw_input("hold and check beliefs in "+self.domainString) if __name__ == "__main__": from belieftracking.baseline import FocusTracker from utils import Settings Settings.load_root('/Users/su259/pydial-letsgo/') Settings.load_config(None) Settings.set_seed(123) Settings.config.add_section("GENERAL") Settings.config.set("GENERAL",'domains', 'CamRestaurants') Ontology.init_global_ontology() tracker = FocusTracker('CamRestaurants') print ("hello()") tracker.update_belief_state(None, [('hello()',1.0)]) print ('inform(area="centre")') tracker.update_belief_state('request(area)', [('inform(area="centre")',0.3)]) print ('inform(area="north")') tracker.update_belief_state('confirm(area="centre")', [('negate(area="north",pricerange="cheap")',1.0)]) tracker.update_belief_state('confirm(area="centre")', [('deny(area="centre",area="north",pricerange="cheap")',1.0)]) # tracker.update_belief_state('confirm(area="centre")', [('negate(area="north")',1.0)])
#------------------------------------------------------------------------------------------- # Main #------------------------------------------------------------------------------------------- if __name__ == "__main__": import sys reload(sys) # sys.setdefaultencoding('utf8') # Sometime the encoding in the example files may cause trouble otherwise if len(sys.argv) < 4: exit( "Usage: python RegexSemi.py EXAMPLE_SENTENCES_FILEPATH DOMAIN_TAG REPOSITORY_ROOT [optional: REFERENCE_FILE]" ) if len(sys.argv) == 5: refFileIn = sys.argv[4] else: refFileIn = None from utils import Settings Settings.load_root( rootIn=sys.argv[3] ) #when runing with FileParser() -- since without a config, root may be unavailable. Settings.load_config(None) Settings.config.add_section("GENERAL") Settings.config.set("GENERAL", 'domains', sys.argv[2]) Ontology.init_global_ontology() fp = FileParser(filename=sys.argv[1], domainTag=sys.argv[2]) fp.decode_file(DOPRINT=refFileIn is None) fp.test_file(referenceFile=refFileIn) #END OF FILE
# num_zeros = belief[slot].values().count(0.0) #dont need a -1 for the **NONE** value as not 0 yet # prob_per_other_val = (1.0-self.CONDITIONAL_BELIEF_PROB)/float(num_zeros) # for k,v in belief[slot].iteritems(): # if v == 0.0: # belief[slot][k] = prob_per_other_val #cant think of better way than to loop for this... # belief[slot]['**NONE**'] = 0.0 # #TODO - delete debug prints: print belief # #print constraints # #raw_input("just cond init blief") # return belief if __name__ == '__main__': from utils.er_model.Belief import Relation, Entity from utils.er_model.DActEntity import DiaActEntity Settings.load_root('/Users/su259/cued/pydial/') Settings.load_config(None) Settings.config.add_section("GENERAL") Settings.config.set("GENERAL", 'domains', 'CamRestaurants,CamHotels') Ontology.init_global_ontology() e1 = Entity('CamRestaurants') e2 = Entity('CamHotels') rel = Relation(e1, e2) rel.updateUserInput([ (DiaActEntity('inform(CamRestaurants#area=CamHotels#area)'), 1.0) ]) # rel.lastHyps = [(DiaActEntity('inform(CamRestaurants#area=CamHotels#area)'),1.0)] # rel.lastHyps = [(DiaActEntity('confirm(CamRestaurants#area=CamHotels#area)'),1.0)] tracker = RelationFocusTracker('relation')